112 lines
3.4 KiB
Dart
112 lines
3.4 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:environmental_protection/common/user_information.dart';
|
|
import 'package:environmental_protection/icon/material_design_icons.dart';
|
|
import 'package:environmental_protection/views/home.dart';
|
|
import 'package:environmental_protection/views/me.dart';
|
|
import 'package:environmental_protection/views/service.dart';
|
|
import 'package:environmental_protection/views/social.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
main() async {
|
|
var global = GlobalInformation.getInstance();
|
|
var response = await global.requester.post(resolve("api/login"), body: jsonEncode({
|
|
'username': 'WUvFG3gY',
|
|
'password': 'ZogPgBF6'
|
|
}));
|
|
print(response.body);
|
|
global.token = jsonDecode(response.body)['token'];
|
|
runApp(const DigitalLife());
|
|
}
|
|
class DigitalLife extends StatelessWidget {
|
|
const DigitalLife({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return const MaterialApp(
|
|
home: RouterView(),
|
|
);
|
|
}
|
|
}
|
|
class RouterView extends StatefulWidget {
|
|
const RouterView({super.key});
|
|
|
|
@override
|
|
State<RouterView> createState() => _RouterViewState();
|
|
}
|
|
|
|
class _RouterViewState extends State<RouterView> {
|
|
int _pageIndex = 0;
|
|
final List<Widget> _pages = [
|
|
const HomePage(),
|
|
const SocialPage(),
|
|
const Placeholder(),
|
|
const ServicePage(),
|
|
const MePage()
|
|
];
|
|
final String _name = "红星海五期";
|
|
GlobalInformation? _globalInformation;
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
_globalInformation ??= GlobalInformation.getInstance(super.setState);
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(_name),
|
|
actions: [
|
|
IconButton(onPressed: (){}, icon: const Icon(MaterialDesign.crop_free)),
|
|
],
|
|
centerTitle: true,
|
|
leading: Center(
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
IconButton(onPressed: (){}, icon: const Icon(Icons.keyboard_arrow_left)),
|
|
const Text("数字社区")
|
|
],
|
|
),
|
|
),
|
|
leadingWidth: 120,
|
|
),
|
|
bottomNavigationBar: BottomNavigationBar(
|
|
currentIndex: _pageIndex,
|
|
items: const [
|
|
BottomNavigationBarItem(icon: Icon(Icons.home), label: "首页"),
|
|
BottomNavigationBarItem(icon: Icon(Icons.group), label: "友邻社交"),
|
|
BottomNavigationBarItem(icon: Icon(null), label: ""),
|
|
BottomNavigationBarItem(icon: Icon(Icons.account_balance), label: "社区服务"),
|
|
BottomNavigationBarItem(icon: Icon(Icons.account_box), label: "我的")
|
|
],
|
|
selectedItemColor: Colors.blue,
|
|
unselectedItemColor: Colors.grey,
|
|
showUnselectedLabels: true,
|
|
type: BottomNavigationBarType.fixed,
|
|
onTap: (i){
|
|
if (i == 2){
|
|
return;
|
|
}
|
|
if (i > 2){
|
|
Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => _pages[i],
|
|
),
|
|
);
|
|
return;
|
|
}
|
|
setState(() {
|
|
_pageIndex = i;
|
|
});
|
|
},
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: () { },
|
|
shape: const CircleBorder(),
|
|
backgroundColor: Colors.blue,
|
|
foregroundColor: Colors.white,
|
|
child: const Icon(Icons.add, size: 50),
|
|
),
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
|
body: _pages[_pageIndex],
|
|
);
|
|
}
|
|
} |