import 'dart:io';
|
import 'dart:ui';
|
|
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
import 'package:flutter/services.dart';
|
import 'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart';
|
import 'package:location/ui/main/location.dart';
|
import 'package:location/ui/mine/advice.dart';
|
import 'package:location/ui/mine/permission.dart';
|
import 'package:location/utils/ui_constant.dart';
|
|
import 'ui/main/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,
|
));
|
}
|
|
if (Platform.isIOS) {
|
BMFMapSDK.setApiKeyAndCoordType(
|
'请输入百度开放平台申请的iOS端API KEY', BMF_COORD_TYPE.BD09LL);
|
} else if (Platform.isAndroid) {
|
// Android 目前不支持接口设置Apikey,
|
// 请在主工程的Manifest文件里设置,详细配置方法请参考[https://lbs.baidu.com/ 官网][https://lbs.baidu.com/)demo
|
BMFMapSDK.setCoordType(BMF_COORD_TYPE.BD09LL);
|
}
|
|
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>[];
|
|
@override
|
void initState() {
|
print("initState");
|
_pages
|
..add(AdvicePage(title: "建议"))
|
..add(LocationPage(title: "定位"))
|
..add(MinePage(title: "我的"));
|
|
super.initState();
|
}
|
|
//设置选中的导航栏
|
void setSelectIndex(int i) {
|
if (i == selectIndex) {
|
return;
|
}
|
setState(() {
|
selectIndex = i;
|
});
|
}
|
|
@override
|
Widget build(BuildContext context) {
|
print("build");
|
return Scaffold(
|
backgroundColor: Colors.white,
|
body: Container(
|
child: Stack(
|
children: [
|
//内容栏
|
Container(
|
color: Colors.white,
|
child: Flex(
|
direction: Axis.vertical,
|
children: [
|
Expanded(child: _pages[selectIndex]),
|
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/images/main/icon_main_nav_history.png",
|
width: 31,
|
),
|
iconHighlight: Image.asset(
|
"assets/images/main/icon_main_nav_history_highlight.png",
|
width: 31,
|
),
|
text: "轨迹",
|
index: 0)),
|
Container(
|
width: 54,
|
),
|
Expanded(
|
child: getNavItem(
|
icon: Image.asset(
|
"assets/images/main/icon_main_nav_mine.png",
|
width: 31),
|
iconHighlight: Image.asset(
|
"assets/images/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: () {
|
setState(() {
|
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/images/main/icon_main_nav_location.png",
|
height: 25,
|
),
|
Container(
|
height: 3,
|
),
|
Text(
|
"定位",
|
style: TextStyle(color: Colors.white, fontSize: 9),
|
)
|
],
|
),
|
));
|
}
|
}
|