frosty/lib/screens/home/home.dart

116 lines
3.4 KiB
Dart
Raw Normal View History

2021-08-25 00:47:01 -04:00
import 'package:flutter/material.dart';
2021-10-01 00:10:50 -04:00
import 'package:flutter_mobx/flutter_mobx.dart';
2021-11-21 23:29:47 -05:00
import 'package:frosty/core/auth/auth_store.dart';
import 'package:frosty/core/settings/settings.dart';
import 'package:frosty/core/settings/settings_store.dart';
import 'package:frosty/screens/followed_streams/followed_streams.dart';
import 'package:frosty/screens/followed_streams/followed_streams_store.dart';
2021-11-21 23:29:47 -05:00
import 'package:frosty/screens/search/search.dart';
2021-11-22 01:26:17 -05:00
import 'package:frosty/screens/search/search_store.dart';
import 'package:frosty/screens/top/categories/categories_store.dart';
import 'package:frosty/screens/top/streams/top_streams_store.dart';
import 'package:frosty/screens/top/top_section.dart';
import 'package:provider/provider.dart';
2021-11-14 23:18:43 -05:00
class Home extends StatefulWidget {
2021-11-22 01:26:17 -05:00
final TopStreamsStore topStreamsStore;
final FollowedStreamsStore followedStreamsStore;
final CategoriesStore categoriesStore;
final SearchStore searchStore;
const Home({
Key? key,
2021-11-22 01:26:17 -05:00
required this.topStreamsStore,
required this.followedStreamsStore,
required this.categoriesStore,
required this.searchStore,
}) : super(key: key);
2021-08-25 00:47:01 -04:00
@override
_HomeState createState() => _HomeState();
}
class _HomeState extends State<Home> {
int _selectedIndex = 0;
void _handleTap(int index) {
if (index != _selectedIndex) {
setState(() {
_selectedIndex = index;
});
}
}
2021-08-25 00:47:01 -04:00
@override
Widget build(BuildContext context) {
2021-12-28 03:14:08 -05:00
final authStore = context.read<AuthStore>();
return Scaffold(
appBar: AppBar(
2021-11-12 03:44:55 -05:00
centerTitle: false,
title: Observer(
builder: (_) {
final titles = [
2021-12-28 03:14:08 -05:00
if (authStore.isLoggedIn) 'Followed Streams',
'Top',
'Search',
];
return Text(
titles[_selectedIndex],
);
},
),
actions: [
IconButton(
icon: const Icon(Icons.settings),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Settings(settingsStore: context.read<SettingsStore>()),
),
),
)
],
),
body: SafeArea(
child: Observer(
builder: (_) {
return IndexedStack(
index: _selectedIndex,
children: [
if (authStore.isLoggedIn) FollowedStreams(store: widget.followedStreamsStore),
TopSection(topStreamsStore: widget.topStreamsStore, categoriesStore: widget.categoriesStore),
Search(searchStore: widget.searchStore),
],
);
},
),
),
bottomNavigationBar: Observer(
builder: (_) {
return BottomNavigationBar(
type: BottomNavigationBarType.fixed,
items: [
2021-12-28 03:14:08 -05:00
if (authStore.isLoggedIn)
const BottomNavigationBarItem(
icon: Icon(Icons.favorite),
label: 'Followed',
),
const BottomNavigationBarItem(
icon: Icon(Icons.arrow_upward),
label: 'Top',
),
const BottomNavigationBarItem(
icon: Icon(Icons.search),
label: 'Search',
),
],
currentIndex: _selectedIndex,
onTap: _handleTap,
);
},
),
2021-08-25 00:47:01 -04:00
);
}
}