2020-09-17 00:25:19 +02:00
|
|
|
import 'dart:async';
|
|
|
|
|
2020-08-02 13:34:42 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2020-09-17 00:25:19 +02:00
|
|
|
import 'package:flutter/services.dart';
|
2020-09-16 23:15:42 +02:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
2020-08-30 22:43:16 +02:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
2020-09-16 23:15:42 +02:00
|
|
|
import 'hooks/stores.dart';
|
2020-09-19 23:56:07 +02:00
|
|
|
import 'pages/communities_tab.dart';
|
2020-09-22 23:51:21 +02:00
|
|
|
import 'pages/create_post.dart';
|
2020-10-04 21:52:39 +02:00
|
|
|
import 'pages/home_tab.dart';
|
2020-09-17 00:29:35 +02:00
|
|
|
import 'pages/profile_tab.dart';
|
2020-09-01 13:22:37 +02:00
|
|
|
import 'stores/accounts_store.dart';
|
2020-08-30 22:43:16 +02:00
|
|
|
import 'stores/config_store.dart';
|
2020-08-02 13:34:42 +02:00
|
|
|
|
2020-08-31 17:52:16 +02:00
|
|
|
Future<void> main() async {
|
|
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
|
2020-09-16 23:22:04 +02:00
|
|
|
final configStore = ConfigStore();
|
2020-08-31 17:52:16 +02:00
|
|
|
await configStore.load();
|
|
|
|
|
2020-09-16 23:22:04 +02:00
|
|
|
final accountsStore = AccountsStore();
|
2020-09-01 13:22:37 +02:00
|
|
|
await accountsStore.load();
|
|
|
|
|
2020-08-30 22:43:16 +02:00
|
|
|
runApp(
|
|
|
|
MultiProvider(
|
|
|
|
providers: [
|
2020-10-25 22:33:44 +01:00
|
|
|
ChangeNotifierProvider.value(
|
|
|
|
value: configStore,
|
2020-08-30 22:43:16 +02:00
|
|
|
),
|
2020-10-26 00:43:37 +01:00
|
|
|
ChangeNotifierProvider.value(
|
|
|
|
value: accountsStore,
|
2020-09-01 13:22:37 +02:00
|
|
|
),
|
2020-08-30 22:43:16 +02:00
|
|
|
],
|
|
|
|
child: MyApp(),
|
|
|
|
),
|
|
|
|
);
|
2020-08-02 13:34:42 +02:00
|
|
|
}
|
|
|
|
|
2020-09-16 23:15:42 +02:00
|
|
|
class MyApp extends HookWidget {
|
2020-08-02 13:34:42 +02:00
|
|
|
@override
|
2020-09-16 23:15:42 +02:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final configStore = useConfigStore();
|
2020-10-25 22:33:44 +01:00
|
|
|
final maybeAmoledColor = configStore.amoledDarkMode ? Colors.black : null;
|
2020-09-16 23:15:42 +02:00
|
|
|
|
2020-10-25 22:33:44 +01:00
|
|
|
return MaterialApp(
|
|
|
|
title: 'Lemmur',
|
|
|
|
themeMode: configStore.theme,
|
|
|
|
darkTheme: ThemeData.dark().copyWith(
|
|
|
|
scaffoldBackgroundColor: maybeAmoledColor,
|
|
|
|
backgroundColor: maybeAmoledColor,
|
|
|
|
canvasColor: maybeAmoledColor,
|
|
|
|
cardColor: maybeAmoledColor,
|
|
|
|
splashColor: maybeAmoledColor,
|
|
|
|
),
|
|
|
|
theme: ThemeData(
|
|
|
|
visualDensity: VisualDensity.adaptivePlatformDensity,
|
|
|
|
),
|
|
|
|
home: MyHomePage(),
|
2020-09-16 23:15:42 +02:00
|
|
|
);
|
|
|
|
}
|
2020-08-02 13:34:42 +02:00
|
|
|
}
|
|
|
|
|
2020-09-17 00:25:19 +02:00
|
|
|
class MyHomePage extends HookWidget {
|
2020-09-19 23:56:07 +02:00
|
|
|
final List<Widget> pages = [
|
2020-10-04 21:52:39 +02:00
|
|
|
HomeTab(),
|
2020-09-19 23:56:07 +02:00
|
|
|
CommunitiesTab(),
|
|
|
|
Center(child: Text('search')), // TODO: search tab
|
|
|
|
UserProfileTab(),
|
|
|
|
];
|
|
|
|
|
2020-08-02 13:34:42 +02:00
|
|
|
@override
|
2020-09-17 00:25:19 +02:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final theme = Theme.of(context);
|
2020-09-19 23:56:07 +02:00
|
|
|
final currentTab = useState(0);
|
2020-08-02 13:34:42 +02:00
|
|
|
|
2020-09-17 00:25:19 +02:00
|
|
|
useEffect(() {
|
2020-09-17 00:29:35 +02:00
|
|
|
Future.microtask(
|
|
|
|
() => SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
|
|
|
|
systemNavigationBarColor: theme.scaffoldBackgroundColor,
|
|
|
|
)),
|
|
|
|
);
|
2020-08-02 13:34:42 +02:00
|
|
|
|
2020-09-17 00:25:19 +02:00
|
|
|
return null;
|
|
|
|
}, [theme.scaffoldBackgroundColor]);
|
2020-08-02 13:34:42 +02:00
|
|
|
|
2020-09-19 23:56:07 +02:00
|
|
|
var tabCounter = 0;
|
|
|
|
|
|
|
|
tabButton(IconData icon) {
|
|
|
|
final tabNum = tabCounter++;
|
|
|
|
|
|
|
|
return IconButton(
|
|
|
|
icon: Icon(icon),
|
|
|
|
color: tabNum == currentTab.value ? theme.accentColor : null,
|
|
|
|
onPressed: () => currentTab.value = tabNum,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Scaffold(
|
2020-09-20 23:27:04 +02:00
|
|
|
extendBody: true,
|
|
|
|
body: IndexedStack(
|
|
|
|
index: currentTab.value,
|
|
|
|
children: pages,
|
2020-09-19 23:56:07 +02:00
|
|
|
),
|
2020-09-22 23:51:21 +02:00
|
|
|
floatingActionButton: CreatePostFab(),
|
2020-09-19 23:56:07 +02:00
|
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
|
|
|
bottomNavigationBar: BottomAppBar(
|
|
|
|
shape: CircularNotchedRectangle(),
|
2020-09-21 20:23:18 +02:00
|
|
|
notchMargin: 7,
|
2020-09-19 23:56:07 +02:00
|
|
|
child: Container(
|
|
|
|
height: 60,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
|
|
children: [
|
|
|
|
tabButton(Icons.home),
|
|
|
|
tabButton(Icons.list),
|
2020-09-29 21:45:18 +02:00
|
|
|
SizedBox.shrink(),
|
|
|
|
SizedBox.shrink(),
|
2020-09-19 23:56:07 +02:00
|
|
|
tabButton(Icons.search),
|
|
|
|
tabButton(Icons.person),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2020-09-17 00:25:19 +02:00
|
|
|
}
|
2020-08-02 13:34:42 +02:00
|
|
|
}
|