Skip to content

Commit

Permalink
feat: Migrate package to use NNBD and rxdart ^0.27.0 (#21)
Browse files Browse the repository at this point in the history
* Migrate package to use NNBD

* Update plugin_platform_interface dependency version

* Bump version to 1.3.0-nullsafety.1

* Use channel beta for the Github Actions

* Fix deprecations and warnings

* Update to rxdart ^0.27.0, refactor implementation

* Use Flutter channel `stable` for CI

* Update lower Dart SDK constraint to `2.12`, remove old analysis options

* Don't explicitly initialise to `null`

* Fix tests

* Update homepage

* Update gitignore, exclude IDE files

* Migrate example app to NNBD, update its pubspec

* Add SubjectValueWrapper

* Make the _persist callback operate on the original type

* Reformat

* Adapt type checks to null-safety

* Documentation improvements

* Use a list instead of prose in HydratedSubject doc comment

Co-authored-by: solid-vovabeloded <[email protected]>

* Improve HydratedSubject doc comment readability

Co-authored-by: solid-vovabeloded <[email protected]>

* Remove `late` modifier in tests, remove unnecessary null check

* Set value wrapper when hydrating

* Fix wrapper not being set

* Fix value setter

* Fix hydration type casts

* Fix value removal for primitive types

* Autoformat

* Use dedicated matchers

* Make widget members private in example app

* Move subject_value_wrapper.dart to src/model

* Move implementation into `src`

* Add export file

* Move variables declaration list to the top of class declaration

* Extract type check function into a utility class

* Use a typedef for function declaration

* Remove TypeComparisonFunction typedef, fix util class naming

Co-authored-by: Yurii Prykhodko <[email protected]>
Co-authored-by: solid-vovabeloded <[email protected]>
  • Loading branch information
3 people authored Aug 9, 2021
1 parent df38649 commit 047f01e
Show file tree
Hide file tree
Showing 16 changed files with 550 additions and 408 deletions.
1 change: 0 additions & 1 deletion .github/workflows/flutter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ jobs:
- uses: actions/checkout@v1
- uses: subosito/flutter-action@v1
with:
flutter-version: '1.12.13+hotfix.5'
channel: 'stable'
- run: flutter pub get
- run: flutter analyze
Expand Down
75 changes: 70 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,75 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.dart_tool/
.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/
ios/.generated/
ios/Flutter/Generated.xcconfig
ios/Runner/GeneratedPluginRegistrant.*

# 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
19 changes: 0 additions & 19 deletions .idea/libraries/Dart_SDK.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

36 changes: 0 additions & 36 deletions .idea/workspace.xml

This file was deleted.

48 changes: 26 additions & 22 deletions example/lib/class_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,59 +17,63 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatelessWidget {
final String title;
final String _title;

final count$ = HydratedSubject<SerializedClass>(
final _countSubject = HydratedSubject<SerializedClass>(
"serialized-count",
hydrate: (value) => SerializedClass.fromJSON(value),
persist: (value) => value.toJSON,
seedValue: SerializedClass(0),
);

MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({
Key? key,
required String title,
}) : _title = title,
super(key: key);

@override
Widget build(BuildContext context) {
print('Serialized Hydrated Demo');

return Scaffold(
appBar: AppBar(
title: Text(this.title),
title: Text(this._title),
),
body: Center(
child: StreamBuilder<SerializedClass>(
stream: count$,
initialData: count$.value,
builder: (context, snap) => Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'${snap.data.count}',
style: Theme.of(context).textTheme.display1,
),
],
stream: _countSubject,
initialData: _countSubject.value,
builder: (context, snapshot) => Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('You have pushed the button this many times:'),
Text(
'${snapshot.data?.count}',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
final count = count$.value.count + 1;
count$.add(SerializedClass(count));
},
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}

void _incrementCounter() {
final count = _countSubject.value.count + 1;
_countSubject.add(SerializedClass(count));
}
}

class SerializedClass {
final int count;

SerializedClass(this.count);
const SerializedClass(this.count);

SerializedClass.fromJSON(String json) : this.count = int.parse(json);

Expand Down
44 changes: 26 additions & 18 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,50 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatelessWidget {
final String title;
final count$ = HydratedSubject<int>("count", seedValue: 0);
final String _title;
final _count = HydratedSubject<int>("count", seedValue: 0);

MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({
Key? key,
required String title,
}) : _title = title,
super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(this.title),
title: Text(this._title),
),
body: Center(
child: StreamBuilder<int>(
stream: count$,
initialData: count$.value,
stream: _count,
initialData: _count.value,
builder: (context, snap) => Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'You have pushed the button this many times:',
),
Text(
'${snap.data}',
style: Theme.of(context).textTheme.display1,
),
],
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text('You have pushed the button this many times:'),
Text(
'${snap.data}',
style: Theme.of(context).textTheme.headline4,
),
],
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => count$.value++,
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}

void dispose() => count$.close();
void _incrementCounter() {
_count.value++;
}

void dispose() {
_count.close();
}
}
47 changes: 2 additions & 45 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,65 +1,22 @@
name: hydrated_demo
description: A demo showcasing the Hydrated package.
publish_to: 'none'

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# Read more about versioning at semver.org.
version: 1.0.0+1

environment:
sdk: ">=2.6.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
hydrated:
path: ../


dev_dependencies:
flutter_test:
sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.io/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.io/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.io/custom-fonts/#from-packages
19 changes: 0 additions & 19 deletions hydrated.iml

This file was deleted.

Loading

0 comments on commit 047f01e

Please sign in to comment.