import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'superplayer_home.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<Widget> _listButton = [];

    for (Map item in mapDwinfoXwx['data']['items']) {
      _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)));
      },
    );
  }
}
