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-10 21:29:15 -05:00
|
|
|
import 'package:frosty/screens/search.dart';
|
|
|
|
|
import 'package:frosty/screens/settings.dart';
|
2021-10-01 00:10:50 -04:00
|
|
|
import 'package:frosty/stores/auth_store.dart';
|
2021-11-12 00:04:39 -05:00
|
|
|
import 'package:frosty/stores/stream_list_store.dart';
|
2021-10-08 02:14:05 -04:00
|
|
|
import 'package:frosty/stores/home_store.dart';
|
2021-11-10 21:29:15 -05:00
|
|
|
import 'package:frosty/stores/settings_store.dart';
|
2021-10-05 03:17:38 -04:00
|
|
|
import 'package:provider/provider.dart';
|
2021-11-12 00:04:39 -05:00
|
|
|
import '../widgets/stream_list.dart';
|
2021-08-25 00:47:01 -04:00
|
|
|
|
2021-10-09 04:02:55 -04:00
|
|
|
class Home extends StatefulWidget {
|
|
|
|
|
final HomeStore homeStore;
|
2021-11-12 00:04:39 -05:00
|
|
|
final StreamListStore streamListStore;
|
2021-10-09 04:02:55 -04:00
|
|
|
|
|
|
|
|
const Home({
|
|
|
|
|
Key? key,
|
|
|
|
|
required this.homeStore,
|
2021-11-12 00:04:39 -05:00
|
|
|
required this.streamListStore,
|
2021-10-09 04:02:55 -04:00
|
|
|
}) : super(key: key);
|
2021-08-25 00:47:01 -04:00
|
|
|
|
2021-10-09 04:02:55 -04:00
|
|
|
@override
|
|
|
|
|
_HomeState createState() => _HomeState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _HomeState extends State<Home> {
|
2021-10-10 00:10:58 -04:00
|
|
|
final _textController = TextEditingController();
|
|
|
|
|
|
2021-08-25 00:47:01 -04:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2021-10-08 02:14:05 -04:00
|
|
|
debugPrint('build home');
|
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 = [
|
|
|
|
|
if (context.read<AuthStore>().isLoggedIn) 'Followed Streams',
|
|
|
|
|
'Top Streams',
|
|
|
|
|
'Search',
|
|
|
|
|
];
|
2021-11-10 21:29:15 -05:00
|
|
|
return Text(
|
|
|
|
|
titles[widget.homeStore.selectedIndex],
|
|
|
|
|
);
|
2021-10-12 02:34:30 -04:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
actions: [
|
|
|
|
|
IconButton(
|
2021-11-10 21:29:15 -05:00
|
|
|
icon: const Icon(Icons.settings),
|
2021-10-12 02:34:30 -04:00
|
|
|
onPressed: () {
|
2021-11-10 21:29:15 -05:00
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) {
|
2021-11-12 03:44:55 -05:00
|
|
|
return Settings(settingsStore: context.read<SettingsStore>());
|
2021-11-10 21:29:15 -05:00
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
2021-10-12 02:34:30 -04:00
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
body: Observer(
|
|
|
|
|
builder: (_) {
|
|
|
|
|
return IndexedStack(
|
2021-10-09 04:02:55 -04:00
|
|
|
index: widget.homeStore.selectedIndex,
|
2021-10-08 02:14:05 -04:00
|
|
|
children: [
|
2021-10-09 04:02:55 -04:00
|
|
|
if (context.read<AuthStore>().isLoggedIn)
|
2021-11-12 00:04:39 -05:00
|
|
|
StreamList(
|
|
|
|
|
category: StreamCategory.followed,
|
|
|
|
|
streamListStore: widget.streamListStore,
|
2021-10-05 03:17:38 -04:00
|
|
|
),
|
2021-11-12 00:04:39 -05:00
|
|
|
StreamList(
|
|
|
|
|
category: StreamCategory.top,
|
|
|
|
|
streamListStore: widget.streamListStore,
|
2021-10-08 02:14:05 -04:00
|
|
|
),
|
2021-11-10 21:29:15 -05:00
|
|
|
const Search(),
|
2021-10-08 02:14:05 -04: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: [
|
|
|
|
|
if (context.read<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',
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
currentIndex: widget.homeStore.selectedIndex,
|
|
|
|
|
onTap: widget.homeStore.handleTap,
|
|
|
|
|
);
|
|
|
|
|
},
|
2021-10-12 02:34:30 -04:00
|
|
|
),
|
2021-08-25 00:47:01 -04:00
|
|
|
);
|
|
|
|
|
}
|
2021-10-10 00:10:58 -04:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
_textController.dispose();
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
2021-08-25 00:47:01 -04:00
|
|
|
}
|