New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Account for existing _forceLastValidStreamState when rebuilding #142
Merged
marcglasberg
merged 4 commits into
marcglasberg:master
from
kuhnroyal:fix/should-update-model-rebuild
Oct 10, 2022
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: Build | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- develop | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
name: Run tests | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: subosito/flutter-action@v2 | ||
with: | ||
channel: stable | ||
- run: flutter pub get | ||
- run: flutter test |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
@Skip('Requires precise timing') | ||
import 'dart:async'; | ||
|
||
import "package:async_redux/async_redux.dart"; | ||
|
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,141 @@ | ||
import "package:async_redux/async_redux.dart"; | ||
import "package:flutter/material.dart"; | ||
import "package:flutter_test/flutter_test.dart"; | ||
|
||
void main() { | ||
group(StoreConnector, () { | ||
// TODO shouldUpdateModel does not currently work with converter | ||
testWidgets( | ||
"shouldUpdateModel.converter", | ||
(tester) async { | ||
final storeTester = StoreTester<int>(initialState: 0); | ||
|
||
await tester.pumpWidget(StoreProvider<int>( | ||
store: storeTester.store, | ||
child: MaterialApp( | ||
home: StoreConnector<int, int>( | ||
converter: (store) => store.state, | ||
shouldUpdateModel: (state) => state % 2 == 0, | ||
builder: (context, value) { | ||
return Text(value.toString()); | ||
}, | ||
), | ||
), | ||
)); | ||
|
||
expect(find.text("0"), findsOneWidget); | ||
|
||
await storeTester.dispatchState(1); | ||
await tester.pumpAndSettle(); | ||
expect(find.text("0"), findsOneWidget); | ||
|
||
await storeTester.dispatchState(2); | ||
await tester.pumpAndSettle(); | ||
expect(find.text("2"), findsOneWidget); | ||
}, | ||
skip: true, | ||
); | ||
|
||
testWidgets( | ||
"shouldUpdateModel.vm", | ||
(tester) async { | ||
final storeTester = StoreTester<int>(initialState: 0); | ||
|
||
await tester.pumpWidget(StoreProvider<int>( | ||
store: storeTester.store, | ||
child: _TestWidget(), | ||
)); | ||
|
||
expect(find.text("0"), findsOneWidget); | ||
|
||
await storeTester.dispatchState(1); | ||
await tester.pumpAndSettle(); | ||
expect(find.text("0"), findsOneWidget); | ||
|
||
await storeTester.dispatchState(2); | ||
await tester.pumpAndSettle(); | ||
expect(find.text("2"), findsOneWidget); | ||
}, | ||
); | ||
|
||
testWidgets( | ||
"shouldUpdateModel.vm with external rebuild", | ||
(tester) async { | ||
final storeTester = StoreTester<int>(initialState: 0); | ||
|
||
await tester.pumpWidget(StoreProvider<int>( | ||
store: storeTester.store, | ||
child: _TestWidget(), | ||
)); | ||
|
||
expect(find.text("0"), findsOneWidget); | ||
|
||
storeTester.dispatchState(1); | ||
await tester.pump(); | ||
await tester.pump(); | ||
expect(find.text("0"), findsOneWidget); | ||
|
||
tester.firstState<_TestWidgetState>(find.byType(_TestWidget)).forceRebuild(); | ||
await tester.pump(); | ||
await tester.pump(); | ||
expect(find.text("0"), findsOneWidget); | ||
}, | ||
); | ||
}); | ||
} | ||
|
||
class _TestWidget extends StatefulWidget { | ||
_TestWidget({ | ||
Key? key, | ||
}) : super(key: key); | ||
|
||
@override | ||
State<_TestWidget> createState() => _TestWidgetState(); | ||
} | ||
|
||
class _TestWidgetState extends State<_TestWidget> { | ||
void forceRebuild() => setState(() {}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
home: _TestContent(key: const ValueKey("tester")), | ||
); | ||
} | ||
} | ||
|
||
class _TestContent extends StatelessWidget { | ||
_TestContent({ | ||
Key? key, | ||
}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return StoreConnector<int, ViewModel>( | ||
vm: () => Factory(this), | ||
shouldUpdateModel: (state) => state % 2 == 0, | ||
builder: (context, vm) { | ||
return Text(vm.counter.toString()); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
class Factory extends VmFactory<int, _TestContent> { | ||
Factory(widget) : super(widget); | ||
|
||
@override | ||
ViewModel fromStore() { | ||
return ViewModel( | ||
counter: state, | ||
); | ||
} | ||
} | ||
|
||
class ViewModel extends Vm { | ||
final int counter; | ||
|
||
ViewModel({ | ||
required this.counter, | ||
}) : super(equals: [counter]); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo here. "This is needed"