import 'package:flutter/material.dart';
import '../model/PhoneInfo.dart';
import 'PhotoView.dart';
import '../widget/LinearButton.dart';
class PhoneLogin extends Dialog {
  final List<PhoneInfo> phoneList;

  PhoneLogin({Key key, this.phoneList = const []}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      child: Scaffold(
        backgroundColor: Color(0xCC000000),
        body: Container(
          child: SizedBox.expand(
            child: UnconstrainedBox(
              child: Container(
                width: 320,
                // padding: EdgeInsets.symmetric(horizontal: 20, vertical: 25),
                height: 380,
                decoration: BoxDecoration(color: Color(0xFF15151D), border: Border.all(width: 1, color: Theme.of(context).primaryColor)),
                child: Stack(
                  children: <Widget>[
                    Padding(
                      padding: EdgeInsets.symmetric(horizontal: 20, vertical: 25),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: <Widget>[
                          Text.rich(TextSpan(style: TextStyle(color: Colors.white, fontSize: 14), children: [
                            TextSpan(text: '欢迎来到杀戮的世界！您的手机可能设置了'),
                            TextSpan(text: '“省电策略”', style: TextStyle(color: Color(0xFFFFB726), fontWeight: FontWeight.w600)),
                            TextSpan(text: '，为了不影响您的游戏体验，请在游戏前，先选择您的手机品牌，跟着说明正确的配置手机')
                          ])),
                          // Container(
                          //   height: 30,
                          // ),
                          Container(
                              width: double.infinity,
                              height: 180,
                              margin: EdgeInsets.fromLTRB(0, 0, 0, 20),
                              child: GridView.builder(
                                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                                      crossAxisCount: 2, //每行三列
                                      childAspectRatio: 3.0 //显示区域宽高相等
                                      ),
                                  itemCount: phoneList.length,
                                  itemBuilder: (context, index) {
                                    //如果显示到最后一个并且Icon总数小于200时继续获取数据

                                    return InkWell(
                                      child: Container(
                                        margin: EdgeInsets.all(5),
                                        color: Colors.white,
                                        child: Row(
                                          mainAxisAlignment: MainAxisAlignment.center,
                                          children: <Widget>[
                                            Image.network(
                                              phoneList[index].icon,
                                              width: 20,
                                            ),
                                            Container(
                                              width: 5,
                                            ),
                                            Text(phoneList[index].phone)
                                          ],
                                        ),
                                      ),
                                      onTap: () async {
                                        var list = phoneList[index].image.split(',');
                                        final bool res = await Navigator.of(context).push(
                                          PageRouteBuilder(
                                            opaque: false,
                                            transitionDuration: Duration(milliseconds: 300),
                                            transitionsBuilder:
                                                (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
                                              return FadeTransition(
                                                opacity: CurvedAnimation(parent: animation, curve: Curves.linear),
                                                child: child,
                                              );
                                            },
                                            pageBuilder: (BuildContext context, _, __) {
                                              return PhotoView(imageList: list);
                                            },
                                          ),
                                        );
                                        if (res != null && res) {
                                          Navigator.of(context).pop(true);
                                        }
                                      },
                                    );
                                  })),
                          Container(
                            child: LinearButton(
                              btntext: '关闭',
                              btnHeight: 36.0,
                              colorList: [Color(0xFF271A21), Color(0xFF271A21)],
                              textColor: Color(0xFFD4504B),
                              textWeight: FontWeight.w400,
                              onTapHomeMenu: () {
                                Navigator.of(context).pop(true);
                              },
                            ),
                          ),
                          // Container(
                          //   height: 5,
                          // )
                        ],
                      ),
                    ),
                    Positioned(
                      top: 0,
                      left: 0,
                      child: Image.asset(
                        'images/tancuang_shang.png',
                        // width: 131,
                      ),
                    ),
                    Positioned(
                      bottom: 0,
                      right: 4,
                      child: Image.asset(
                        'images/tancuang_xia.png',
                        // width: 148,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
      onWillPop: () {
      
        return Future.value(false);
      },
    );
  }
}
