v0.0.5
flutter_awesome_reels
一个功能强大且可自定义的 Flutter 小部件,用于创建类似 TikTok/Instagram 的竖屏视频轮播,具备缓存、分析和丰富交互等高级功能。
21喜欢 69近 30 天下载150Pub 分数
AndroidiOSmacOS
wailashraf71/flutter_awesome_reels open-source repository details.
{"sdk":"flutter"}^2.10.0^0.4.0+2^4.7.2^5.9.0^2.1.5^3.3.1^11.0.0^1.3.2^11.5.0^1.0.1^10.9.0^6.1.4^2.1.0{"sdk":"flutter"}^6.0.0^5.5.0^2.5.0以下为英文项目原文快照,最新内容请访问 GitHub。
A powerful and feature-rich Flutter package for creating Instagram/TikTok-like video reels with advanced streaming support including HLS, DASH, and MP4 formats.
Flutter Awesome Reels Preview
onPress and onLongPress event callbacks for advanced interaction handling. Update your widget usage to handle these events if needed.Add this to your package's pubspec.yaml file:
dependencies:
flutter_awesome_reels: ^0.0.3
Then run:
flutter pub get
import 'package:flutter/material.dart';
import 'package:flutter_awesome_reels/flutter_awesome_reels.dart';
class MyReelsPage extends StatefulWidget {
@override
_MyReelsPageState createState() => _MyReelsPageState();
}
class _MyReelsPageState extends State<MyReelsPage> {
late ReelController _controller;
@override
void initState() {
super.initState();
// Create reels with different streaming formats
final reels = [
ReelModel(
id: '4',
videoSource: VideoSource(
url: 'https://bitmovin-a.akamaihd.net/content/MI201109210084_1/mpds/f08e80da-bf1d-4e3d-8899-f0f6155f6efa.mpd',
),
user: const ReelUser(
id: 'u2',
username: 'bob',
displayName: 'Bob Builder',
isFollowing: true,
),
likesCount: 200,
commentsCount: 30,
sharesCount: 10,
tags: ['adventure', 'travel'],
audio: const ReelAudio(title: 'Adventure Tune'),
duration: const Duration(seconds: 20),
isLiked: true,
views: 2500,
location: 'Mountains',
),
ReelModel(
id: '1',
videoSource: VideoSource(
url: 'https://demo.unified-streaming.com/k8s/features/stable/video/tears-of-steel/tears-of-steel.ism/.m3u8',
),
user: const ReelUser(
id: 'u3',
username: 'charlie',
displayName: 'Charlie Chaplin',
),
likesCount: 4325,
commentsCount: 45,
sharesCount: 20,
tags: ['comedy', 'classic'],
audio: const ReelAudio(title: 'Classic Comedy'),
duration: const Duration(seconds: 15),
isLiked: false,
views: 5000,
location: 'Hollywood',
),
ReelModel(
id: '3',
videoSource: VideoSource(
url: 'https://www.sample-videos.com/video321/mp4/720/big_buck_bunny_720p_1mb.mp4',
),
user: const ReelUser(
id: 'u1',
username: 'alice',
displayName: 'Alice in Wonderland',
),
likesCount: 120,
commentsCount: 15,
sharesCount: 5,
tags: ['fun', 'bunny'],
audio: const ReelAudio(title: 'Sample Music'),
duration: const Duration(seconds: 10),
isLiked: false,
views: 1000,
location: 'Wonderland',
),
];
_controller = ReelController();
_controller.initialize(reels: reels, config: ReelConfig());
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: AwesomeReels(
reels: _controller.reels,
controller: _controller,
config: ReelConfig(
showDownloadButton: false,
enablePullToRefresh: true,
),
onReelChanged: (index) {
debugPrint('Reel changed to index: $index');
},
onReelLiked: (reel) {
_showSnackBar(
'[${reel.isLiked ? 'Liked' : 'Unliked'} ${reel.user?.displayName}\'s reel');
},
onReelShared: (reel) {
_showSnackBar('Shared ${reel.user?.displayName}\'s reel');
},
onReelCommented: (reel) {
// Show comment dialog or navigate to comments page
},
onUserFollowed: (user) {
_showSnackBar(
'${user.isFollowing ? 'Following' : 'Unfollowed'} ${user.displayName}');
},
onUserBlocked: (user) {
_showSnackBar('Blocked ${user.displayName}');
},
onVideoCompleted: (reel) {
debugPrint('Video completed: ${reel.id}');
},
onVideoError: (reel, error) {
_showSnackBar('Error playing video: $error');
},
// New event callbacks
onPress: (reel) {
debugPrint('Pressed: ${reel.id}');
},
onLongPress: (reel) {
debugPrint('Long pressed: ${reel.id}');
},
),
);
}
void _showSnackBar(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
duration: const Duration(seconds: 2),
backgroundColor: Colors.grey[800],
),
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
}
// Create a reel with multiple format support
final multiFormatReel = ReelModel(
id: 'multi_1',
videoSource: VideoSource(
format: VideoFormat.hls, // Primary format
urls: {
VideoFormat.hls: 'https://example.com/video.m3u8',
VideoFormat.dash: 'https://example.com/video.mpd',
VideoFormat.mp4: 'https://example.com/video.mp4',
},
),
thumbnailUrl: 'https://example.com/thumb.jpg',
duration: Duration(minutes: 3),
user: ReelUser(
id: 'user1',
username: 'creator',
profilePictureUrl: 'https://example.com/avatar.jpg',
),
caption: 'Multi-format video with fallback support',
);
// Advanced streaming configuration
final streamingConfig = StreamingConfig(
preferredFormat: PreferredStreamingFormat.hls,
enableAdaptiveBitrate: true,
enableLowLatency: false,
maxBitrate: 5000000, // 5 Mbps
minBitrate: 500000, // 500 Kbps
enableSubtitleSelection: true,
enableAudioTrackSelection: true,
enableQualitySelection: true,
enableFallback: true,
fallbackFormats: [VideoFormat.dash, VideoFormat.mp4],
networkTimeout: Duration(seconds: 30),
maxRetryAttempts: 3,
enableDRM: false,
);
final config = ReelConfig(
enableCaching: true,
cacheConfig: CacheConfig(
maxCacheSize: 500 * 1024 * 1024, // 500MB
maxCacheAge: Duration(days: 7),
),
videoPlayerConfig: VideoPlayerConfig(
useBetterPlayer: true,
enableHardwareAcceleration: true,
enablePictureInPicture: true,
streamingConfig: streamingConfig,
),
preloadConfig: PreloadConfig(
preloadCount: 2,
preloadRadius: 1,
),
);
.m3u8ReelModel.hls(
id: 'hls_video',
hlsUrl: 'https://example.com/playlist.m3u8',
// ... other properties
);
.mpdReelModel.dash(
id: 'dash_video',
dashUrl: 'https://example.com/manifest.mpd',
// ... other properties
);
.mp4ReelModel.mp4(
id: 'mp4_video',
mp4Url: 'https://example.com/video.mp4',
// ... other properties
);
| Property | Type | Default | Description |
|---|---|---|---|
enableCaching |
bool |
true |
Enable video caching |
cacheConfig |
CacheConfig |
CacheConfig() |
Cache configuration |
preloadConfig |
PreloadConfig |
PreloadConfig() |
Video preloading settings |
videoPlayerConfig |
VideoPlayerConfig |
VideoPlayerConfig() |
Video player configuration |
progressIndicatorConfig |