ModelOfTheTime/lib/main.dart
2024-09-05 20:18:11 +08:00

102 lines
2.9 KiB
Dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:model_of_the_times/entities/ViewInformation.dart';
import 'package:model_of_the_times/icons/material_design_icons.dart';
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';
import 'package:model_of_the_times/views/home.dart';
import 'package:model_of_the_times/views/learned.dart';
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(
title: '时代楷模',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.red, surface: Colors.white),
useMaterial3: true,
),
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();
}
)
);
}
}
class MainPage extends StatefulWidget {
const MainPage({super.key});
@override
State<MainPage> createState() => _MainPageState();
}
class _MainPageState extends State<MainPage> {
int _nowPageIndex = 0;
final List<ViewInformation> _pages = [
ViewInformation(const HomeView(), "时代楷模"),
ViewInformation(const Activity(), "公益活动"),
ViewInformation(const Learned(), "学习心得")
];
@override
Widget build(BuildContext context) {
final page = _pages[_nowPageIndex];
return Scaffold(
appBar: AppBar(
title: Text(
page.title,
style: const TextStyle(
color: Colors.red
),
),
centerTitle: true,
),
body: page.view,
bottomNavigationBar: BottomNavigationBar(
onTap: (newIndex){
if (newIndex >= _pages.length) {
return;
}
setState(() {
_nowPageIndex = newIndex;
});
},
currentIndex: _nowPageIndex,
type: BottomNavigationBarType.fixed,
items: const [
BottomNavigationBarItem(
icon: Icon(MaterialDesign.home),
label: "首页"
),
BottomNavigationBarItem(
icon: Icon(MaterialDesign.feedback),
label: "公益"
),
BottomNavigationBarItem(
icon: Icon(MaterialDesign.favorite),
label: "心得"
),
BottomNavigationBarItem(
icon: Icon(MaterialDesign.view_stream),
label: "数据分析"
),
]
),
);
}
}