adding packages
This commit is contained in:
@@ -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/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
|
||||
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
|
||||
@@ -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: 5bb552270db3acc43528ce843f66c08a1a9d37d4
|
||||
channel: master
|
||||
|
||||
project_type: package
|
||||
@@ -0,0 +1,7 @@
|
||||
## 1.0.4
|
||||
|
||||
- Sync with code gen package
|
||||
|
||||
## [0.0.1] - TODO: Add release date.
|
||||
|
||||
* TODO: Describe initial release.
|
||||
@@ -0,0 +1 @@
|
||||
TODO: Add your license here.
|
||||
@@ -0,0 +1,127 @@
|
||||
[](https://pub.dartlang.org/packages/settings_manager)
|
||||
[](https://pub.dartlang.org/packages/settings_gen)
|
||||
|
||||
# Settings Manager
|
||||
|
||||
- Flutter settings store built on top of shared preferences.
|
||||
- Code Generator for supported types
|
||||
|
||||
## Usage
|
||||
|
||||
```dart
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:settings_manager/settings_manager.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
part 'settings.g.dart';
|
||||
|
||||
class Settings = SettingsBase with _$Settings;
|
||||
|
||||
abstract class SettingsBase with SettingsStore {
|
||||
@BoolSetting(defaultValue: false)
|
||||
bool darkMode;
|
||||
|
||||
@StringSetting(defaultValue: 'none')
|
||||
String userId;
|
||||
|
||||
@IntSetting(defaultValue: 0)
|
||||
int counterValue;
|
||||
|
||||
@DoubleSetting(defaultValue: 0)
|
||||
double radialValue;
|
||||
|
||||
@StringListSetting(defaultValue: [])
|
||||
List<String> savedItems;
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```dart
|
||||
import 'package:flutter/material.dart';
|
||||
import 'settings.dart';
|
||||
|
||||
void main() {
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(primarySwatch: Colors.blue),
|
||||
home: MyHomePage(title: 'Flutter Demo Home Page'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
MyHomePage({Key key, this.title}) : super(key: key);
|
||||
|
||||
final String title;
|
||||
|
||||
@override
|
||||
_MyHomePageState createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
final _settings = Settings();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_settings.init().then((ready) {
|
||||
if (mounted) setState(() {});
|
||||
});
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StreamBuilder<int>(
|
||||
stream: _settings.counterValueStream,
|
||||
builder: (context, snapshot) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text(widget.title)),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'You have pushed the button this many times:',
|
||||
),
|
||||
Text(
|
||||
'${snapshot.data}',
|
||||
style: Theme.of(context).textTheme.headline4,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => _settings.counterValue = snapshot.data + 1,
|
||||
tooltip: 'Increment',
|
||||
child: Icon(Icons.add),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Annotations
|
||||
|
||||
`BoolSetting`
|
||||
|
||||
`StringSetting`
|
||||
|
||||
`IntSetting`
|
||||
|
||||
`DoubleSetting`
|
||||
|
||||
`StringListSetting`
|
||||
|
||||
All of these can enable/disable `addStream` and `addValueNotifier`
|
||||
@@ -0,0 +1,4 @@
|
||||
library settings_manager;
|
||||
|
||||
export 'src/api/annotations.dart';
|
||||
export 'src/api/store.dart';
|
||||
@@ -0,0 +1,62 @@
|
||||
/// Declares configuration of a SettingsStore class.
|
||||
/// Currently the only configuration used is boolean to indicate generation of toString method (true), or not (false)
|
||||
|
||||
class SettingsConfig {
|
||||
const SettingsConfig({this.hasToString = true});
|
||||
final bool hasToString;
|
||||
}
|
||||
|
||||
class BoolSetting {
|
||||
const BoolSetting({
|
||||
this.defaultValue,
|
||||
this.addStream = true,
|
||||
this.addValueNotifier = true,
|
||||
});
|
||||
final bool defaultValue;
|
||||
final bool addStream;
|
||||
final bool addValueNotifier;
|
||||
}
|
||||
|
||||
class StringSetting {
|
||||
const StringSetting({
|
||||
this.defaultValue,
|
||||
this.addStream = true,
|
||||
this.addValueNotifier = true,
|
||||
});
|
||||
final String defaultValue;
|
||||
final bool addStream;
|
||||
final bool addValueNotifier;
|
||||
}
|
||||
|
||||
class IntSetting {
|
||||
const IntSetting({
|
||||
this.defaultValue,
|
||||
this.addStream = true,
|
||||
this.addValueNotifier = true,
|
||||
});
|
||||
final int defaultValue;
|
||||
final bool addStream;
|
||||
final bool addValueNotifier;
|
||||
}
|
||||
|
||||
class DoubleSetting {
|
||||
const DoubleSetting({
|
||||
this.defaultValue,
|
||||
this.addStream = true,
|
||||
this.addValueNotifier = true,
|
||||
});
|
||||
final double defaultValue;
|
||||
final bool addStream;
|
||||
final bool addValueNotifier;
|
||||
}
|
||||
|
||||
class StringListSetting {
|
||||
const StringListSetting({
|
||||
this.defaultValue,
|
||||
this.addStream = true,
|
||||
this.addValueNotifier = true,
|
||||
});
|
||||
final List<String> defaultValue;
|
||||
final bool addStream;
|
||||
final bool addValueNotifier;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
/// The `SettingsStore` mixin is primarily meant for code-generation and used as part of the
|
||||
/// `settings_gen` package.
|
||||
mixin SettingsStore {}
|
||||
@@ -0,0 +1,17 @@
|
||||
name: settings_manager
|
||||
description: A settings manager built on top of SharedPreferences.
|
||||
version: 1.0.4
|
||||
homepage: https://github.com/rodydavis/settings_manager
|
||||
|
||||
environment:
|
||||
sdk: ">=2.1.0 <3.0.0"
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
flutter:
|
||||
Reference in New Issue
Block a user