flutter_smart_video_player 1.0.0 copy "flutter_smart_video_player: ^1.0.0" to clipboard
flutter_smart_video_player: ^1.0.0 copied to clipboard

A fully customizable YouTube video player using WebView and IFrame API. Works seamlessly inside dynamic UI rendering systems.

flutter_smart_video_player #

A production-ready, fully customizable YouTube video player Flutter package built on WebView + YouTube IFrame API. Designed for dynamic UI rendering systems.

pub.dev License: MIT


โœจ Features #

  • ๐ŸŽฌ YouTube playback from any standard YouTube URL
  • ๐Ÿ“บ Flutter-controlled fullscreen (landscape lock, smooth transition)
  • ๐ŸŽฎ Custom controls โ€” play/pause, seek bar, time labels, fullscreen toggle
  • ๐Ÿ”„ Dynamic rendering safe โ€” survives rebuilds, no unnecessary restarts
  • ๐Ÿ“‹ Multiple instances โ€” isolated controllers, no WebView conflicts
  • ๐ŸŽ›๏ธ External controller API โ€” programmatically control playback
  • ๐Ÿ”ง Custom controls builder โ€” replace the default UI entirely
  • โšก Lifecycle aware โ€” pauses on app background/dispose
  • โŒ Graceful error handling โ€” invalid URLs, unavailable videos

๐Ÿš€ Installation #

Add to your pubspec.yaml:

dependencies:
  flutter_smart_video_player: ^1.0.0

Android setup #

In android/app/src/main/AndroidManifest.xml, add inside <application>:

<application
  android:usesCleartextTraffic="true"
  ...>

Also ensure minSdkVersion is at least 19 in android/app/build.gradle.

iOS setup #

In ios/Runner/Info.plist, add:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

๐Ÿ“– Usage #

Basic โ€” just a URL #

import 'package:flutter_smart_video_player/flutter_smart_video_player.dart';

SmartVideoPlayer(
  url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
)

Supports all YouTube URL formats:

  • https://www.youtube.com/watch?v=VIDEO_ID
  • https://youtu.be/VIDEO_ID
  • https://www.youtube.com/embed/VIDEO_ID
  • https://www.youtube.com/shorts/VIDEO_ID
  • Raw VIDEO_ID (11 chars)

With configuration #

SmartVideoPlayer(
  url: 'https://youtu.be/dQw4w9WgXcQ',
  config: const SmartVideoConfig(
    autoPlay: true,
    showControls: true,
    aspectRatio: 16 / 9,
    backgroundColor: Colors.black,
    allowFullscreen: true,
  ),
)

With external controller #

final controller = SmartVideoController();

@override
void dispose() {
  controller.dispose();
  super.dispose();
}

// In your widget:
SmartVideoPlayer(
  url: 'https://youtu.be/dQw4w9WgXcQ',
  controller: controller,
)

// Control from anywhere:
controller.play();
controller.pause();
controller.seekTo(const Duration(seconds: 30));

React to state changes #

ValueListenableBuilder<SmartVideoState>(
  valueListenable: controller,
  builder: (context, state, _) {
    return Text('${state.positionLabel} / ${state.durationLabel}');
  },
)

Custom controls UI #

SmartVideoPlayer(
  url: url,
  config: const SmartVideoConfig(showControls: false),
  customControlsBuilder: (context, controller, state) {
    return MyCustomControls(controller: controller, state: state);
  },
)

Dynamic rendering system (your use case) #

Widget buildComponent(Map<String, dynamic> item) {
  switch (item['type']) {
    case 'ytVideo':
      return SmartVideoPlayer(url: item['data']);
    case 'text':
      return Text(item['data']);
    // ...other types
  }
}

๐ŸŽ›๏ธ API Reference #

SmartVideoPlayer #

Parameter Type Default Description
url String required YouTube URL
controller SmartVideoController? auto External controller
config SmartVideoConfig default Player configuration
customControlsBuilder Widget Function(...)? null Custom controls overlay

SmartVideoConfig #

Property Type Default Description
autoPlay bool false Auto-start on ready
showControls bool true Show built-in controls
backgroundColor Color Colors.black BG behind WebView
aspectRatio double 16/9 Player container ratio
allowFullscreen bool true Enable fullscreen button
showAnnotations bool false YouTube annotations
showRelatedVideos bool false Related videos on end

SmartVideoController #

Method Description
play() Start/resume playback
pause() Pause playback
seekTo(Duration) Jump to position
enterFullscreen() Enter fullscreen
exitFullscreen() Exit fullscreen
dispose() Cleanup resources

SmartVideoState #

Property Type Description
isPlaying bool Currently playing
isReady bool Player initialized
isBuffering bool Currently buffering
isFullscreen bool In fullscreen mode
position Duration Current position
duration Duration Total duration
progress double Progress 0.0โ€“1.0
positionLabel String mm:ss position
durationLabel String mm:ss duration
error String? Error message or null

๐Ÿ— Architecture #

lib/
โ”œโ”€โ”€ flutter_smart_video_player.dart    # Public exports
โ””โ”€โ”€ src/
    โ”œโ”€โ”€ controller/
    โ”‚   โ””โ”€โ”€ smart_video_controller.dart   # ValueNotifier controller + JS bridge
    โ”œโ”€โ”€ models/
    โ”‚   โ”œโ”€โ”€ smart_video_state.dart        # Immutable state object
    โ”‚   โ””โ”€โ”€ smart_video_config.dart       # Configuration options
    โ”œโ”€โ”€ js/
    โ”‚   โ””โ”€โ”€ player_html.dart             # YouTube IFrame HTML+JS builder
    โ”œโ”€โ”€ view/
    โ”‚   โ””โ”€โ”€ smart_video_view.dart        # InAppWebView + JS handler registration
    โ”œโ”€โ”€ player/
    โ”‚   โ””โ”€โ”€ flutter_smart_video_player.dart      # Public widget (composes all layers)
    โ”œโ”€โ”€ fullscreen/
    โ”‚   โ””โ”€โ”€ fullscreen_page.dart         # Fullscreen navigator page
    โ”œโ”€โ”€ widgets/
    โ”‚   โ””โ”€โ”€ controls.dart               # Default controls overlay UI
    โ””โ”€โ”€ utils/
        โ””โ”€โ”€ youtube_parser.dart         # YouTube URL โ†’ video ID parser

๐Ÿ”ง How It Works #

  1. URL Parsing: YoutubeParser extracts the video ID from any YouTube URL format
  2. HTML Generation: PlayerHtml builds a self-contained HTML page embedding the YouTube IFrame API
  3. WebView: SmartVideoView hosts the WebView, loads the HTML, and registers JS message handlers
  4. JS Bridge: Events from the IFrame (onReady, onStateChange, onProgress, onError) are sent to Flutter via flutter_inappwebview.callHandler()
  5. Controller: SmartVideoController exposes state via ValueNotifier and dispatches JS commands back to the WebView
  6. Fullscreen: Uses Navigator.push() to a dedicated page, reusing the same controller โ€” no video restart

๐Ÿงช Testing #

flutter test

๐Ÿ“‹ Manual Testing Checklist #

  • โŒ Android real device โ€” play/pause/seek
  • โŒ iOS real device โ€” play/pause/seek
  • โŒ Fullscreen enter/exit (portrait restore)
  • โŒ Back button in fullscreen
  • โŒ Multiple players on same screen
  • โŒ Scroll list โ€” players don't restart
  • โŒ Dynamic rebuild โ€” players survive
  • โŒ Invalid URL โ€” error shown gracefully
  • โŒ Private video โ€” error shown gracefully
  • โŒ App background โ€” video pauses

๐Ÿ“ฆ Publishing #

dart pub publish --dry-run   # Check for issues
dart pub publish             # Publish to pub.dev

๐Ÿ“„ License #

MIT โ€” see LICENSE

3
likes
0
points
44
downloads

Publisher

unverified uploader

Weekly Downloads

A fully customizable YouTube video player using WebView and IFrame API. Works seamlessly inside dynamic UI rendering systems.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_inappwebview

More

Packages that depend on flutter_smart_video_player