import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'superplayer_home.dart';

//import 'tc_player.dart';
import 'data_file.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
      theme: ThemeData(primarySwatch: Colors.blue),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  var crashInfo;
  bool isLoadOk = false;
  List<Widget> listButton = [];

  @override
  void initState() {
    getListButton().then((value) {
      setState(() {});
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('LiteAVSDK播放 plugin example app'),
      ),
      body: Center(
        child: ListView(
          children: listButton,
        ),
      ),
    );
  }

  var isLoad = false;

  void showMsg(String msg) {
    showDialog(
        context: context,
        builder: (context) {
          return AlertDialog(
            content: Text(msg),
            actions: [
              FlatButton(
                  onPressed: () {
                    Navigator.pop(context);
                  },
                  child: Text("我知道了"))
            ],
          );
        });
  }

  Future getListButton() async {
    List listDw = mapDwinfo['data']['items'];

    List<Widget> _listButton = [];
    _listButton.addAll([
      getPlayUrl(
          'http://www.yibinu.edu.cn/__local/5/35/DF/264049B7E978EEE2F5849688986_05D4A6FE_152CDB8C.mp4?e=.mp4',
          'yibinu'),
      getPlayUrl('https://yongling8808.github.io/test/video/movie/movie.mp4', '网络视频'),
      getPlayUrl(
          'http://125.64.218.67:9908/video/2_6063_20210410_155327_川QKK380.mp4', '违章视频-川QKK380'),
      getPlayUrl(
          'http://125.64.218.67:9908/video/2_6063_20210409_140608_川Q31715.mp4', '违章视频-川Q31715'),
    ]);

    for (Map item in listDw) {
      _listButton.add(
          getPlayUrl(item["play_urlhead"] + item["video16"], '${item["dwbh"]}.' + item["dwmc"]));
    }

    listButton = _listButton;
  }

  Widget getPlayUrl(String _url, text) {
    return RaisedButton(
      child: Text("LiteAVSDK播放-$text"),
      onPressed: () async {
        Navigator.of(context).push(MaterialPageRoute(
            builder: (context) => SuperPlayerPage(url: _url, loop: 0, title: text)));
      },
    );
  }
}
