2021-08-25 00:47:01 -04:00
|
|
|
import 'package:flutter/material.dart';
|
2023-01-19 02:27:51 -05:00
|
|
|
import 'package:flutter/services.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';
|
2024-08-13 00:41:06 -07:00
|
|
|
import 'package:frosty/screens/settings/widgets/release_notes.dart';
|
2023-10-22 18:38:32 -04:00
|
|
|
import 'package:frosty/widgets/profile_picture.dart';
|
2024-08-13 00:41:06 -07:00
|
|
|
import 'package:package_info_plus/package_info_plus.dart';
|
2021-10-05 03:17:38 -04:00
|
|
|
import 'package:provider/provider.dart';
|
2024-08-13 00:41:06 -07: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 {
|
2023-10-28 18:13:23 -04:00
|
|
|
const Home({super.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);
|
|
|
|
|
|
2024-08-13 00:41:06 -07:00
|
|
|
Future<void> checkAndShowReleaseNotes() async {
|
|
|
|
|
final packageInfo = await PackageInfo.fromPlatform();
|
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
|
|
|
|
|
|
final currentVersion = packageInfo.version;
|
|
|
|
|
final storedVersion = prefs.getString('last_shown_version');
|
|
|
|
|
|
2025-06-13 01:01:48 -04:00
|
|
|
// Extract major.minor version (ignore patch)
|
|
|
|
|
final currentMajorMinor = currentVersion.split('.').take(2).join('.');
|
|
|
|
|
final storedMajorMinor = storedVersion?.split('.').take(2).join('.');
|
|
|
|
|
|
|
|
|
|
if (storedMajorMinor == null || storedMajorMinor != currentMajorMinor) {
|
2024-08-13 00:41:06 -07:00
|
|
|
if (!mounted) return;
|
|
|
|
|
|
|
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(builder: (context) => const ReleaseNotes()),
|
2024-08-13 18:36:03 -07:00
|
|
|
).then((_) => prefs.setString('last_shown_version', currentVersion));
|
2024-08-13 00:41:06 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
checkAndShowReleaseNotes();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-25 22:06:01 -05:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2023-01-19 02:27:51 -05:00
|
|
|
SystemChrome.setPreferredOrientations([]);
|
|
|
|
|
|
2023-10-22 18:38:32 -04:00
|
|
|
final isLoggedIn = _authStore.isLoggedIn && _authStore.user.details != null;
|
|
|
|
|
|
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,
|
2024-09-06 21:43:27 -07:00
|
|
|
shape: const Border(),
|
2022-01-19 15:37:20 -05:00
|
|
|
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: [
|
2024-09-06 21:43:27 -07:00
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(right: 8),
|
|
|
|
|
child: IconButton(
|
|
|
|
|
tooltip: 'Settings',
|
|
|
|
|
icon: isLoggedIn
|
|
|
|
|
? ProfilePicture(
|
|
|
|
|
userLogin: _authStore.user.details!.login,
|
|
|
|
|
radius: 16,
|
|
|
|
|
)
|
|
|
|
|
: const Icon(Icons.settings_rounded),
|
|
|
|
|
onPressed: () => Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(
|
|
|
|
|
builder: (context) =>
|
|
|
|
|
Settings(settingsStore: context.read<SettingsStore>()),
|
|
|
|
|
),
|
2022-01-19 15:37:20 -05:00
|
|
|
),
|
2022-01-03 05:51:43 -05:00
|
|
|
),
|
2023-10-22 18:38:32 -04:00
|
|
|
),
|
2022-01-19 15:37:20 -05:00
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
body: SafeArea(
|
2023-01-18 05:34:54 -05:00
|
|
|
child: Observer(
|
|
|
|
|
builder: (_) => IndexedStack(
|
|
|
|
|
index: _homeStore.selectedIndex,
|
|
|
|
|
children: [
|
|
|
|
|
if (_authStore.isLoggedIn)
|
|
|
|
|
StreamsList(
|
|
|
|
|
listType: ListType.followed,
|
|
|
|
|
scrollController: _homeStore.followedScrollController,
|
2022-06-29 01:06:33 -04:00
|
|
|
),
|
2023-01-18 05:34:54 -05:00
|
|
|
TopSection(
|
|
|
|
|
homeStore: _homeStore,
|
2022-06-29 01:06:33 -04:00
|
|
|
),
|
2023-01-18 05:34:54 -05:00
|
|
|
Search(
|
|
|
|
|
scrollController: _homeStore.searchScrollController,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2022-01-16 18:21:36 -05:00
|
|
|
),
|
2021-12-30 04:12:49 -05:00
|
|
|
),
|
2024-09-06 21:43:27 -07:00
|
|
|
bottomNavigationBar: Column(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
const Divider(),
|
|
|
|
|
Observer(
|
|
|
|
|
builder: (_) => NavigationBar(
|
|
|
|
|
destinations: [
|
|
|
|
|
if (_authStore.isLoggedIn)
|
|
|
|
|
const NavigationDestination(
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.favorite_border_rounded,
|
|
|
|
|
),
|
|
|
|
|
selectedIcon: Icon(Icons.favorite_rounded),
|
|
|
|
|
label: 'Following',
|
|
|
|
|
tooltip: 'Following',
|
|
|
|
|
),
|
|
|
|
|
const NavigationDestination(
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.arrow_upward_rounded,
|
|
|
|
|
),
|
|
|
|
|
selectedIcon: Icon(Icons.arrow_upward_rounded),
|
|
|
|
|
label: 'Top',
|
|
|
|
|
tooltip: 'Top',
|
|
|
|
|
),
|
|
|
|
|
const NavigationDestination(
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.search_rounded,
|
|
|
|
|
),
|
|
|
|
|
selectedIcon: Icon(Icons.search_rounded),
|
|
|
|
|
label: 'Search',
|
|
|
|
|
tooltip: 'Search',
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
selectedIndex: _homeStore.selectedIndex,
|
|
|
|
|
onDestinationSelected: _homeStore.handleTap,
|
2022-01-19 15:37:20 -05:00
|
|
|
),
|
2024-09-06 21:43:27 -07: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
|
|
|
}
|