ModelOfTheTime/lib/main.dart

102 lines
2.9 KiB
Dart
Raw Normal View History

2024-09-05 20:18:11 +08:00
import 'dart:convert';
2024-09-03 16:50:16 +08:00
import 'package:flutter/material.dart';
2024-09-04 19:04:29 +08:00
import 'package:model_of_the_times/entities/ViewInformation.dart';
import 'package:model_of_the_times/icons/material_design_icons.dart';
2024-09-05 20:18:11 +08:00
import 'package:model_of_the_times/requester/requester.dart';
import 'package:model_of_the_times/views/activity.dart';
import 'package:model_of_the_times/views/common/data_required.dart';
2024-09-04 19:04:29 +08:00
import 'package:model_of_the_times/views/home.dart';
2024-09-05 20:18:11 +08:00
import 'package:model_of_the_times/views/learned.dart';
2024-09-03 16:50:16 +08:00
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
2024-09-04 19:04:29 +08:00
title: '时代楷模',
2024-09-03 16:50:16 +08:00
theme: ThemeData(
2024-09-05 20:18:11 +08:00
colorScheme: ColorScheme.fromSeed(seedColor: Colors.red, surface: Colors.white),
2024-09-03 16:50:16 +08:00
useMaterial3: true,
),
2024-09-05 20:18:11 +08:00
home: DataRequired(
fetchData: (global) async {
var data = await global.requester.post(resolve("/app/login"), body: jsonEncode({'username': 'WUvFG3gY','password': 'ZogPgBF6'}));
return jsonFromResponse(data);
},
afterLoading: (data){
GlobalInformation.getInstance().token = data['token'];
return const MainPage();
}
)
2024-09-03 16:50:16 +08:00
);
}
}
2024-09-04 19:04:29 +08:00
class MainPage extends StatefulWidget {
const MainPage({super.key});
2024-09-03 16:50:16 +08:00
@override
2024-09-04 19:04:29 +08:00
State<MainPage> createState() => _MainPageState();
2024-09-03 16:50:16 +08:00
}
2024-09-04 19:04:29 +08:00
class _MainPageState extends State<MainPage> {
int _nowPageIndex = 0;
final List<ViewInformation> _pages = [
2024-09-05 20:18:11 +08:00
ViewInformation(const HomeView(), "时代楷模"),
ViewInformation(const Activity(), "公益活动"),
ViewInformation(const Learned(), "学习心得")
2024-09-04 19:04:29 +08:00
];
2024-09-03 16:50:16 +08:00
@override
Widget build(BuildContext context) {
2024-09-04 19:04:29 +08:00
final page = _pages[_nowPageIndex];
2024-09-03 16:50:16 +08:00
return Scaffold(
appBar: AppBar(
2024-09-04 19:04:29 +08:00
title: Text(
page.title,
style: const TextStyle(
color: Colors.red
),
2024-09-03 16:50:16 +08:00
),
2024-09-04 19:04:29 +08:00
centerTitle: true,
),
body: page.view,
bottomNavigationBar: BottomNavigationBar(
onTap: (newIndex){
2024-09-05 20:18:11 +08:00
if (newIndex >= _pages.length) {
return;
}
2024-09-04 19:04:29 +08:00
setState(() {
_nowPageIndex = newIndex;
});
},
2024-09-05 20:18:11 +08:00
currentIndex: _nowPageIndex,
2024-09-04 19:04:29 +08:00
type: BottomNavigationBarType.fixed,
items: const [
BottomNavigationBarItem(
icon: Icon(MaterialDesign.home),
label: "首页"
),
BottomNavigationBarItem(
icon: Icon(MaterialDesign.feedback),
2024-09-05 20:18:11 +08:00
label: "公益"
2024-09-04 19:04:29 +08:00
),
BottomNavigationBarItem(
icon: Icon(MaterialDesign.favorite),
label: "心得"
),
BottomNavigationBarItem(
icon: Icon(MaterialDesign.view_stream),
label: "数据分析"
),
]
2024-09-03 16:50:16 +08:00
),
);
}
2024-09-04 19:04:29 +08:00
}