-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove app bloc and replace it with app providers
- Loading branch information
1 parent
0853f64
commit dd6d5a8
Showing
13 changed files
with
116 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
library app_providers; | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
import 'notifiers/local_notifier.dart'; | ||
import 'notifiers/theme_notifier.dart'; | ||
|
||
export 'notifiers/local_notifier.dart'; | ||
export 'notifiers/theme_notifier.dart'; | ||
|
||
final localProvider = NotifierProvider<LocalNotifier, Locale>(() { | ||
return LocalNotifier(); | ||
}); | ||
|
||
final themeProvider = NotifierProvider<ThemeNotifier, ThemeMode>(() { | ||
return ThemeNotifier(); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'dart:io'; | ||
import 'dart:ui'; | ||
|
||
import 'package:bond_cache/bond_cache.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
class LocalNotifier extends Notifier<Locale> { | ||
@override | ||
Locale build() => Locale( | ||
Cache.get( | ||
'language', | ||
defaultValue: Platform.localeName, | ||
), | ||
); | ||
|
||
void update(Locale locale) { | ||
Cache.put('language', locale.languageCode); | ||
state = locale; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'package:bond_cache/bond_cache.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
class ThemeNotifier extends Notifier<ThemeMode> { | ||
@override | ||
ThemeMode build() => XThemeMode.fromValue( | ||
Cache.get( | ||
'theme', | ||
defaultValue: ThemeMode.system.value, | ||
), | ||
); | ||
|
||
void update(ThemeMode themeMode) { | ||
Cache.put('theme', themeMode.value); | ||
} | ||
} | ||
|
||
extension XThemeMode on ThemeMode { | ||
String get value { | ||
switch (this) { | ||
case ThemeMode.dark: | ||
return 'dark'; | ||
case ThemeMode.light: | ||
return 'light'; | ||
case ThemeMode.system: | ||
return 'system'; | ||
default: | ||
return 'system'; | ||
} | ||
} | ||
|
||
static ThemeMode fromValue(String value) { | ||
switch (value) { | ||
case 'dark': | ||
return ThemeMode.dark; | ||
case 'light': | ||
return ThemeMode.light; | ||
case 'system': | ||
return ThemeMode.system; | ||
default: | ||
return ThemeMode.system; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.