Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
gamako committed Nov 3, 2021
0 parents commit 692fa08
Show file tree
Hide file tree
Showing 19 changed files with 1,235 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Sugama Tatsuo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# SharedPreferences riverpod

Make it easier to access SharePreferences using Riverpod's Provider.

https://pub.dev/packages/shared_preferences
https://pub.dev/packages/riverpod

## Usage

```dart
final booPrefProvider = createPrefNotifierProvider<bool>(
prefs: (_) => prefs,
prefKey: "boolValue",
defaultValue: false,
);
enum EnumValues {
foo,
bar,
}
final enumPrefProvider = createEnumPrefNotifierProvider<EnumValues>(
prefs: (_) => prefs,
prefKey: "enumValue",
mapFrom: (v) => EnumValues.values
.firstWhere((e) => e.toString() == v, orElse: () => EnumValues.foo),
mapTo: (v) => v.toString(),
);
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Sample',
home: Scaffold(
appBar: AppBar(),
body: Consumer(builder: (context, watch, _) {
return ListView(children: [
CheckboxListTile(
title: Text('BoolPrefNotifier ${watch(booPrefProvider)}'),
value: watch(booPrefProvider),
onChanged: (v) {
if (v != null) watch(booPrefProvider.notifier).update(v);
},
),
RadioListTile(
title: Text('Enum ${EnumValues.foo.toString()}'),
value: EnumValues.foo,
groupValue: watch(enumPrefProvider),
onChanged: (EnumValues? v) {
if (v != null) watch(enumPrefProvider.notifier).update(v);
},
),
RadioListTile(
title: Text('Enum ${EnumValues.foo.toString()}'),
value: EnumValues.bar,
groupValue: watch(enumPrefProvider),
onChanged: (EnumValues? v) {
if (v != null) watch(enumPrefProvider.notifier).update(v);
},
),
]);
}),
),
);
}
}
```
75 changes: 75 additions & 0 deletions packages/shared_preferences_flutter_riverpod/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
build/

# Android related
**/android/**/gradle-wrapper.jar
**/android/.gradle
**/android/captures/
**/android/gradlew
**/android/gradlew.bat
**/android/local.properties
**/android/**/GeneratedPluginRegistrant.java

# iOS/XCode related
**/ios/**/*.mode1v3
**/ios/**/*.mode2v3
**/ios/**/*.moved-aside
**/ios/**/*.pbxuser
**/ios/**/*.perspectivev3
**/ios/**/*sync/
**/ios/**/.sconsign.dblite
**/ios/**/.tags*
**/ios/**/.vagrant/
**/ios/**/DerivedData/
**/ios/**/Icon?
**/ios/**/Pods/
**/ios/**/.symlinks/
**/ios/**/profile
**/ios/**/xcuserdata
**/ios/.generated/
**/ios/Flutter/App.framework
**/ios/Flutter/Flutter.framework
**/ios/Flutter/Flutter.podspec
**/ios/Flutter/Generated.xcconfig
**/ios/Flutter/ephemeral
**/ios/Flutter/app.flx
**/ios/Flutter/app.zip
**/ios/Flutter/flutter_assets/
**/ios/Flutter/flutter_export_environment.sh
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
10 changes: 10 additions & 0 deletions packages/shared_preferences_flutter_riverpod/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 18116933e77adc82f80866c928266a5b4f1ed645
channel: stable

project_type: package
3 changes: 3 additions & 0 deletions packages/shared_preferences_flutter_riverpod/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
21 changes: 21 additions & 0 deletions packages/shared_preferences_flutter_riverpod/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Sugama Tatsuo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
70 changes: 70 additions & 0 deletions packages/shared_preferences_flutter_riverpod/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# SharedPreferences riverpod

Make it easier to access SharePreferences using Riverpod's Provider.

https://pub.dev/packages/shared_preferences
https://pub.dev/packages/riverpod

## Usage

```dart
final booPrefProvider = createPrefNotifierProvider<bool>(
prefs: (_) => prefs,
prefKey: "boolValue",
defaultValue: false,
);
enum EnumValues {
foo,
bar,
}
final enumPrefProvider = createEnumPrefNotifierProvider<EnumValues>(
prefs: (_) => prefs,
prefKey: "enumValue",
mapFrom: (v) => EnumValues.values
.firstWhere((e) => e.toString() == v, orElse: () => EnumValues.foo),
mapTo: (v) => v.toString(),
);
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Sample',
home: Scaffold(
appBar: AppBar(),
body: Consumer(builder: (context, watch, _) {
return ListView(children: [
CheckboxListTile(
title: Text('BoolPrefNotifier ${watch(booPrefProvider)}'),
value: watch(booPrefProvider),
onChanged: (v) {
if (v != null) watch(booPrefProvider.notifier).update(v);
},
),
RadioListTile(
title: Text('Enum ${EnumValues.foo.toString()}'),
value: EnumValues.foo,
groupValue: watch(enumPrefProvider),
onChanged: (EnumValues? v) {
if (v != null) watch(enumPrefProvider.notifier).update(v);
},
),
RadioListTile(
title: Text('Enum ${EnumValues.foo.toString()}'),
value: EnumValues.bar,
groupValue: watch(enumPrefProvider),
onChanged: (EnumValues? v) {
if (v != null) watch(enumPrefProvider.notifier).update(v);
},
),
]);
}),
),
);
}
}
```
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:flutter_lints/flutter.yaml
49 changes: 49 additions & 0 deletions packages/shared_preferences_flutter_riverpod/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
ios/
android/

# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Web related
lib/generated_plugin_registrant.dart

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
10 changes: 10 additions & 0 deletions packages/shared_preferences_flutter_riverpod/example/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: 18116933e77adc82f80866c928266a5b4f1ed645
channel: stable

project_type: app
16 changes: 16 additions & 0 deletions packages/shared_preferences_flutter_riverpod/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# shared_preferences_flutter_riverpod_sample

A new Flutter project.

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)

For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

linter:
rules:
Loading

0 comments on commit 692fa08

Please sign in to comment.