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

void main() {
  runApp(const 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(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

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

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  double _duration = 0;
  double _currentTime = 0;
  String _playerState = "";
  late int _playerWidgetId;
  // late NutPlayerWidgetController controller;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text("NutPlayer Test"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              '$_playerState',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
            // AspectRatio(aspectRatio: 16/10,
            //     child: NutPlayerWidget(onNutPlayerWidgetCreated: (NutPlayerWidgetController newController, int playerId) {
            //       controller = newController;
            //       _playerWidgetId = playerId;
            //       controller.init();
            //       var dataSource = DataSource(
            //         sourceType: DataSourceType.network,
            //         uri: "https://cloud.nut.tech/index.php/s/CEb4Xd48wd98kj4/download/star-wars.mp4",
            //         format: VideoFormat.mp4,
            //       );
            //       controller.create(dataSource);
            //     }, creationParams: {})
            // ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text('$_currentTime',
                  key: const Key('CurrentTimeText'),
                  style: TextStyle(
                      decoration: TextDecoration.none,
                      color: Colors.blue,
                      fontSize: 17,
                      fontWeight: FontWeight.w600),
                ),
                TextButton(
                    onPressed: () {
                      // controller.play(_playerWidgetId);
                    },
                    child: const Text(
                      'Старт',
                      textAlign: TextAlign.center,
                      style: TextStyle(
                          decoration: TextDecoration.none,
                          color: Colors.blue,
                          fontSize: 17,
                          fontWeight: FontWeight.w600),
                    )),
                TextButton(
                    onPressed: () {
                      // controller.pause(_playerWidgetId);
                    },
                    child: const Text(
                      'Пауза',
                      textAlign: TextAlign.center,
                      style: TextStyle(
                          decoration: TextDecoration.none,
                          color: Colors.blue,
                          fontSize: 17,
                          fontWeight: FontWeight.w600),
                    )),
                Text('$_duration',
                  key: const Key('DurationText'),
                  style: TextStyle(
                      decoration: TextDecoration.none,
                      color: Colors.blue,
                      fontSize: 17,
                      fontWeight: FontWeight.w600),
                ),
              ],)
          ],
        ),
      ),
    );
  }
}