import 'dart:io'; import 'package:ctjt_flutter/common/states.dart'; import 'package:ctjt_flutter/common/styles.dart'; import 'package:ctjt_flutter/common/time.dart'; import 'package:ctjt_flutter/widget/button.dart'; import 'package:ctjt_flutter/widget/contact.dart'; import 'package:ctjt_flutter/widget/drawer.dart'; import 'package:ctjt_flutter/widget/title.dart'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:provider/provider.dart'; // 首页 class HomePage extends StatefulWidget { HomePage({Key? key}) : super(key: key); @override _HomePageState createState() => _HomePageState(); } class _HomePageState extends State { int tts = 0; @override void initState() { super.initState(); // 初始化状态 States.init(context); // 显示隐私协议 Future.delayed(Duration(seconds: 1), () { var flag = Provider.of(context, listen: false).showContact; if (flag) { Contact.showUserContactDialog(context); } }); } @override void didChangeDependencies() { super.didChangeDependencies(); Styles.initSize(); // 在首页中初始化公共样式变量的值 } @override Widget build(BuildContext context) { return WillPopScope( // 响应Android返回按钮,需要在首页最外层包装此组件 child: Scaffold( backgroundColor: Colors.white, appBar: PageHead( leadingType: LeadingType.Menu, title: Text("Test"), ), // 左侧边栏 drawer: DrawerMenu(), body: Column( children: [ TButton( onPressed: () { Navigator.pushNamed(context, '/remote_call'); }, child: Text("呼叫测试")), ], )), onWillPop: () { if (Navigator.canPop(context)) { print('返回了 -- 回退一层'); Navigator.pop(context); } else { int ticks = TimeUtils.getDayNow(); if (ticks - tts <= 2000) { print('返回了 -- 退出程序'); exit(0); } else { print('返回了 -- 再按一次退出程序'); tts = ticks; Fluttertoast.showToast( msg: "再按一次退出程序", toastLength: Toast.LENGTH_LONG, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1); } } return new Future.value(false); }, ); } }