Rename Home to Main
This commit is contained in:
parent
52bd797eb8
commit
52d986d693
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:keyboard_dismisser/keyboard_dismisser.dart';
|
import 'package:keyboard_dismisser/keyboard_dismisser.dart';
|
||||||
|
|
||||||
import 'l10n/l10n.dart';
|
import 'l10n/l10n.dart';
|
||||||
import 'pages/home_page.dart';
|
import 'pages/main/main_page.dart';
|
||||||
import 'resources/theme.dart';
|
import 'resources/theme.dart';
|
||||||
import 'stores/config_store.dart';
|
import 'stores/config_store.dart';
|
||||||
import 'util/observer_consumers.dart';
|
import 'util/observer_consumers.dart';
|
||||||
|
@ -22,7 +22,7 @@ class MyApp extends StatelessWidget {
|
||||||
darkTheme: store.amoledDarkMode ? amoledTheme : darkTheme,
|
darkTheme: store.amoledDarkMode ? amoledTheme : darkTheme,
|
||||||
locale: store.locale,
|
locale: store.locale,
|
||||||
theme: lightTheme,
|
theme: lightTheme,
|
||||||
home: const HomePage(),
|
home: const MainPage(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,27 +2,34 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
|
|
||||||
import '../util/extensions/brightness.dart';
|
import '../../util/extensions/brightness.dart';
|
||||||
import 'communities_tab.dart';
|
import '../communities_tab.dart';
|
||||||
import 'create_post.dart';
|
import '../create_post.dart';
|
||||||
import 'home_tab.dart';
|
import '../home_tab.dart';
|
||||||
import 'profile_tab.dart';
|
import '../profile_tab.dart';
|
||||||
import 'search_tab.dart';
|
import '../search_tab.dart';
|
||||||
|
|
||||||
class HomePage extends HookWidget {
|
enum AppTab {
|
||||||
const HomePage();
|
home,
|
||||||
|
communities,
|
||||||
|
search,
|
||||||
|
profile,
|
||||||
|
}
|
||||||
|
|
||||||
static const List<Widget> pages = [
|
class MainPage extends HookWidget {
|
||||||
HomeTab(),
|
const MainPage();
|
||||||
CommunitiesTab(),
|
|
||||||
SearchTab(),
|
static const tabs = {
|
||||||
UserProfileTab(),
|
AppTab.home: HomeTab(),
|
||||||
];
|
AppTab.communities: CommunitiesTab(),
|
||||||
|
AppTab.search: SearchTab(),
|
||||||
|
AppTab.profile: UserProfileTab(),
|
||||||
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final currentTab = useState(0);
|
final current = useState(AppTab.home);
|
||||||
|
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
Future.microtask(
|
Future.microtask(
|
||||||
|
@ -35,15 +42,11 @@ class HomePage extends HookWidget {
|
||||||
return null;
|
return null;
|
||||||
}, [theme.scaffoldBackgroundColor]);
|
}, [theme.scaffoldBackgroundColor]);
|
||||||
|
|
||||||
var tabCounter = 0;
|
tabButton(AppTab tab) {
|
||||||
|
|
||||||
tabButton(IconData icon) {
|
|
||||||
final tabNum = tabCounter++;
|
|
||||||
|
|
||||||
return IconButton(
|
return IconButton(
|
||||||
icon: Icon(icon),
|
icon: Icon(tab.icon),
|
||||||
color: tabNum == currentTab.value ? theme.colorScheme.secondary : null,
|
color: tab == current.value ? theme.colorScheme.secondary : null,
|
||||||
onPressed: () => currentTab.value = tabNum,
|
onPressed: () => current.value = tab,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,8 +56,8 @@ class HomePage extends HookWidget {
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: IndexedStack(
|
child: IndexedStack(
|
||||||
index: currentTab.value,
|
index: tabs.keys.toList().indexOf(current.value),
|
||||||
children: pages,
|
children: tabs.values.toList(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: kMinInteractiveDimension / 2),
|
const SizedBox(height: kMinInteractiveDimension / 2),
|
||||||
|
@ -70,12 +73,12 @@ class HomePage extends HookWidget {
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
children: [
|
children: [
|
||||||
tabButton(Icons.home),
|
tabButton(AppTab.home),
|
||||||
tabButton(Icons.list),
|
tabButton(AppTab.communities),
|
||||||
const SizedBox.shrink(),
|
const SizedBox.shrink(),
|
||||||
const SizedBox.shrink(),
|
const SizedBox.shrink(),
|
||||||
tabButton(Icons.search),
|
tabButton(AppTab.search),
|
||||||
tabButton(Icons.person),
|
tabButton(AppTab.profile),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -83,3 +86,18 @@ class HomePage extends HookWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue