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

This is a Vimeo Video Player Package

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:vimeo_player_package/vimeo_player_package.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  VimeoPlayerController? controller;
  bool _playerReady = false;
  final double _height = 244;
  bool _isDisposed = false;

  @override
  void initState() {
    super.initState();

    // Initialize controller with a video ID
    // Uncomment the lines below to test with a proper controller
    controller = VimeoPlayerController(
      initialVideoId: '1003797907',
      flags: VimeoPlayerFlags(),
    )..addListener(listener);

    // To test null controller scenario, comment out the above and uncomment below:
    // controller = null; // This will test null controller memory leak prevention
  }

  void listener() async {
    if (_isDisposed || !mounted) return;

    if (_playerReady) {
      // Use a more memory-safe approach instead of addPostFrameCallback
      if (mounted && !_isDisposed) {
        setState(() {
          // Video title is available via controller.value.videoTitle if needed
        });
      }
    }
  }

  @override
  void dispose() {
    _isDisposed = true;

    // Remove listener first
    controller?.removeListener(listener);

    // Dispose controller
    controller?.dispose();
    controller = null;

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return VimeoBuilder(
      player: VimeoPlayer(
        controller: controller,
        skipDuration: 10,
        portrait: false, // Set to true for portrait video, false for landscape
        onReady: () {
          if (_isDisposed || !mounted) return;
          print('onReady callback triggered!');
          setState(() {
            _playerReady = true;
          });
        },
      ),
      builder: (context, player) {
        return Scaffold(
          appBar: AppBar(title: Text(widget.title)),
          body: Center(
            child: Column(
              children: <Widget>[
                const SizedBox(height: 20),
                SizedBox(height: _height, child: player),
                const SizedBox(height: 20),
              ],
            ),
          ),
        );
      },
    );
  }
}
0
likes
70
points
32
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

This is a Vimeo Video Player Package

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, flutter_inappwebview, webview_flutter

More

Packages that depend on vimeo_player_package