lemmur-app-android/lib/pages/main/main_page.dart

104 lines
2.6 KiB
Dart
Raw Normal View History

2020-08-02 13:34:42 +02:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
2020-09-16 23:15:42 +02:00
import 'package:flutter_hooks/flutter_hooks.dart';
2021-10-31 16:45:34 +01:00
import '../../util/extensions/brightness.dart';
import '../communities_tab.dart';
import '../create_post.dart';
import '../home_tab.dart';
import '../profile_tab.dart';
import '../search_tab.dart';
2020-08-02 13:34:42 +02:00
2021-10-31 16:45:34 +01:00
enum AppTab {
home,
communities,
search,
profile,
}
class MainPage extends HookWidget {
const MainPage();
2021-01-03 19:43:39 +01:00
2021-10-31 16:45:34 +01:00
static const tabs = {
AppTab.home: HomeTab(),
AppTab.communities: CommunitiesTab(),
AppTab.search: SearchTab(),
AppTab.profile: UserProfileTab(),
};
2020-09-19 23:56:07 +02:00
2020-08-02 13:34:42 +02:00
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
2021-10-31 16:45:34 +01:00
final current = useState(AppTab.home);
2020-08-02 13:34:42 +02:00
useEffect(() {
2020-09-17 00:29:35 +02:00
Future.microtask(
() => SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemNavigationBarColor: theme.scaffoldBackgroundColor,
systemNavigationBarIconBrightness: theme.brightness.reverse,
2020-09-17 00:29:35 +02:00
)),
);
2020-08-02 13:34:42 +02:00
return null;
}, [theme.scaffoldBackgroundColor]);
2020-08-02 13:34:42 +02:00
2021-10-31 16:45:34 +01:00
tabButton(AppTab tab) {
2020-09-19 23:56:07 +02:00
return IconButton(
2021-10-31 16:45:34 +01:00
icon: Icon(tab.icon),
color: tab == current.value ? theme.colorScheme.secondary : null,
onPressed: () => current.value = tab,
2020-09-19 23:56:07 +02:00
);
}
return Scaffold(
2020-09-20 23:27:04 +02:00
extendBody: true,
body: Column(
children: [
Expanded(
child: IndexedStack(
2021-10-31 16:45:34 +01:00
index: tabs.keys.toList().indexOf(current.value),
children: tabs.values.toList(),
),
),
const SizedBox(height: kMinInteractiveDimension / 2),
],
2020-09-19 23:56:07 +02:00
),
2021-01-03 19:43:39 +01:00
floatingActionButton: const CreatePostFab(),
2020-09-19 23:56:07 +02:00
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
bottomNavigationBar: BottomAppBar(
2021-01-03 19:43:39 +01:00
shape: const CircularNotchedRectangle(),
2020-09-21 20:23:18 +02:00
notchMargin: 7,
2021-01-03 18:03:59 +01:00
child: SizedBox(
2020-09-19 23:56:07 +02:00
height: 60,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
2021-10-31 16:45:34 +01:00
tabButton(AppTab.home),
tabButton(AppTab.communities),
2021-01-03 19:43:39 +01:00
const SizedBox.shrink(),
const SizedBox.shrink(),
2021-10-31 16:45:34 +01:00
tabButton(AppTab.search),
tabButton(AppTab.profile),
2020-09-19 23:56:07 +02:00
],
),
),
),
);
}
2020-08-02 13:34:42 +02:00
}
2021-10-31 16:45:34 +01:00
extension on AppTab {
IconData get icon {
switch (this) {
case AppTab.home:
return Icons.home;
case AppTab.communities:
return Icons.list;
case AppTab.search:
return Icons.search;
case AppTab.profile:
return Icons.person;
}
}
}