2023-03-20 17:43:32 +08:00
|
|
|
|
import 'package:bistro/common/global.dart';
|
2023-03-29 14:47:31 +08:00
|
|
|
|
import 'package:bistro/router/router_table.dart';
|
2022-02-18 18:44:57 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
2023-03-20 17:43:32 +08:00
|
|
|
|
import 'package:flutter/services.dart';
|
2023-03-20 15:52:49 +08:00
|
|
|
|
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
2023-03-29 14:47:31 +08:00
|
|
|
|
import 'package:flutter_web_plugins/url_strategy.dart';
|
2022-02-22 22:10:18 +08:00
|
|
|
|
|
2022-02-21 14:51:53 +08:00
|
|
|
|
// import 'package:flutter_localizations/flutter_localizations.dart';
|
|
|
|
|
|
import 'app.dart';
|
|
|
|
|
|
import 'life.dart';
|
|
|
|
|
|
import 'mine.dart';
|
2022-02-21 20:01:39 +08:00
|
|
|
|
import 'news.dart';
|
2022-02-18 18:44:57 +08:00
|
|
|
|
|
2022-02-22 22:10:18 +08:00
|
|
|
|
void main() {
|
2023-03-29 14:47:31 +08:00
|
|
|
|
// 保证核心已启动
|
2022-02-22 22:10:18 +08:00
|
|
|
|
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
|
2023-03-29 14:47:31 +08:00
|
|
|
|
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
|
|
|
|
|
|
|
|
|
|
|
|
//
|
2023-03-20 17:43:32 +08:00
|
|
|
|
SystemChrome.setEnabledSystemUIMode(
|
|
|
|
|
|
SystemUiMode.edgeToEdge,
|
|
|
|
|
|
overlays: [SystemUiOverlay.bottom, SystemUiOverlay.top],
|
|
|
|
|
|
);
|
2023-03-29 14:47:31 +08:00
|
|
|
|
|
|
|
|
|
|
// 只允许竖屏
|
|
|
|
|
|
SystemChrome.setPreferredOrientations(
|
|
|
|
|
|
[
|
|
|
|
|
|
DeviceOrientation.portraitUp, // 竖屏 Portrait 模式
|
|
|
|
|
|
DeviceOrientation.portraitDown,
|
|
|
|
|
|
// DeviceOrientation.landscapeLeft, // 横屏 Landscape 模式
|
|
|
|
|
|
// DeviceOrientation.landscapeRight,
|
|
|
|
|
|
],
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// web 使用 path(history)路由
|
|
|
|
|
|
usePathUrlStrategy();
|
|
|
|
|
|
|
|
|
|
|
|
runApp(Bistro());
|
2022-02-22 22:10:18 +08:00
|
|
|
|
}
|
2022-02-18 18:44:57 +08:00
|
|
|
|
|
2022-02-21 14:51:53 +08:00
|
|
|
|
class Bistro extends StatelessWidget {
|
2023-03-29 14:47:31 +08:00
|
|
|
|
final GlobalKey<NavigatorState> navigationKey = GlobalKey<NavigatorState>();
|
|
|
|
|
|
|
|
|
|
|
|
Bistro({Key? key}) : super(key: key);
|
2022-02-18 18:44:57 +08:00
|
|
|
|
|
|
|
|
|
|
// This widget is the root of your application.
|
|
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
|
return MaterialApp(
|
2022-02-21 14:51:53 +08:00
|
|
|
|
title: '小酒馆',
|
2022-02-18 18:44:57 +08:00
|
|
|
|
theme: ThemeData(
|
2022-02-21 18:50:14 +08:00
|
|
|
|
fontFamily: "SongTiHeavy",
|
2023-03-20 17:43:32 +08:00
|
|
|
|
primaryColor: const Color(0xFFD56937),
|
|
|
|
|
|
primaryColorDark: const Color(0xFFD56937),
|
2023-03-29 14:47:31 +08:00
|
|
|
|
// appBarTheme: const AppBarTheme(color: Color(0xff384444)),
|
2023-03-27 18:19:56 +08:00
|
|
|
|
navigationBarTheme: const NavigationBarThemeData(
|
2023-03-29 14:47:31 +08:00
|
|
|
|
indicatorColor: Color(0xFFD56937),
|
|
|
|
|
|
labelTextStyle: MaterialStatePropertyAll(
|
|
|
|
|
|
TextStyle(
|
|
|
|
|
|
// color: Color(0xffd56937),
|
|
|
|
|
|
),
|
|
|
|
|
|
),
|
2023-03-27 18:19:56 +08:00
|
|
|
|
),
|
2023-03-20 17:43:32 +08:00
|
|
|
|
colorScheme: const ColorScheme.dark(
|
2023-03-27 16:48:10 +08:00
|
|
|
|
primary: Color(0xFFD56937),
|
|
|
|
|
|
secondary: Color(0xFFC8C2B4),
|
2023-03-29 14:47:31 +08:00
|
|
|
|
tertiary: Color(0xff384444),
|
|
|
|
|
|
background: Color(0xff2a2a22),
|
2023-03-27 16:48:10 +08:00
|
|
|
|
),
|
2023-03-27 18:19:56 +08:00
|
|
|
|
useMaterial3: true,
|
2022-02-21 18:50:14 +08:00
|
|
|
|
),
|
2023-03-29 14:47:31 +08:00
|
|
|
|
themeMode: ThemeMode.system,
|
2022-02-21 18:50:14 +08:00
|
|
|
|
home: const BistroFrame(
|
|
|
|
|
|
title: '小酒馆',
|
|
|
|
|
|
),
|
2022-02-21 14:51:53 +08:00
|
|
|
|
// 路由
|
2023-03-29 14:47:31 +08:00
|
|
|
|
// routes: RouterTable.routeTables,
|
|
|
|
|
|
navigatorKey: navigationKey,
|
|
|
|
|
|
onGenerateRoute: RouterTable.onGenerateRoute,
|
|
|
|
|
|
initialRoute: RouterTable.homePath,
|
2022-02-18 18:44:57 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-21 14:51:53 +08:00
|
|
|
|
class BistroFrame extends StatefulWidget {
|
2022-02-21 18:50:14 +08:00
|
|
|
|
const BistroFrame({Key? key, required this.title}) : super(key: key);
|
2022-02-18 18:44:57 +08:00
|
|
|
|
|
|
|
|
|
|
final String title;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
2023-03-20 15:52:49 +08:00
|
|
|
|
BistroFrameState createState() => BistroFrameState();
|
2022-02-18 18:44:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-20 15:52:49 +08:00
|
|
|
|
class BistroFrameState extends State<BistroFrame> {
|
2022-02-21 14:51:53 +08:00
|
|
|
|
late Widget _body;
|
2023-03-29 14:47:31 +08:00
|
|
|
|
late int _index = 2;
|
|
|
|
|
|
final List<int> loginRequired = [3];
|
2022-02-21 20:14:46 +08:00
|
|
|
|
|
2022-02-21 20:01:39 +08:00
|
|
|
|
static const List<Map<String, dynamic>> _iconList = [
|
|
|
|
|
|
{
|
2022-02-21 20:20:31 +08:00
|
|
|
|
"title": "满席",
|
2022-02-21 20:14:46 +08:00
|
|
|
|
"icon": Icons.storefront_outlined,
|
2023-03-29 14:47:31 +08:00
|
|
|
|
"selectedIcon": Icons.storefront_rounded,
|
2022-02-21 20:01:39 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"title": "道听",
|
2022-02-21 20:14:46 +08:00
|
|
|
|
"icon": Icons.forum_outlined,
|
2023-03-29 14:47:31 +08:00
|
|
|
|
"selectedIcon": Icons.forum_rounded,
|
2022-02-21 20:01:39 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
"title": "途说",
|
2022-02-21 20:14:46 +08:00
|
|
|
|
"icon": Icons.supervisor_account_outlined,
|
2023-03-29 14:47:31 +08:00
|
|
|
|
"selectedIcon": Icons.supervisor_account_rounded,
|
2022-02-21 20:01:39 +08:00
|
|
|
|
},
|
|
|
|
|
|
{
|
2022-02-21 20:20:31 +08:00
|
|
|
|
"title": "在下",
|
2022-02-21 20:14:46 +08:00
|
|
|
|
"icon": Icons.person_outline,
|
2023-03-29 14:47:31 +08:00
|
|
|
|
"selectedIcon": Icons.person_rounded,
|
2022-02-21 20:01:39 +08:00
|
|
|
|
},
|
|
|
|
|
|
];
|
2022-02-18 18:44:57 +08:00
|
|
|
|
|
2022-02-22 22:10:18 +08:00
|
|
|
|
@override
|
|
|
|
|
|
initState() {
|
2022-02-21 14:51:53 +08:00
|
|
|
|
//页面初始化时要干的事
|
2022-02-22 22:10:18 +08:00
|
|
|
|
super.initState();
|
|
|
|
|
|
|
|
|
|
|
|
initialization();
|
2023-03-29 14:47:31 +08:00
|
|
|
|
Global.init(context);
|
2022-02-22 22:10:18 +08:00
|
|
|
|
}
|
2022-02-21 20:01:39 +08:00
|
|
|
|
|
2022-02-22 22:10:18 +08:00
|
|
|
|
void initData() {
|
2022-02-21 14:51:53 +08:00
|
|
|
|
_body = IndexedStack(
|
2023-03-20 15:52:49 +08:00
|
|
|
|
index: _index,
|
|
|
|
|
|
children: const <Widget>[
|
|
|
|
|
|
App(),
|
2022-02-21 14:51:53 +08:00
|
|
|
|
News(),
|
2023-03-20 15:52:49 +08:00
|
|
|
|
Life(),
|
|
|
|
|
|
Mine(),
|
2022-02-21 14:51:53 +08:00
|
|
|
|
],
|
|
|
|
|
|
);
|
2022-02-18 18:44:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-22 22:10:18 +08:00
|
|
|
|
void initialization() async {
|
|
|
|
|
|
// This is where you can initialize the resources needed by your app while
|
|
|
|
|
|
// the splash screen is displayed. Remove the following example because
|
|
|
|
|
|
// delaying the user experience is a bad design practice!
|
2023-03-20 15:52:49 +08:00
|
|
|
|
// if (kDebugMode) {
|
|
|
|
|
|
// print('ready in 3...');
|
|
|
|
|
|
// }
|
|
|
|
|
|
// await Future.delayed(const Duration(seconds: 1));
|
2023-03-20 17:43:32 +08:00
|
|
|
|
// if (kDebugMode) {
|
|
|
|
|
|
// print('ready in 2...');
|
|
|
|
|
|
// }
|
|
|
|
|
|
// await Future.delayed(const Duration(seconds: 1));
|
2023-03-29 14:47:31 +08:00
|
|
|
|
// await Future.delayed(const Duration(seconds: 1));
|
|
|
|
|
|
// printWhenDebug('go!');
|
2023-03-20 17:57:09 +08:00
|
|
|
|
FlutterNativeSplash.remove();
|
2022-02-22 22:10:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-18 18:44:57 +08:00
|
|
|
|
@override
|
|
|
|
|
|
Widget build(BuildContext context) {
|
2022-02-21 14:51:53 +08:00
|
|
|
|
initData();
|
|
|
|
|
|
|
2023-03-29 14:47:31 +08:00
|
|
|
|
List<NavigationDestination> bottomNavigationBarData = [];
|
|
|
|
|
|
for (var i = 0; i < 4; i++) {
|
|
|
|
|
|
NavigationDestination itemWidget = bottomAppBarItem(index: i);
|
2022-02-21 20:01:39 +08:00
|
|
|
|
bottomNavigationBarData.add(itemWidget);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-02-18 18:44:57 +08:00
|
|
|
|
return Scaffold(
|
2023-03-29 14:47:31 +08:00
|
|
|
|
appBar: AppBar(
|
|
|
|
|
|
title: Text(_iconList[_index]['title']),
|
|
|
|
|
|
systemOverlayStyle: const SystemUiOverlayStyle(
|
|
|
|
|
|
statusBarColor: Colors.transparent, //设置为透明
|
|
|
|
|
|
),
|
2022-02-21 14:51:53 +08:00
|
|
|
|
),
|
2023-03-29 14:47:31 +08:00
|
|
|
|
body: _body,
|
2022-02-21 14:51:53 +08:00
|
|
|
|
floatingActionButton: FloatingActionButton(
|
2023-03-27 18:19:56 +08:00
|
|
|
|
enableFeedback: true,
|
2023-03-20 15:52:49 +08:00
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.background,
|
2022-02-21 14:51:53 +08:00
|
|
|
|
onPressed: () => {},
|
|
|
|
|
|
child: Icon(
|
|
|
|
|
|
Icons.search,
|
|
|
|
|
|
color: Theme.of(context).primaryColor,
|
|
|
|
|
|
),
|
2022-02-18 18:44:57 +08:00
|
|
|
|
),
|
2023-03-29 14:47:31 +08:00
|
|
|
|
bottomNavigationBar: NavigationBar(
|
|
|
|
|
|
selectedIndex: _index,
|
|
|
|
|
|
destinations: bottomNavigationBarData,
|
|
|
|
|
|
onDestinationSelected: (int index) {
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
_index = index;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
loginRequired.forEach((index) {
|
|
|
|
|
|
if (_index == index) {
|
|
|
|
|
|
Navigator.of(context).pushNamed(RouterTable.loginPath);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
),
|
2022-02-21 14:51:53 +08:00
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-29 14:47:31 +08:00
|
|
|
|
NavigationDestination bottomAppBarItem({
|
2022-02-21 14:51:53 +08:00
|
|
|
|
required int index, // 序列
|
|
|
|
|
|
}) {
|
2022-02-21 20:01:39 +08:00
|
|
|
|
Map<String, dynamic> item = _iconList[index];
|
|
|
|
|
|
|
2023-03-29 14:47:31 +08:00
|
|
|
|
NavigationDestination child = NavigationDestination(
|
|
|
|
|
|
icon: Icon(item['icon']),
|
|
|
|
|
|
label: item["title"],
|
|
|
|
|
|
selectedIcon: Icon(item['selectedIcon']),
|
|
|
|
|
|
);
|
2022-02-21 14:51:53 +08:00
|
|
|
|
|
2023-03-27 18:19:56 +08:00
|
|
|
|
return child;
|
2022-02-18 18:44:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|