panhui 6 жил өмнө
parent
commit
3af1ca2d45

+ 21 - 0
lib/model/PhoneInfo.dart

@@ -0,0 +1,21 @@
+import 'package:json_annotation/json_annotation.dart';
+
+part 'PhoneInfo.g.dart';
+
+@JsonSerializable()
+class PhoneInfo {
+  PhoneInfo(this.id, this.phone, this.image);
+  int id;
+  String phone;//手机型号
+  String image;//图标
+  factory PhoneInfo.fromJson(Map<String, dynamic> json) =>
+      _$PhoneInfoFromJson(json);
+
+  Map<String, dynamic> toJson() => _$PhoneInfoToJson(this);
+  // 命名构造函数
+  PhoneInfo.empty();
+  @override
+  String toString() {
+    return _$PhoneInfoToJson(this).toString();
+  }
+}

+ 20 - 0
lib/model/PhoneInfo.g.dart

@@ -0,0 +1,20 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+part of 'PhoneInfo.dart';
+
+// **************************************************************************
+// JsonSerializableGenerator
+// **************************************************************************
+
+PhoneInfo _$PhoneInfoFromJson(Map<String, dynamic> json) {
+  return PhoneInfo(
+      json['id'] as int,
+      json['phone'] as String,
+      json['image'] as String);
+}
+
+Map<String, dynamic> _$PhoneInfoToJson(PhoneInfo instance) => <String, dynamic>{
+      'id': instance.id,
+      'phone': instance.phone,
+      'image': instance.image
+    };

+ 176 - 8
lib/pages/MatchPage.dart

@@ -1,6 +1,6 @@
 import 'package:flutter/material.dart';
 import 'package:flutter_swiper/flutter_swiper.dart';
-import 'package:cached_network_image/cached_network_image.dart';
+import 'package:shared_preferences/shared_preferences.dart';
 import 'package:flutter/cupertino.dart';
 import '../styles/totast.dart';
 import '../net/HttpManager.dart';
@@ -10,10 +10,8 @@ import 'package:flutter_redux/flutter_redux.dart';
 import '../redux/AppState.dart';
 import '../widget/LinearButton.dart';
 import '../model/BannerInfo.dart';
-import '../widget/ITextInput.dart';
 import '../widget/HouseItem.dart';
 import '../model/HouseInfo.dart';
-import 'OpenRoom.dart';
 import 'package:flutter_picker/flutter_picker.dart';
 import 'CompetitionInformation.dart';
 import '../model/GameInfo.dart';
@@ -22,6 +20,9 @@ import 'dart:convert';
 import 'dart:ui';
 import 'dart:math';
 import 'SelectRoom.dart';
+import 'package:flutter/services.dart';
+import 'PhotoView.dart';
+import '../model/PhoneInfo.dart';
 
 class MatchPage extends StatefulWidget {
   @override
@@ -41,6 +42,7 @@ class _MatchPageState extends State<MatchPage> with WidgetsBindingObserver {
   String gameName = '全部游戏';
   bool isFirst = true;
   FocusNode _focusNode = new FocusNode();
+  List<PhoneInfo> phoneList = [];
 
   //展示通知
   void showNotice() {
@@ -168,6 +170,44 @@ class _MatchPageState extends State<MatchPage> with WidgetsBindingObserver {
     }
   }
 
+  Future<void> getPhoneInfo() async {
+    List<PhoneInfo> _phoneList = [];
+    Result res = await HttpManager.get('phoneInfo/all');
+    if (res.success && res.data != null) {
+      for (var item in res.data) {
+        PhoneInfo phone = PhoneInfo.fromJson(item);
+        _phoneList.add(phone);
+      }
+      setState(() {
+        phoneList = _phoneList;
+      });
+    }
+
+    final prefs = await SharedPreferences.getInstance();
+    var now = new DateTime.now();
+    var timeStr = now.year.toString() + '/' + now.month.toString() + '/' + now.day.toString();
+    prefs.setString('showPhoneInfo', timeStr);
+
+    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 LoadingDialog(
+            text: '部分手机自动设置了省电策略,会将我们的app在游戏进程中从后台停掉,为了你的正常比赛,请点击你的手机型号查看具体设置',
+            phoneList: phoneList,
+          );
+        },
+      ),
+    );
+  }
+
   @override
   void initState() {
     super.initState();
@@ -184,10 +224,16 @@ class _MatchPageState extends State<MatchPage> with WidgetsBindingObserver {
         }
       }
     });
-    Future.delayed(Duration.zero, () {
+    Future.delayed(Duration.zero, () async {
       getBannerInfo();
       getGame();
       getRoomInfo();
+      final prefs = await SharedPreferences.getInstance();
+      var now = new DateTime.now();
+      var timeStr = now.year.toString() + '/' + now.month.toString() + '/' + now.day.toString();
+      if (prefs.getString('showPhoneInfo') != timeStr) {
+        getPhoneInfo();
+      }
     });
   }
 
@@ -413,16 +459,16 @@ class _MatchPageState extends State<MatchPage> with WidgetsBindingObserver {
           _focusNode.unfocus();
         },
       ),
-      onWillPop: () {
+      onWillPop: () async {
         if (isFirst) {
           isFirst = false;
-          Toast.show(context, '再次点击退出程序', 1500, 'info');
-          Timer(Duration(seconds: 2), () {
+          Toast.show(context, '再次点击退出程序', 1000, 'info');
+          Timer(Duration(seconds: 1), () {
             isFirst = true;
           });
           return Future.value(false);
         } else {
-          return Future.value(true);
+          return await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
         }
       },
     );
@@ -465,3 +511,125 @@ class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
     return maxHeight != oldDelegate.maxHeight || minHeight != oldDelegate.minHeight || child != oldDelegate.child;
   }
 }
+
+typedef OnTapHomeMenu = void Function();
+
+class LoadingDialog extends Dialog {
+  String text;
+  final List<PhoneInfo> phoneList;
+
+  LoadingDialog({Key key, @required this.text, 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: 360,
+                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(text, style: TextStyle(color: Color(0xFFC2524D), fontSize: 14), textAlign: TextAlign.center),
+                          // 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: Center(
+                                          child: Text(phoneList[index].phone),
+                                        ),
+                                      ),
+                                      onTap: () {
+                                        var list = phoneList[index].image.split(',');
+                                        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);
+                                            },
+                                          ),
+                                        );
+                                      },
+                                    );
+                                  })),
+                          Container(
+                            child: LinearButton(
+                              btntext: '关闭',
+                              btnHeight: 36.0,
+                              colorList: [Color(0xFF271A21), Color(0xFF271A21)],
+                              textColor: Color(0xFFD4504B),
+                              textWeight: FontWeight.w400,
+                              onTapHomeMenu: () {
+                                Navigator.of(context).pop();
+                              },
+                            ),
+                          ),
+                          // 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);
+      },
+    );
+  }
+}

+ 47 - 0
lib/pages/PhotoView.dart

@@ -0,0 +1,47 @@
+import 'package:flutter/material.dart';
+import 'package:photo_view/photo_view.dart';
+import 'package:photo_view/photo_view_gallery.dart';
+
+class PhotoView extends StatefulWidget {
+  final List<String> imageList;
+  PhotoView({this.imageList = const []});
+
+  @override
+  _PhotoViewState createState() => _PhotoViewState();
+}
+
+class _PhotoViewState extends State<PhotoView> with WidgetsBindingObserver {
+  int nowIndex = 1;
+
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+      backgroundColor: Colors.black,
+      body: PhotoViewGallery.builder(
+        scrollPhysics: const BouncingScrollPhysics(),
+        builder: (BuildContext context, int index) {
+          return PhotoViewGalleryPageOptions(
+            imageProvider: NetworkImage(widget.imageList[index]),
+          );
+        },
+        itemCount: widget.imageList.length,
+        backgroundDecoration: BoxDecoration(color: Colors.black),
+        onPageChanged: (index) {
+          print(index);
+          setState(() {
+            nowIndex = index + 1;
+          });
+        },
+        // loadingChild: Center(
+        //   child: Text('加载中...',),
+
+        // )
+      ),
+      floatingActionButton: Container(
+        padding: EdgeInsets.all(30),
+        child: Text('${nowIndex}/${widget.imageList.length}', style: TextStyle(color: Colors.white)),
+      ),
+      floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
+    );
+  }
+}

+ 4 - 2
lib/widget/LinearButton.dart

@@ -11,6 +11,7 @@ class LinearButton extends StatelessWidget {
   final Color textColor;
   final num textSize;
   final num radius;
+  final FontWeight textWeight;
   LinearButton(
       {this.btntext = '',
       this.onTapHomeMenu,
@@ -19,7 +20,8 @@ class LinearButton extends StatelessWidget {
       this.childWidget,
       this.textColor = Colors.white,
       this.textSize = 16.0,
-      this.radius = 4.0});
+      this.radius = 4.0,
+      this.textWeight=FontWeight.w600});
 
   @override
   Widget build(BuildContext context) {
@@ -37,7 +39,7 @@ class LinearButton extends StatelessWidget {
               : Center(
                   child: Text(
                   btntext,
-                  style: TextStyle(fontSize: textSize, fontWeight: FontWeight.w600, color: textColor),
+                  style: TextStyle(fontSize: textSize, fontWeight: textWeight, color: textColor),
                 )),
         ),
       ),

+ 14 - 0
pubspec.lock

@@ -1,6 +1,13 @@
 # Generated by pub
 # See https://www.dartlang.org/tools/pub/glossary#lockfile
 packages:
+  after_layout:
+    dependency: transitive
+    description:
+      name: after_layout
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "1.0.7+2"
   analyzer:
     dependency: transitive
     description:
@@ -445,6 +452,13 @@ packages:
       url: "https://pub.dartlang.org"
     source: hosted
     version: "1.5.0"
+  photo_view:
+    dependency: "direct main"
+    description:
+      name: photo_view
+      url: "https://pub.dartlang.org"
+    source: hosted
+    version: "0.3.3"
   platform:
     dependency: transitive
     description:

+ 1 - 0
pubspec.yaml

@@ -42,6 +42,7 @@ dependencies:
   cached_network_image: ^0.8.0
   image_picker: ^0.6.0+4
   get_ip: ^0.3.0
+  photo_view: ^0.3.3
   fluwx:
     git:
       url: https://github.com/x1ongzhu/fluwx.git