12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import 'dart:io';
- import 'package:eitc_erm_app/utils/Component.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'home.dart';
- import 'mine.dart';
- void main() {
- WidgetsFlutterBinding.ensureInitialized();
- runApp(BottomNavigationWidget());
- }
- class BottomNavigationWidget extends StatefulWidget {
- @override
- _BottomNavigationWidgetState createState() => _BottomNavigationWidgetState();
- }
- class _BottomNavigationWidgetState extends State<BottomNavigationWidget> {
- final bottomNavigationColor = Colors.blue;
- int curIndex = 0;
- List<Widget> pages = [];
- int lastExitTime = 0;
- @override
- void initState() {
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- pages
- ..add(Home(context))
- ..add(Mine());
- return PopScope(
- canPop: !Platform.isAndroid,
- onPopInvokedWithResult: _onPopInvoke,
- child: Scaffold(
- body: pages[curIndex],
- bottomNavigationBar: BottomNavigationBar(
- items: [
- BottomNavigationBarItem(
- icon: Icon(Icons.home, color: bottomNavigationColor),
- label: '首页',
- // title: Text('home1', style: TextStyle(color: bottomNavigationColor))
- ),
- BottomNavigationBarItem(
- icon: Icon(Icons.person, color: bottomNavigationColor),
- label: '我的',
- // title: Text('home', style: TextStyle(color: bottomNavigationColor))
- )
- ],
- currentIndex: curIndex,
- onTap: (int index) {
- setState(() {
- curIndex = index;
- });
- },
- fixedColor: Colors.blue,
- type: BottomNavigationBarType.fixed,
- ),
- ));
- }
- void _onPopInvoke(bool didPop, dynamic result) {
- if (didPop) {
- return;
- }
- int now = DateTime.now().millisecondsSinceEpoch;
- if (lastExitTime == 0 || now - lastExitTime > 2000) {
- Component.toast("再次点击退出应用", 2);
- lastExitTime = now;
- return;
- }
- SystemNavigator.pop(animated: true);
- }
- }
|