Skip to content

Commit

Permalink
Fix wrong usage of ref.read
Browse files Browse the repository at this point in the history
  • Loading branch information
dhzdhd committed Jun 17, 2024
1 parent 16d5a36 commit d421b66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion lib/src/accounts/controllers/folder_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class Folder extends _$Folder {
) async {
// Improvise
final oldAuthModel = ref
.read(authProvider)
.watch(authProvider)
.where(
(element) =>
element.email == folderModel.email &&
Expand Down
20 changes: 6 additions & 14 deletions lib/src/home/views/home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class _HomeViewState extends ConsumerState<HomeView> {

@override
void initState() {
final folders = ref.read(folderProvider).toList();
final folders = ref.watch(folderProvider).toList();
_watchers = folders.map((e) => DirectoryWatcher(e.folderPath)).toList();
super.initState();
}
Expand Down Expand Up @@ -139,7 +139,7 @@ class _HomeViewState extends ConsumerState<HomeView> {
floatingActionButton: FloatingActionButton(
tooltip: 'Sync new folder',
onPressed: () async {
if (ref.read(authProvider).isEmpty) {
if (ref.watch(authProvider).isEmpty) {
context.showErrorSnackBar('No accounts registered yet');
return;
}
Expand Down Expand Up @@ -358,19 +358,14 @@ class _HomeViewState extends ConsumerState<HomeView> {
'Auto sync',
style: Theme.of(context).textTheme.bodyLarge,
),
// Spacer(),
SizedBox(
// width: 10,
height: 30,
child: FittedBox(
fit: BoxFit.fill,
child: Switch(
value: e.isAutoSync,
onChanged: (val) {
ref
.watch(folderProvider.notifier)
.toggleAutoSync(e);
},
onChanged: (val) =>
folderNotifier.toggleAutoSync(e),
),
),
)
Expand All @@ -394,11 +389,8 @@ class _HomeViewState extends ConsumerState<HomeView> {
fit: BoxFit.fill,
child: Switch(
value: e.isDeletionEnabled,
onChanged: (val) => {
ref
.watch(folderProvider.notifier)
.toggleDeletionOnSync(e)
},
onChanged: (val) =>
folderNotifier.toggleDeletionOnSync(e),
),
),
)
Expand Down

0 comments on commit d421b66

Please sign in to comment.