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';
|
2022-01-02 22:52:57 -05:00
|
|
|
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';
|
2022-01-02 22:52:57 -05:00
|
|
|
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';
|
2021-10-05 03:17:38 -04:00
|
|
|
import 'package:provider/provider.dart';
|
2021-11-14 23:18:43 -05:00
|
|
|
|
2022-01-02 22:52:57 -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;
|
2021-10-09 04:02:55 -04:00
|
|
|
|
|
|
|
|
const Home({
|
|
|
|
|
Key? key,
|
2021-11-22 01:26:17 -05:00
|
|
|
required this.topStreamsStore,
|
|
|
|
|
required this.followedStreamsStore,
|
|
|
|
|
required this.categoriesStore,
|
|
|
|
|
required this.searchStore,
|
2021-10-09 04:02:55 -04:00
|
|
|
}) : super(key: key);
|
2021-08-25 00:47:01 -04:00
|
|
|
|
2022-01-02 22:52:57 -05: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>();
|
|
|
|
|
|
2021-10-12 02:34:30 -04:00
|
|
|
return Scaffold(
|
|
|
|
|
appBar: AppBar(
|
2021-11-12 03:44:55 -05:00
|
|
|
centerTitle: false,
|
2021-10-12 02:34:30 -04:00
|
|
|
title: Observer(
|
|
|
|
|
builder: (_) {
|
2021-11-12 16:50:02 -05:00
|
|
|
final titles = [
|
2021-12-28 03:14:08 -05:00
|
|
|
if (authStore.isLoggedIn) 'Followed Streams',
|
2022-01-02 22:52:57 -05:00
|
|
|
'Top',
|
2021-11-12 16:50:02 -05:00
|
|
|
'Search',
|
|
|
|
|
];
|
2021-11-10 21:29:15 -05:00
|
|
|
return Text(
|
2022-01-02 22:52:57 -05:00
|
|
|
titles[_selectedIndex],
|
2021-11-10 21:29:15 -05:00
|
|
|
);
|
2021-10-12 02:34:30 -04:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
2021-11-10 21:29:15 -05:00
|
|
|
icon: const Icon(Icons.settings),
|
2022-01-03 05:51:43 -05:00
|
|
|
onPressed: () => Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) => Settings(settingsStore: context.read<SettingsStore>()),
|
|
|
|
|
),
|
|
|
|
|
),
|
2021-10-12 02:34:30 -04:00
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
2021-12-30 04:12:49 -05:00
|
|
|
body: SafeArea(
|
|
|
|
|
child: Observer(
|
|
|
|
|
builder: (_) {
|
|
|
|
|
return IndexedStack(
|
2022-01-02 22:52:57 -05:00
|
|
|
index: _selectedIndex,
|
2021-12-30 04:12:49 -05:00
|
|
|
children: [
|
2022-01-02 22:52:57 -05:00
|
|
|
if (authStore.isLoggedIn) FollowedStreams(store: widget.followedStreamsStore),
|
|
|
|
|
TopSection(topStreamsStore: widget.topStreamsStore, categoriesStore: widget.categoriesStore),
|
|
|
|
|
Search(searchStore: widget.searchStore),
|
2021-12-30 04:12:49 -05:00
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
2021-10-12 02:34:30 -04:00
|
|
|
),
|
2021-11-14 21:12:57 -05:00
|
|
|
bottomNavigationBar: Observer(
|
|
|
|
|
builder: (_) {
|
|
|
|
|
return BottomNavigationBar(
|
|
|
|
|
type: BottomNavigationBarType.fixed,
|
|
|
|
|
items: [
|
2021-12-28 03:14:08 -05:00
|
|
|
if (authStore.isLoggedIn)
|
2021-11-10 21:29:15 -05:00
|
|
|
const BottomNavigationBarItem(
|
2021-11-14 21:12:57 -05:00
|
|
|
icon: Icon(Icons.favorite),
|
|
|
|
|
label: 'Followed',
|
2021-11-10 21:29:15 -05:00
|
|
|
),
|
2021-11-14 21:12:57 -05:00
|
|
|
const BottomNavigationBarItem(
|
|
|
|
|
icon: Icon(Icons.arrow_upward),
|
|
|
|
|
label: 'Top',
|
|
|
|
|
),
|
|
|
|
|
const BottomNavigationBarItem(
|
|
|
|
|
icon: Icon(Icons.search),
|
|
|
|
|
label: 'Search',
|
|
|
|
|
),
|
|
|
|
|
],
|
2022-01-02 22:52:57 -05:00
|
|
|
currentIndex: _selectedIndex,
|
|
|
|
|
onTap: _handleTap,
|
2021-11-14 21:12:57 -05:00
|
|
|
);
|
|
|
|
|
},
|
2021-10-12 02:34:30 -04:00
|
|
|
),
|
2021-08-25 00:47:01 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|