-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example showing an unintuitive situation
where `MappedNavigatableSource` instances can be created in `build()` methods, which would then be recreated (and thus loose all state) on higher-level rebuilds/hot reloads
- Loading branch information
Showing
4 changed files
with
80 additions
and
3 deletions.
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
39 changes: 39 additions & 0 deletions
39
example/lib/src/examples/hot_reloadable_mapped_navigator.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,39 @@ | ||
import 'package:fdr/fdr.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class HotReloadableMappedNavigator extends StatelessNavigator { | ||
@override | ||
List<DeclarativeNavigatable> build() { | ||
return [ | ||
MappedNavigatorDemo(), | ||
]; | ||
} | ||
} | ||
|
||
class MappedNavigatorDemo extends MappedNavigatableSource<int> { | ||
MappedNavigatorDemo() : super(initialState: 0); | ||
|
||
@override | ||
List<DeclarativeNavigatable> build() { | ||
return [ | ||
Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Stateless Navigator'), | ||
), | ||
body: Center( | ||
child: Column( | ||
children: [ | ||
Text('Count: $state'), | ||
FilledButton( | ||
onPressed: () { | ||
state++; | ||
}, | ||
child: const Text('Increment'), | ||
) | ||
], | ||
), | ||
), | ||
).page(onPop: null), | ||
]; | ||
} | ||
} |
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
34 changes: 34 additions & 0 deletions
34
example/lib/src/examples/hot_reloadable_stateless_navigator.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,34 @@ | ||
import 'package:fdr/fdr.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class HotReloadableStatelessNavigator extends StatelessNavigator { | ||
@override | ||
List<DeclarativeNavigatable> build() { | ||
return [ | ||
StatelessNavigatorDemo(greeting: 'hello, world!'), | ||
]; | ||
} | ||
} | ||
|
||
class StatelessNavigatorDemo extends StatelessNavigator { | ||
@visibleForTesting | ||
StatelessNavigatorDemo({ | ||
required this.greeting, | ||
}); | ||
|
||
final String greeting; | ||
|
||
@override | ||
List<DeclarativeNavigatable> build() { | ||
return [ | ||
Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Stateless Navigator'), | ||
), | ||
body: Center( | ||
child: Text(greeting), | ||
), | ||
).page(onPop: null), | ||
]; | ||
} | ||
} |