Fix log out not triggering refresh, home clean up

This commit is contained in:
tommyxchow 2022-01-16 18:21:36 -05:00
parent e62a0fc373
commit 262f151b07
3 changed files with 41 additions and 47 deletions

View file

@ -139,9 +139,6 @@ abstract class _AuthBase with Store {
// Clear the user info.
user.dispose();
// Set the login status to logged out.
_isLoggedIn = false;
// If the default token already exists, set it.
_token = await _storage.read(key: 'DEFAULT_TOKEN');
@ -165,6 +162,8 @@ abstract class _AuthBase with Store {
} catch (e) {
debugPrint(e.toString());
}
// Set the login status to logged out.
_isLoggedIn = false;
debugPrint('Successfully logged out');
}

View file

@ -159,6 +159,13 @@ class MyApp extends StatelessWidget {
: ThemeMode.dark,
home: Home(
homeStore: HomeStore(),
followedStreamsStore: authStore.isLoggedIn
? ListStore(
authStore: authStore,
twitchApi: twitchApi,
listType: ListType.followed,
)
: null,
topSectionStore: ListStore(
authStore: authStore,
twitchApi: twitchApi,
@ -168,13 +175,6 @@ class MyApp extends StatelessWidget {
authStore: authStore,
twitchApi: twitchApi,
),
followedStreamsStore: authStore.isLoggedIn
? ListStore(
authStore: authStore,
twitchApi: twitchApi,
listType: ListType.followed,
)
: null,
searchStore: SearchStore(
authStore: authStore,
twitchApi: twitchApi,

View file

@ -14,18 +14,18 @@ import 'package:provider/provider.dart';
class Home extends StatelessWidget {
final HomeStore homeStore;
final ListStore? followedStreamsStore;
final ListStore topSectionStore;
final CategoriesStore categoriesSectionStore;
final SearchStore searchStore;
final ListStore? followedStreamsStore;
const Home({
Key? key,
required this.homeStore,
required this.followedStreamsStore,
required this.topSectionStore,
required this.categoriesSectionStore,
required this.searchStore,
required this.followedStreamsStore,
}) : super(key: key);
@override
@ -42,9 +42,8 @@ class Home extends StatelessWidget {
'Top',
'Search',
];
return Text(
titles[homeStore.selectedIndex],
);
return Text(titles[homeStore.selectedIndex]);
},
),
actions: [
@ -62,43 +61,39 @@ class Home extends StatelessWidget {
),
body: SafeArea(
child: Observer(
builder: (_) {
return IndexedStack(
index: homeStore.selectedIndex,
children: [
if (authStore.isLoggedIn) StreamsList(store: followedStreamsStore!),
TopSection(
topSectionStore: topSectionStore,
categoriesSectionStore: categoriesSectionStore,
),
Search(searchStore: searchStore),
],
);
},
builder: (_) => IndexedStack(
index: homeStore.selectedIndex,
children: [
if (authStore.isLoggedIn) StreamsList(store: followedStreamsStore!),
TopSection(
topSectionStore: topSectionStore,
categoriesSectionStore: categoriesSectionStore,
),
Search(searchStore: searchStore),
],
),
),
),
bottomNavigationBar: Observer(
builder: (_) {
return BottomNavigationBar(
items: [
if (authStore.isLoggedIn)
const BottomNavigationBarItem(
icon: Icon(Icons.favorite),
label: 'Followed',
),
builder: (_) => BottomNavigationBar(
items: [
if (authStore.isLoggedIn)
const BottomNavigationBarItem(
icon: Icon(Icons.arrow_upward),
label: 'Top',
icon: Icon(Icons.favorite),
label: 'Followed',
),
const BottomNavigationBarItem(
icon: Icon(Icons.search),
label: 'Search',
),
],
currentIndex: homeStore.selectedIndex,
onTap: homeStore.handleTap,
);
},
const BottomNavigationBarItem(
icon: Icon(Icons.arrow_upward),
label: 'Top',
),
const BottomNavigationBarItem(
icon: Icon(Icons.search),
label: 'Search',
),
],
currentIndex: homeStore.selectedIndex,
onTap: homeStore.handleTap,
),
),
);
}