pikapika/lib/screens/AppScreen.dart

76 lines
1.7 KiB
Dart
Raw Normal View History

2021-09-29 23:57:09 +00:00
import 'package:flutter/material.dart';
2021-11-11 09:05:48 +00:00
import 'package:pikapika/basic/config/Version.dart';
import 'package:pikapika/screens/components/Badge.dart';
2021-09-29 23:57:09 +00:00
import 'CategoriesScreen.dart';
import 'SpaceScreen.dart';
// MAIN UI 底部导航栏
class AppScreen extends StatefulWidget {
const AppScreen({Key? key}) : super(key: key);
@override
State<AppScreen> createState() => _AppScreenState();
}
class _AppScreenState extends State<AppScreen> {
2021-11-11 09:05:48 +00:00
@override
void initState() {
versionEvent.subscribe(_onVersion);
super.initState();
}
@override
void dispose() {
versionEvent.unsubscribe(_onVersion);
super.dispose();
}
void _onVersion(dynamic a) {
setState(() {});
}
2021-11-29 03:26:30 +00:00
static const List<Widget> _widgetOptions = <Widget>[
const CategoriesScreen(),
const SpaceScreen(),
2021-09-29 23:57:09 +00:00
];
late int _selectedIndex = 0;
void _onItemTapped(int index) {
setState(() {
2021-11-29 03:26:30 +00:00
_selectedIndex = index;
2021-09-29 23:57:09 +00:00
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
2021-11-29 03:26:30 +00:00
body: IndexedStack(
index: _selectedIndex,
2021-09-29 23:57:09 +00:00
children: _widgetOptions,
),
bottomNavigationBar: BottomNavigationBar(
2021-11-11 09:05:48 +00:00
items: <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.public),
label: '浏览',
),
BottomNavigationBarItem(
icon: Badged(
child: Icon(Icons.face),
badge: latestVersion() == null ? null : "1",
),
label: '我的',
),
],
2021-09-29 23:57:09 +00:00
currentIndex: _selectedIndex,
iconSize: 20,
selectedFontSize: 12,
unselectedFontSize: 12,
onTap: _onItemTapped,
),
);
}
}