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 ' ;
2022-08-31 14:11:45 -04:00
import ' package:frosty/screens/home/home_store.dart ' ;
2022-01-04 02:58:02 -05:00
import ' package:frosty/screens/home/search/search.dart ' ;
2022-08-31 14:11:45 -04:00
import ' package:frosty/screens/home/stream_list/stream_list_store.dart ' ;
import ' package:frosty/screens/home/stream_list/streams_list.dart ' ;
import ' package:frosty/screens/home/top/top.dart ' ;
2022-01-04 02:58:02 -05:00
import ' package:frosty/screens/settings/settings.dart ' ;
2022-08-31 14:11:45 -04:00
import ' package:frosty/screens/settings/stores/auth_store.dart ' ;
2022-01-04 02:58:02 -05:00
import ' package:frosty/screens/settings/stores/settings_store.dart ' ;
2022-06-25 22:50:16 -04:00
import ' package:frosty/widgets/button.dart ' ;
2022-06-27 00:51:13 -04:00
import ' package:frosty/widgets/dialog.dart ' ;
2022-05-30 20:32:10 -04:00
import ' package:package_info_plus/package_info_plus.dart ' ;
2021-10-05 03:17:38 -04:00
import ' package:provider/provider.dart ' ;
2022-05-30 20:32:10 -04:00
import ' package:shared_preferences/shared_preferences.dart ' ;
2021-11-14 23:18:43 -05:00
2022-01-25 22:06:01 -05:00
class Home extends StatefulWidget {
2022-01-25 16:38:43 -05:00
const Home ( { Key ? key } ) : super ( key: key ) ;
2021-08-25 00:47:01 -04:00
@ override
2022-01-25 22:06:01 -05:00
State < Home > createState ( ) = > _HomeState ( ) ;
}
class _HomeState extends State < Home > {
late final _authStore = context . read < AuthStore > ( ) ;
2021-12-28 03:14:08 -05:00
2022-01-25 22:06:01 -05:00
late final _homeStore = HomeStore ( authStore: _authStore ) ;
2022-05-30 20:32:10 -04:00
Future < void > _showStartDialog ( ) async {
final packageInfo = await PackageInfo . fromPlatform ( ) ;
final prefs = await SharedPreferences . getInstance ( ) ;
if ( prefs . getBool ( ' first_run ' ) = = false ) return ;
return showDialog (
barrierDismissible: false ,
context: context ,
2022-06-27 00:51:13 -04:00
builder: ( context ) = > FrostyDialog (
title: ' Frosty v ${ packageInfo . version } ( ${ packageInfo . buildNumber } ) ' ,
2022-05-30 20:32:10 -04:00
content: Column (
mainAxisSize: MainAxisSize . min ,
crossAxisAlignment: CrossAxisAlignment . start ,
2022-06-30 06:03:04 -04:00
children: const [
Text (
2022-07-06 00:51:58 -04:00
' Thank you so much for downloading and trying out Frosty! Hopefully it \' ll make your mobile Twitch viewing experience a little more enjoyable. ' ) ,
2022-06-30 06:03:04 -04:00
SizedBox ( height: 20.0 ) ,
2022-07-06 00:51:58 -04:00
Text (
' Frosty is completely free and open-source. If you \' d like to explore the source code, report an issue, or make a feature request, check out the GitHub repo (link at the top-right of settings). ' ) ,
2022-06-30 06:03:04 -04:00
SizedBox ( height: 20.0 ) ,
2022-07-06 00:51:58 -04:00
Text ( ' You can also find links to the full changelog and FAQ in Settings -> Other. ' ) ,
2022-06-30 06:03:04 -04:00
SizedBox ( height: 20.0 ) ,
2022-07-06 00:51:58 -04:00
Text ( ' Don \' t forget to leave a rating and/or review on the app store! ' ) ,
2022-05-30 20:32:10 -04:00
] ,
) ,
actions: [
2022-06-25 22:50:16 -04:00
Button (
2022-05-30 20:32:10 -04:00
onPressed: ( ) {
prefs . setBool ( ' first_run ' , false ) ;
Navigator . of ( context ) . pop ( ) ;
} ,
child: const Text ( ' Close ' ) ,
) ,
] ,
) ,
) ;
}
@ override
void initState ( ) {
super . initState ( ) ;
_showStartDialog ( ) ;
}
2022-01-25 22:06:01 -05:00
@ override
Widget build ( BuildContext context ) {
2022-01-19 15:37:20 -05:00
return GestureDetector (
2022-01-19 17:36:31 -05:00
onTap: FocusScope . of ( context ) . unfocus ,
2022-01-19 15:37:20 -05:00
child: Scaffold (
appBar: AppBar (
centerTitle: false ,
title: Observer (
builder: ( _ ) {
final titles = [
2022-09-06 12:04:31 -04:00
if ( _authStore . isLoggedIn ) ' Following ' ,
2022-01-19 15:37:20 -05:00
' Top ' ,
' Search ' ,
] ;
2022-01-16 18:21:36 -05:00
2022-03-30 19:29:51 -04:00
return Text ( titles [ _homeStore . selectedIndex ] ) ;
2022-01-19 15:37:20 -05:00
} ,
) ,
actions: [
IconButton (
tooltip: ' Settings ' ,
icon: const Icon ( Icons . settings ) ,
onPressed: ( ) = > Navigator . push (
context ,
MaterialPageRoute (
builder: ( context ) = > Settings ( settingsStore: context . read < SettingsStore > ( ) ) ,
) ,
2022-01-03 05:51:43 -05:00
) ,
2022-01-19 15:37:20 -05:00
)
] ,
) ,
body: SafeArea (
2022-07-02 00:50:58 -04:00
child: Column (
children: [
Expanded (
child: Observer (
builder: ( _ ) = > IndexedStack (
index: _homeStore . selectedIndex ,
children: [
if ( _authStore . isLoggedIn )
StreamsList (
listType: ListType . followed ,
scrollController: _homeStore . followedScrollController ,
) ,
TopSection (
homeStore: _homeStore ,
) ,
Search (
scrollController: _homeStore . searchScrollController ,
) ,
] ,
2022-06-29 01:06:33 -04:00
) ,
) ,
2022-07-02 00:50:58 -04:00
) ,
const Divider ( height: 1.0 , thickness: 1.0 ) ,
] ,
2022-01-16 18:21:36 -05:00
) ,
2021-12-30 04:12:49 -05:00
) ,
2022-01-19 15:37:20 -05:00
bottomNavigationBar: Observer (
builder: ( _ ) = > BottomNavigationBar (
2022-07-02 00:50:58 -04:00
unselectedFontSize: 12.0 ,
selectedFontSize: 12.0 ,
type: BottomNavigationBarType . fixed ,
2022-01-19 15:37:20 -05:00
items: [
2022-01-25 22:06:01 -05:00
if ( _authStore . isLoggedIn )
2022-01-19 15:37:20 -05:00
const BottomNavigationBarItem (
icon: Icon ( Icons . favorite ) ,
2022-09-06 12:04:31 -04:00
label: ' Following ' ,
2022-07-02 00:50:58 -04:00
tooltip: ' Followed streams ' ,
2022-01-19 15:37:20 -05:00
) ,
2021-11-14 21:12:57 -05:00
const BottomNavigationBarItem (
2022-01-19 15:37:20 -05:00
icon: Icon ( Icons . arrow_upward ) ,
label: ' Top ' ,
2022-07-02 00:50:58 -04:00
tooltip: ' Top streams and categories ' ,
2021-11-14 21:12:57 -05:00
) ,
2022-01-19 15:37:20 -05:00
const BottomNavigationBarItem (
icon: Icon ( Icons . search ) ,
label: ' Search ' ,
2022-07-02 00:50:58 -04:00
tooltip: ' Search for channels and categories ' ,
2022-01-19 15:37:20 -05:00
) ,
] ,
2022-01-25 22:06:01 -05:00
currentIndex: _homeStore . selectedIndex ,
onTap: _homeStore . handleTap ,
2022-01-19 15:37:20 -05:00
) ,
2022-01-16 18:21:36 -05:00
) ,
2021-10-12 02:34:30 -04:00
) ,
2021-08-25 00:47:01 -04:00
) ;
}
2022-01-25 22:06:01 -05:00
@ override
void dispose ( ) {
_homeStore . dispose ( ) ;
super . dispose ( ) ;
}
2021-08-25 00:47:01 -04:00
}