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

main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  const Home({super.key});

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

class _HomeState extends State<Home> {
  late final TextEditingController _urlController;

  @override
  void initState() {
    _urlController = TextEditingController(
        text:
            'https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4');
    super.initState();
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("App with test plugin"),
        backgroundColor: Colors.blueGrey,
      ),
      body: Center(
        child: NutPlayerAndroid(
          onMapViewCreated: _onMapViewCreated,
        ),
      ),
    );
  }

  void _onMapViewCreated(NutPlayerAndroidViewController controller) {
    controller.setUrl(url: _urlController.text);
    controller.play();
  }
}