Skip to content
This repository was archived by the owner on Apr 3, 2025. It is now read-only.

Commit 2f94c42

Browse files
committed
refactor: remove riverpod state management
1 parent b65af75 commit 2f94c42

29 files changed

+74
-186
lines changed

lib/core.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// This file is deprecated and should no longer be actively used.
22
/// All imports should happen directly and canonical export files will not be used anymore.
33
4-
export 'state/state.dart';
4+
export 'system/state.dart';
55
export 'types/loading_state.dart';
66
export 'database/box.dart';
77
export 'database/models/profile.dart';

lib/modules.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import 'package:lunasea/modules/sabnzbd.dart';
1717
import 'package:lunasea/modules/nzbget.dart';
1818
import 'package:lunasea/modules/tautulli.dart';
1919

20-
import 'package:lunasea/modules/dashboard/core/state.dart' as dashboard_state;
20+
import 'package:lunasea/modules/dashboard/core/state.dart';
2121
import 'package:lunasea/api/wake_on_lan/wake_on_lan.dart';
2222
import 'package:lunasea/system/flavor.dart';
2323

@@ -484,7 +484,7 @@ extension LunaModuleExtension on LunaModule {
484484
case LunaModule.WAKE_ON_LAN:
485485
return null;
486486
case LunaModule.DASHBOARD:
487-
return context.read<dashboard_state.ModuleState>();
487+
return context.read<DashboardState>();
488488
case LunaModule.SETTINGS:
489489
return context.read<SettingsState>();
490490
case LunaModule.SEARCH:

lib/modules/dashboard/core/state.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import 'package:lunasea/modules/dashboard/core/adapters/calendar_starting_size.d
44
import 'package:lunasea/modules/dashboard/core/adapters/calendar_starting_type.dart';
55
import 'package:lunasea/modules/dashboard/core/api/api.dart';
66
import 'package:lunasea/modules/dashboard/core/api/data/abstract.dart';
7-
import 'package:lunasea/state/state.dart';
7+
import 'package:lunasea/system/state.dart';
88
import 'package:lunasea/vendor.dart';
99

10-
class ModuleState extends LunaModuleState {
11-
ModuleState() {
10+
class DashboardState extends LunaModuleState {
11+
DashboardState() {
1212
reset();
1313
}
1414

lib/modules/dashboard/routes/dashboard/pages/calendar.dart

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:flutter/material.dart';
2-
import 'package:provider/provider.dart';
32

43
import 'package:lunasea/widgets/ui.dart';
54
import 'package:lunasea/system/logger.dart';
@@ -26,8 +25,8 @@ class _State extends State<CalendarPage>
2625

2726
@override
2827
Future<void> loadCallback() async {
29-
context.read<ModuleState>().resetToday();
30-
context.read<ModuleState>().resetUpcoming();
28+
context.read<DashboardState>().resetToday();
29+
context.read<DashboardState>().resetUpcoming();
3130
}
3231

3332
@override
@@ -38,7 +37,7 @@ class _State extends State<CalendarPage>
3837
key: _refreshKey,
3938
onRefresh: loadCallback,
4039
child: FutureBuilder(
41-
future: context.watch<ModuleState>().upcoming,
40+
future: context.watch<DashboardState>().upcoming,
4241
builder: (
4342
BuildContext context,
4443
AsyncSnapshot<Map<DateTime, List<CalendarData>>> snapshot,
@@ -55,7 +54,7 @@ class _State extends State<CalendarPage>
5554
if (snapshot.connectionState == ConnectionState.done &&
5655
snapshot.hasData) {
5756
final events = snapshot.data!;
58-
return Selector<ModuleState, CalendarStartingType>(
57+
return Selector<DashboardState, CalendarStartingType>(
5958
selector: (_, s) => s.calendarType,
6059
builder: (context, type, _) {
6160
if (type == CalendarStartingType.CALENDAR)

lib/modules/dashboard/routes/dashboard/widgets/calendar_view.dart

+9-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class _State extends State<CalendarView> {
4444

4545
void _onDaySelected(DateTime selected, DateTime focused) {
4646
HapticFeedback.selectionClick();
47-
context.read<ModuleState>().selected = selected.floor();
47+
context.read<DashboardState>().selected = selected.floor();
4848
}
4949

5050
@override
@@ -108,10 +108,10 @@ class _State extends State<CalendarView> {
108108
DashboardDatabase.CALENDAR_STARTING_SIZE,
109109
],
110110
builder: (context, _) {
111-
DateTime firstDay = context.watch<ModuleState>().today.subtract(
111+
DateTime firstDay = context.watch<DashboardState>().today.subtract(
112112
Duration(days: DashboardDatabase.CALENDAR_DAYS_PAST.read()),
113113
);
114-
DateTime lastDay = context.watch<ModuleState>().today.add(
114+
DateTime lastDay = context.watch<DashboardState>().today.add(
115115
Duration(days: DashboardDatabase.CALENDAR_DAYS_FUTURE.read()),
116116
);
117117
return SafeArea(
@@ -124,7 +124,7 @@ class _State extends State<CalendarView> {
124124
),
125125
rowHeight: 48.0,
126126
rangeSelectionMode: RangeSelectionMode.disabled,
127-
focusedDay: context.watch<ModuleState>().selected,
127+
focusedDay: context.watch<DashboardState>().selected,
128128
firstDay: firstDay,
129129
lastDay: lastDay,
130130
//events: widget.events,
@@ -142,7 +142,8 @@ class _State extends State<CalendarView> {
142142
startingDayOfWeek:
143143
DashboardDatabase.CALENDAR_STARTING_DAY.read().data,
144144
selectedDayPredicate: (date) {
145-
return date.floor() == context.read<ModuleState>().selected;
145+
return date.floor() ==
146+
context.read<DashboardState>().selected;
146147
},
147148
calendarStyle: CalendarStyle(
148149
markersMaxCount: 1,
@@ -170,7 +171,7 @@ class _State extends State<CalendarView> {
170171
todayTextStyle: dayStyle,
171172
),
172173
onFormatChanged: (format) {
173-
context.read<ModuleState>().calendarFormat = format;
174+
context.read<DashboardState>().calendarFormat = format;
174175
},
175176
daysOfWeekStyle: DaysOfWeekStyle(
176177
weekendStyle: weekdayStyle,
@@ -180,7 +181,7 @@ class _State extends State<CalendarView> {
180181
if (widget.events.isEmpty) return [];
181182
return widget.events[date.floor()] ?? [];
182183
},
183-
calendarFormat: context.watch<ModuleState>().calendarFormat,
184+
calendarFormat: context.watch<DashboardState>().calendarFormat,
184185
availableCalendarFormats: const {
185186
CalendarFormat.month: 'Month',
186187
CalendarFormat.twoWeeks: '2 Weeks',
@@ -228,7 +229,7 @@ class _State extends State<CalendarView> {
228229
}
229230

230231
Widget _calendarList() {
231-
final selected = context.read<ModuleState>().selected;
232+
final selected = context.read<DashboardState>().selected;
232233
final events = widget.events[selected.floor()] ?? [];
233234
if (events.isEmpty) {
234235
return Expanded(

lib/modules/dashboard/routes/dashboard/widgets/schedule_view.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class _State extends State<ScheduleView> {
6262
keys.sort();
6363

6464
for (final key in keys) {
65-
final selected = context.read<ModuleState>().selected;
65+
final selected = context.read<DashboardState>().selected;
6666
if (key.isBefore(selected) || key.isAtSameMomentAs(selected)) {
6767
offsetOfSelected = offset;
6868
}

lib/modules/dashboard/routes/dashboard/widgets/switch_view_action.dart

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:flutter/material.dart';
2-
import 'package:provider/provider.dart';
32

43
import 'package:lunasea/widgets/ui.dart';
54
import 'package:lunasea/vendor.dart';
@@ -44,14 +43,14 @@ class _State extends State<SwitchViewAction> with LunaLoadCallbackMixin {
4443

4544
@override
4645
Widget build(BuildContext context) {
47-
return Selector<ModuleState, CalendarStartingType>(
46+
return Selector<DashboardState, CalendarStartingType>(
4847
selector: (_, state) => state.calendarType,
4948
builder: (context, view, _) {
5049
if (_showButton) {
5150
return LunaIconButton.appBar(
5251
icon: view.icon,
5352
onPressed: () {
54-
final state = context.read<ModuleState>();
53+
final state = context.read<DashboardState>();
5554
if (view == CalendarStartingType.CALENDAR)
5655
state.calendarType = CalendarStartingType.SCHEDULE;
5756
else

lib/modules/settings/core/dialogs.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:lunasea/database/tables/lunasea.dart';
44
import 'package:lunasea/firebase/types.dart';
55
import 'package:lunasea/modules.dart';
66
import 'package:lunasea/modules/settings/core/types/header.dart';
7-
import 'package:lunasea/state/state.dart';
7+
import 'package:lunasea/system/state.dart';
88
import 'package:lunasea/system/localization.dart';
99
import 'package:lunasea/vendor.dart';
1010
import 'package:lunasea/widgets/ui.dart';

lib/modules/settings/routes/account/pages/password_reset.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:lunasea/core.dart';
33
import 'package:lunasea/firebase/auth.dart';
44
import 'package:lunasea/utils/validator.dart';
55

6-
class AccountPasswordResetRoute extends ConsumerStatefulWidget {
6+
class AccountPasswordResetRoute extends StatefulWidget {
77
const AccountPasswordResetRoute({
88
Key? key,
99
}) : super(key: key);
@@ -12,7 +12,7 @@ class AccountPasswordResetRoute extends ConsumerStatefulWidget {
1212
_State createState() => _State();
1313
}
1414

15-
class _State extends ConsumerState<AccountPasswordResetRoute>
15+
class _State extends State<AccountPasswordResetRoute>
1616
with LunaScrollControllerMixin {
1717
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
1818
final TextEditingController _emailController = TextEditingController();
@@ -99,7 +99,7 @@ class _State extends ConsumerState<AccountPasswordResetRoute>
9999
}
100100

101101
bool _validateEmailAddress({bool showSnackBarOnFailure = true}) {
102-
if (!ref.watch(validatorProvider).email(_emailController.text)) {
102+
if (!LunaValidator().email(_emailController.text)) {
103103
if (showSnackBarOnFailure) {
104104
showLunaErrorSnackBar(
105105
title: 'settings.InvalidEmail'.tr(),

lib/modules/settings/routes/account/pages/signed_out.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:lunasea/firebase/auth.dart';
44
import 'package:lunasea/router/routes/settings.dart';
55
import 'package:lunasea/utils/validator.dart';
66

7-
class SettingsAccountSignedOutPage extends ConsumerStatefulWidget {
7+
class SettingsAccountSignedOutPage extends StatefulWidget {
88
final ScrollController scrollController;
99

1010
const SettingsAccountSignedOutPage({
@@ -16,7 +16,7 @@ class SettingsAccountSignedOutPage extends ConsumerStatefulWidget {
1616
_State createState() => _State();
1717
}
1818

19-
class _State extends ConsumerState<SettingsAccountSignedOutPage> {
19+
class _State extends State<SettingsAccountSignedOutPage> {
2020
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
2121
final TextEditingController _emailController = TextEditingController();
2222
final TextEditingController _passwordController = TextEditingController();
@@ -124,7 +124,7 @@ class _State extends ConsumerState<SettingsAccountSignedOutPage> {
124124
}
125125

126126
bool _validateEmailAddress({bool showSnackBarOnFailure = true}) {
127-
if (!ref.watch(validatorProvider).email(_emailController.text)) {
127+
if (!LunaValidator().email(_emailController.text)) {
128128
if (showSnackBarOnFailure)
129129
showLunaErrorSnackBar(
130130
title: 'settings.InvalidEmail'.tr(),

lib/modules/settings/routes/account/widgets/config_backup_tile.dart

+4-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:lunasea/modules/settings.dart';
77
import 'package:lunasea/utils/encryption.dart';
88
import 'package:lunasea/utils/uuid.dart';
99

10-
class SettingsAccountBackupConfigurationTile extends ConsumerStatefulWidget {
10+
class SettingsAccountBackupConfigurationTile extends StatefulWidget {
1111
const SettingsAccountBackupConfigurationTile({
1212
Key? key,
1313
}) : super(key: key);
@@ -16,7 +16,7 @@ class SettingsAccountBackupConfigurationTile extends ConsumerStatefulWidget {
1616
_State createState() => _State();
1717
}
1818

19-
class _State extends ConsumerState<SettingsAccountBackupConfigurationTile> {
19+
class _State extends State<SettingsAccountBackupConfigurationTile> {
2020
LunaLoadingState _loadingState = LunaLoadingState.INACTIVE;
2121

2222
void updateState(LunaLoadingState state) {
@@ -44,12 +44,10 @@ class _State extends ConsumerState<SettingsAccountBackupConfigurationTile> {
4444
Tuple2<bool, String> _values =
4545
await SettingsDialogs().backupConfiguration(context);
4646
if (_values.item1) {
47-
final encryption = ref.watch(encryptionProvider);
48-
4947
String decrypted = LunaConfig().export();
50-
String encrypted = encryption.encrypt(_values.item2, decrypted);
48+
String encrypted = LunaEncryption().encrypt(_values.item2, decrypted);
5149
int timestamp = DateTime.now().millisecondsSinceEpoch;
52-
String id = ref.watch(uuidProvider).generate();
50+
String id = LunaUUID().generate();
5351
String format = 'MMMM dd, yyyy\nhh:mm:ss a';
5452
String title = DateFormat(format).format(DateTime.now());
5553

lib/modules/settings/routes/account/widgets/config_restore_tile.dart

+3-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'package:lunasea/firebase/storage.dart';
66
import 'package:lunasea/modules/settings.dart';
77
import 'package:lunasea/utils/encryption.dart';
88

9-
class SettingsAccountRestoreConfigurationTile extends ConsumerStatefulWidget {
9+
class SettingsAccountRestoreConfigurationTile extends StatefulWidget {
1010
const SettingsAccountRestoreConfigurationTile({
1111
Key? key,
1212
}) : super(key: key);
@@ -15,7 +15,7 @@ class SettingsAccountRestoreConfigurationTile extends ConsumerStatefulWidget {
1515
_State createState() => _State();
1616
}
1717

18-
class _State extends ConsumerState<SettingsAccountRestoreConfigurationTile> {
18+
class _State extends State<SettingsAccountRestoreConfigurationTile> {
1919
LunaLoadingState _loadingState = LunaLoadingState.INACTIVE;
2020

2121
void updateState(LunaLoadingState state) {
@@ -61,8 +61,7 @@ class _State extends ConsumerState<SettingsAccountRestoreConfigurationTile> {
6161
Tuple2<bool, String> _key = await SettingsDialogs().decryptBackup(context);
6262
if (_key.item1) {
6363
try {
64-
final encryption = ref.watch(encryptionProvider);
65-
String decrypted = encryption.decrypt(_key.item2, encrypted);
64+
String decrypted = LunaEncryption().decrypt(_key.item2, encrypted);
6665
await LunaConfig().import(context, decrypted);
6766
showLunaSuccessSnackBar(
6867
title: 'settings.RestoreFromCloudSuccess'.tr(),

lib/modules/settings/routes/system/widgets/backup_tile.dart

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,27 @@ import 'package:lunasea/modules/settings.dart';
55
import 'package:lunasea/system/filesystem/filesystem.dart';
66
import 'package:lunasea/utils/encryption.dart';
77

8-
class SettingsSystemBackupRestoreBackupTile extends ConsumerWidget {
8+
class SettingsSystemBackupRestoreBackupTile extends StatelessWidget {
99
const SettingsSystemBackupRestoreBackupTile({
1010
Key? key,
1111
}) : super(key: key);
1212

1313
@override
14-
Widget build(BuildContext context, WidgetRef ref) {
14+
Widget build(BuildContext context) {
1515
return LunaBlock(
1616
title: 'settings.BackupToDevice'.tr(),
1717
body: [TextSpan(text: 'settings.BackupToDeviceDescription'.tr())],
1818
trailing: const LunaIconButton(icon: Icons.upload_rounded),
19-
onTap: () async => _backup(context, ref),
19+
onTap: () async => _backup(context),
2020
);
2121
}
2222

23-
Future<void> _backup(BuildContext context, WidgetRef ref) async {
23+
Future<void> _backup(BuildContext context) async {
2424
try {
2525
final _values = await SettingsDialogs().backupConfiguration(context);
2626
if (_values.item1) {
27-
final encryption = ref.watch(encryptionProvider);
2827
String data = LunaConfig().export();
29-
String encrypted = encryption.encrypt(_values.item2, data);
28+
String encrypted = LunaEncryption().encrypt(_values.item2, data);
3029
String name = DateFormat('y-MM-dd kk-mm-ss').format(DateTime.now());
3130
bool result = await LunaFileSystem().save(
3231
context,

lib/modules/settings/routes/system/widgets/build_details.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import 'package:lunasea/vendor.dart';
88
import 'package:lunasea/widgets/sheets/changelog/sheet.dart';
99
import 'package:lunasea/widgets/ui.dart';
1010

11-
class BuildDetails extends ConsumerStatefulWidget {
11+
class BuildDetails extends StatefulWidget {
1212
const BuildDetails({Key? key}) : super(key: key);
1313

1414
@override
15-
ConsumerState<BuildDetails> createState() => _State();
15+
State<BuildDetails> createState() => _State();
1616
}
1717

18-
class _State extends ConsumerState<BuildDetails> {
18+
class _State extends State<BuildDetails> {
1919
Future<PackageInfo> packageInfo = PackageInfo.fromPlatform();
2020
Future<Tuple2<bool, int?>> checkUpdates = LunaBuild().isLatestBuildNumber();
2121

0 commit comments

Comments
 (0)