Skip to content

Commit 047f01e

Browse files
solid-yuriiprykhodkoYurii Prykhodkosolid-vovabeloded
authored
feat: Migrate package to use NNBD and rxdart ^0.27.0 (#21)
* 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]>
1 parent df38649 commit 047f01e

File tree

16 files changed

+550
-408
lines changed

16 files changed

+550
-408
lines changed

.github/workflows/flutter.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ jobs:
99
- uses: actions/checkout@v1
1010
- uses: subosito/flutter-action@v1
1111
with:
12-
flutter-version: '1.12.13+hotfix.5'
1312
channel: 'stable'
1413
- run: flutter pub get
1514
- run: flutter analyze

.gitignore

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,75 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
16
.DS_Store
2-
.dart_tool/
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
12+
# IntelliJ related
13+
*.iml
14+
*.ipr
15+
*.iws
16+
.idea/
317

18+
# The .vscode folder contains launch configuration and tasks you configure in
19+
# VS Code which you may wish to be included in version control, so this line
20+
# is commented out by default.
21+
#.vscode/
22+
23+
# Flutter/Dart/Pub related
24+
**/doc/api/
25+
.dart_tool/
26+
.flutter-plugins
27+
.flutter-plugins-dependencies
428
.packages
29+
.pub-cache/
530
.pub/
6-
731
build/
8-
ios/.generated/
9-
ios/Flutter/Generated.xcconfig
10-
ios/Runner/GeneratedPluginRegistrant.*
32+
33+
# Android related
34+
**/android/**/gradle-wrapper.jar
35+
**/android/.gradle
36+
**/android/captures/
37+
**/android/gradlew
38+
**/android/gradlew.bat
39+
**/android/local.properties
40+
**/android/**/GeneratedPluginRegistrant.java
41+
42+
# iOS/XCode related
43+
**/ios/**/*.mode1v3
44+
**/ios/**/*.mode2v3
45+
**/ios/**/*.moved-aside
46+
**/ios/**/*.pbxuser
47+
**/ios/**/*.perspectivev3
48+
**/ios/**/*sync/
49+
**/ios/**/.sconsign.dblite
50+
**/ios/**/.tags*
51+
**/ios/**/.vagrant/
52+
**/ios/**/DerivedData/
53+
**/ios/**/Icon?
54+
**/ios/**/Pods/
55+
**/ios/**/.symlinks/
56+
**/ios/**/profile
57+
**/ios/**/xcuserdata
58+
**/ios/.generated/
59+
**/ios/Flutter/App.framework
60+
**/ios/Flutter/Flutter.framework
61+
**/ios/Flutter/Flutter.podspec
62+
**/ios/Flutter/Generated.xcconfig
63+
**/ios/Flutter/ephemeral
64+
**/ios/Flutter/app.flx
65+
**/ios/Flutter/app.zip
66+
**/ios/Flutter/flutter_assets/
67+
**/ios/Flutter/flutter_export_environment.sh
68+
**/ios/ServiceDefinitions.json
69+
**/ios/Runner/GeneratedPluginRegistrant.*
70+
71+
# Exceptions to above rules.
72+
!**/ios/**/default.mode1v3
73+
!**/ios/**/default.mode2v3
74+
!**/ios/**/default.pbxuser
75+
!**/ios/**/default.perspectivev3

.idea/libraries/Dart_SDK.xml

Lines changed: 0 additions & 19 deletions
This file was deleted.

.idea/modules.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/workspace.xml

Lines changed: 0 additions & 36 deletions
This file was deleted.

example/lib/class_example.dart

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,59 +17,63 @@ class MyApp extends StatelessWidget {
1717
}
1818

1919
class MyHomePage extends StatelessWidget {
20-
final String title;
20+
final String _title;
2121

22-
final count$ = HydratedSubject<SerializedClass>(
22+
final _countSubject = HydratedSubject<SerializedClass>(
2323
"serialized-count",
2424
hydrate: (value) => SerializedClass.fromJSON(value),
2525
persist: (value) => value.toJSON,
2626
seedValue: SerializedClass(0),
2727
);
2828

29-
MyHomePage({Key key, this.title}) : super(key: key);
29+
MyHomePage({
30+
Key? key,
31+
required String title,
32+
}) : _title = title,
33+
super(key: key);
3034

3135
@override
3236
Widget build(BuildContext context) {
3337
print('Serialized Hydrated Demo');
3438

3539
return Scaffold(
3640
appBar: AppBar(
37-
title: Text(this.title),
41+
title: Text(this._title),
3842
),
3943
body: Center(
4044
child: StreamBuilder<SerializedClass>(
41-
stream: count$,
42-
initialData: count$.value,
43-
builder: (context, snap) => Column(
44-
mainAxisAlignment: MainAxisAlignment.center,
45-
children: <Widget>[
46-
Text(
47-
'You have pushed the button this many times:',
48-
),
49-
Text(
50-
'${snap.data.count}',
51-
style: Theme.of(context).textTheme.display1,
52-
),
53-
],
45+
stream: _countSubject,
46+
initialData: _countSubject.value,
47+
builder: (context, snapshot) => Column(
48+
mainAxisAlignment: MainAxisAlignment.center,
49+
children: [
50+
Text('You have pushed the button this many times:'),
51+
Text(
52+
'${snapshot.data?.count}',
53+
style: Theme.of(context).textTheme.headline4,
5454
),
55+
],
56+
),
5557
),
5658
),
5759
floatingActionButton: FloatingActionButton(
58-
onPressed: () {
59-
final count = count$.value.count + 1;
60-
count$.add(SerializedClass(count));
61-
},
60+
onPressed: _incrementCounter,
6261
tooltip: 'Increment',
6362
child: Icon(Icons.add),
6463
),
6564
);
6665
}
66+
67+
void _incrementCounter() {
68+
final count = _countSubject.value.count + 1;
69+
_countSubject.add(SerializedClass(count));
70+
}
6771
}
6872

6973
class SerializedClass {
7074
final int count;
7175

72-
SerializedClass(this.count);
76+
const SerializedClass(this.count);
7377

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

example/lib/main.dart

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,50 @@ class MyApp extends StatelessWidget {
1717
}
1818

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

23-
MyHomePage({Key key, this.title}) : super(key: key);
23+
MyHomePage({
24+
Key? key,
25+
required String title,
26+
}) : _title = title,
27+
super(key: key);
2428

2529
@override
2630
Widget build(BuildContext context) {
2731
return Scaffold(
2832
appBar: AppBar(
29-
title: Text(this.title),
33+
title: Text(this._title),
3034
),
3135
body: Center(
3236
child: StreamBuilder<int>(
33-
stream: count$,
34-
initialData: count$.value,
37+
stream: _count,
38+
initialData: _count.value,
3539
builder: (context, snap) => Column(
36-
mainAxisAlignment: MainAxisAlignment.center,
37-
children: <Widget>[
38-
Text(
39-
'You have pushed the button this many times:',
40-
),
41-
Text(
42-
'${snap.data}',
43-
style: Theme.of(context).textTheme.display1,
44-
),
45-
],
40+
mainAxisAlignment: MainAxisAlignment.center,
41+
children: [
42+
Text('You have pushed the button this many times:'),
43+
Text(
44+
'${snap.data}',
45+
style: Theme.of(context).textTheme.headline4,
4646
),
47+
],
48+
),
4749
),
4850
),
4951
floatingActionButton: FloatingActionButton(
50-
onPressed: () => count$.value++,
52+
onPressed: _incrementCounter,
5153
tooltip: 'Increment',
5254
child: Icon(Icons.add),
5355
),
5456
);
5557
}
5658

57-
void dispose() => count$.close();
59+
void _incrementCounter() {
60+
_count.value++;
61+
}
62+
63+
void dispose() {
64+
_count.close();
65+
}
5866
}

example/pubspec.yaml

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,22 @@
11
name: hydrated_demo
22
description: A demo showcasing the Hydrated package.
3+
publish_to: 'none'
34

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

127
environment:
13-
sdk: ">=2.6.0 <3.0.0"
8+
sdk: ">=2.12.0 <3.0.0"
149

1510
dependencies:
1611
flutter:
1712
sdk: flutter
1813

19-
# The following adds the Cupertino Icons font to your application.
20-
# Use with the CupertinoIcons class for iOS style icons.
21-
cupertino_icons: ^0.1.2
2214
hydrated:
2315
path: ../
2416

25-
2617
dev_dependencies:
2718
flutter_test:
2819
sdk: flutter
2920

30-
# For information on the generic Dart part of this file, see the
31-
# following page: https://www.dartlang.org/tools/pub/pubspec
32-
33-
# The following section is specific to Flutter.
3421
flutter:
35-
# The following line ensures that the Material Icons font is
36-
# included with your application, so that you can use the icons in
37-
# the material Icons class.
3822
uses-material-design: true
39-
# To add assets to your application, add an assets section, like this:
40-
# assets:
41-
# - images/a_dot_burr.jpeg
42-
# - images/a_dot_ham.jpeg
43-
# An image asset can refer to one or more resolution-specific "variants", see
44-
# https://flutter.io/assets-and-images/#resolution-aware.
45-
# For details regarding adding assets from package dependencies, see
46-
# https://flutter.io/assets-and-images/#from-packages
47-
# To add custom fonts to your application, add a fonts section here,
48-
# in this "flutter" section. Each entry in this list should have a
49-
# "family" key with the font family name, and a "fonts" key with a
50-
# list giving the asset and other descriptors for the font. For
51-
# example:
52-
# fonts:
53-
# - family: Schyler
54-
# fonts:
55-
# - asset: fonts/Schyler-Regular.ttf
56-
# - asset: fonts/Schyler-Italic.ttf
57-
# style: italic
58-
# - family: Trajan Pro
59-
# fonts:
60-
# - asset: fonts/TrajanPro.ttf
61-
# - asset: fonts/TrajanPro_Bold.ttf
62-
# weight: 700
63-
#
64-
# For details regarding fonts from package dependencies,
65-
# see https://flutter.io/custom-fonts/#from-packages

hydrated.iml

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)