import 'dart:async';
|
import 'dart:io';
|
import 'dart:ui';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import 'package:flutter/services.dart';
|
import '../../api/http.dart';
|
import '../../ui/widget/dialog.dart';
|
import '../../utils/ad_util.dart';
|
import '../../utils/event_bus_util.dart';
|
import '../../utils/pageutils.dart';
|
import '../../utils/ui_constant.dart';
|
import '../../utils/ui_utils.dart';
|
import '../../utils/user_util.dart';
|
import 'mine.dart';
|
|
void main() {
|
if (Platform.isAndroid) {
|
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
statusBarColor: Colors.transparent,
|
systemNavigationBarColor: Color(0xFF000000),
|
systemNavigationBarDividerColor: null,
|
systemNavigationBarIconBrightness: Brightness.light,
|
statusBarIconBrightness: Brightness.dark,
|
statusBarBrightness: Brightness.light,
|
));
|
}
|
runApp(MyApp());
|
}
|
|
class MyApp extends StatelessWidget {
|
// This widget is the root of your application.
|
@override
|
Widget build(BuildContext context) {
|
return MaterialApp(
|
title: 'Flutter Demo',
|
theme: ThemeData(
|
// This is the theme of your application.
|
//
|
// Try running your application with "flutter run". You'll see the
|
// application has a blue toolbar. Then, without quitting the app, try
|
// changing the primarySwatch below to Colors.green and then invoke
|
// "hot reload" (press "r" in the console where you ran "flutter run",
|
// or simply save your changes to "hot reload" in a Flutter IDE).
|
// Notice that the counter didn't reset back to zero; the application
|
// is not restarted.
|
|
primaryColor: Color(0xFFFFFFFF)),
|
home: MainPage(title: ''),
|
);
|
}
|
}
|
|
class MainPage extends StatefulWidget {
|
MainPage({Key? key, required this.title}) : super(key: key);
|
|
// This widget is the home page of your application. It is stateful, meaning
|
// that it has a State object (defined below) that contains fields that affect
|
// how it looks.
|
|
// This class is the configuration for the state. It holds the values (in this
|
// case the title) provided by the parent (in this case the App widget) and
|
// used by the build method of the State. Fields in a Widget subclass are
|
// always marked "final".
|
|
final String title;
|
|
@override
|
_MainPageState createState() => _MainPageState();
|
}
|
|
class _MainPageState extends State<MainPage>
|
with SingleTickerProviderStateMixin {
|
int selectIndex = 1;
|
List<Widget> _pages = <Widget>[];
|
TabController? _tabController;
|
|
@override
|
void initState() {
|
_pages
|
// ..add(KeepAliveWrapper(child: MainTravelPage()))
|
// ..add(KeepAliveWrapper(child: LocationPage(title: "定位")))
|
..add(KeepAliveWrapper(child: MinePage(title: "我的")));
|
_tabController =
|
TabController(length: _pages.length, initialIndex: 1, vsync: this);
|
super.initState();
|
|
Timer(const Duration(seconds: 1), () {
|
AdUtil.getAdInfo(AdPosition.homeInterstitial).then((value) {
|
AdUtil.loadInterstitial(value, (success, msg) {});
|
});
|
});
|
|
UserUtil.updateUserInfo(context);
|
}
|
|
int lastCenterClick = 0;
|
|
//设置选中的导航栏
|
void setSelectIndex(int i) {
|
if (i == selectIndex) {
|
if (selectIndex == 1) {
|
if (DateTime.now().millisecondsSinceEpoch - lastCenterClick < 400) {
|
print("双击");
|
} else {
|
//单击
|
Future.delayed(const Duration(milliseconds: 400), () {
|
if (DateTime.now().millisecondsSinceEpoch - lastCenterClick <
|
400) {
|
return;
|
}
|
print("单击");
|
});
|
|
|
}
|
lastCenterClick = DateTime.now().millisecondsSinceEpoch;
|
}
|
return;
|
}
|
setState(() {
|
selectIndex = i;
|
});
|
print("setSelectIndex");
|
_tabController!.animateTo(i);
|
}
|
|
int lastBack = 0;
|
|
@override
|
Widget build(BuildContext context) {
|
return WillPopScope(
|
onWillPop: () async {
|
if (DateTime.now().millisecondsSinceEpoch - lastBack > 1000 * 5) {
|
lastBack = DateTime.now().millisecondsSinceEpoch;
|
ToastUtil.toast("再按一次退出应用");
|
return false;
|
} else {
|
return true;
|
}
|
},
|
child: Scaffold(
|
backgroundColor: Colors.white,
|
resizeToAvoidBottomInset: false,
|
body: Container(
|
child: Stack(
|
children: [
|
//内容栏
|
Container(
|
color: Colors.white,
|
child: Flex(
|
direction: Axis.vertical,
|
children: [
|
Expanded(
|
child: TabBarView(
|
controller: _tabController,
|
children: _pages,
|
physics: const NeverScrollableScrollPhysics(),
|
)),
|
Container(
|
height: 60,
|
)
|
],
|
),
|
),
|
|
//底部导航栏
|
Positioned(
|
bottom: 0,
|
child: Container(
|
child: Stack(
|
alignment: Alignment.bottomCenter,
|
children: [
|
Container(
|
height: 60,
|
width: MediaQuery.of(context).size.width,
|
alignment: Alignment.center,
|
decoration:
|
BoxDecoration(color: Colors.white, boxShadow: [
|
BoxShadow(
|
blurRadius: 10,
|
spreadRadius: 1,
|
color: Color(0x4D0E96FF),
|
)
|
]),
|
child: Flex(
|
direction: Axis.horizontal,
|
children: [
|
Expanded(
|
child: getNavItem(
|
icon: Image.asset(
|
"assets/imgs/main/icon_main_nav_history.png",
|
width: 31,
|
),
|
iconHighlight: Image.asset(
|
"assets/imgs/main/icon_main_nav_history_highlight.png",
|
width: 31,
|
),
|
text: "轨迹",
|
index: 0)),
|
Container(
|
width: 54,
|
),
|
Expanded(
|
child: getNavItem(
|
icon: Image.asset(
|
"assets/imgs/main/icon_main_nav_mine.png",
|
width: 31),
|
iconHighlight: Image.asset(
|
"assets/imgs/main/icon_main_nav_mine_highlight.png",
|
width: 31),
|
text: "我的",
|
index: 2)),
|
],
|
),
|
),
|
Positioned(
|
child: Container(
|
height: 72,
|
width: 72,
|
decoration: BoxDecoration(
|
color: Colors.white,
|
borderRadius: BorderRadius.circular(36),
|
boxShadow: [
|
BoxShadow(
|
blurRadius: 10,
|
spreadRadius: 1,
|
color: Color(0x4D0E96FF))
|
]),
|
),
|
),
|
Container(
|
height: 60,
|
width: 100,
|
color: Colors.white,
|
),
|
Container(
|
height: 72,
|
width: 72,
|
alignment: Alignment.center,
|
child: getNavLocationItem(),
|
)
|
],
|
)))
|
],
|
),
|
),
|
));
|
}
|
|
Widget getNavItem(
|
{required Image icon,
|
required Image iconHighlight,
|
required String text,
|
required int index}) {
|
return Container(
|
alignment: Alignment.center,
|
child: InkWell(
|
onTap: () {
|
setSelectIndex(index);
|
},
|
child: Flex(
|
mainAxisAlignment: MainAxisAlignment.center,
|
direction: Axis.horizontal,
|
children: [
|
selectIndex == index ? iconHighlight : icon,
|
Text(
|
text,
|
style: TextStyle(
|
fontSize: 15,
|
color: selectIndex == index
|
? ColorConstant.theme
|
: Color(0xFF9DAAB3)),
|
)
|
],
|
),
|
),
|
);
|
}
|
|
Widget getNavLocationItem() {
|
return InkWell(
|
onTap: () {
|
setSelectIndex(1);
|
},
|
child: Container(
|
width: 54,
|
height: 54,
|
decoration: BoxDecoration(
|
color: selectIndex == 1 ? ColorConstant.theme : Color(0xFF9DAAB3),
|
borderRadius: BorderRadius.circular(27),
|
boxShadow: selectIndex == 1
|
? [
|
BoxShadow(
|
blurRadius: 3,
|
spreadRadius: 2,
|
color: Color(0x4D0E96FF))
|
]
|
: []),
|
child: Flex(
|
direction: Axis.vertical,
|
mainAxisAlignment: MainAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
children: [
|
Image.asset(
|
"assets/imgs/main/icon_main_nav_location.png",
|
height: 25,
|
),
|
Container(
|
height: 3,
|
),
|
const Text(
|
"定位",
|
style: TextStyle(color: Colors.white, fontSize: 9),
|
)
|
],
|
),
|
));
|
}
|
}
|