-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[go_router] Nested stateful navigation with ShellRoute #2650
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
Closed
Closed
Changes from 17 commits
Commits
Show all changes
159 commits
Select commit
Hold shift + click to select a range
fa4c542
Added NestedNavigationShellRoute, to support building nested persiste…
tolo 76b17ae
Added example for NestedNavigationShellRoute.
tolo 7612a55
Formatting.
tolo 62574bd
Formatting.
tolo 850f41a
Removed NestedNavigationShellRoute and replaced it with new field `ne…
tolo 1c04588
Rebased onto upstream/main.
tolo 1db6bba
Fixed typos.
tolo 6028c90
Updated documentation of property navigatorKey on ShellRoute.
tolo 5f2e995
Added another unit test for ShellRoute with nestedNavigationBuilder.
tolo 461efd9
Updated example to use nested ShellRoutes instead of creating nested …
tolo 0315e1a
Refactored support for nested stateful navigation - introduced new ro…
tolo 510ec34
Some renaming.
tolo e82647a
Changed the way currentLocation is calculated since it currently does…
tolo e38fa32
Minor cleanup and refactoring.
tolo f38b9bf
Renamed StackedNavigationScaffold to StackedNavigationShell.
tolo 89f1dd7
Added more tests for PartitionedShellRoute.
tolo 3a00a54
Added more detail
tolo b0a6264
Fixed analyzer issue and code style issue.
tolo b729d64
Merge branch 'main' of github.com:flutter/packages into nested-persis…
johnpryan 3b3909f
Fix test
johnpryan f0b2a1b
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo eb6d4d3
Introduced the method `navigatorKeyForChildRoute` on ShellRouteBase t…
tolo 016be76
Added a canPop test for PartitionedShellRoute (by replacing a duplica…
tolo 4ae26d7
Updated implementation of popRoute be in sync with canPop.
tolo 4a9889a
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 1f3f01a
Updated documentation of PartitionedShellRoute with examples.
tolo 3b38641
Updated documentation for builder and pageBuilder fields of ShellRout…
tolo d701ab5
Fixed documentation typos and minor refactoring (renaming).
tolo bb6240d
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 245d47b
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo bda571b
Refactored PartitionedShellRoute and renamed to StatefulShellRoute.
tolo da1ea0b
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 59c19e7
Some refactoring (mostly naming and code readability).
tolo 723de76
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 4c0a91d
Fixed CI analyzer issue.
tolo 7556965
Removed animation support from StatefulNavigationShell and refactored…
tolo ee9bde9
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo e9a7029
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 59a6b05
Updated changelog (replaced PartitionedShellRoute with StatefulShellR…
tolo 06ab1e9
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 1b877c8
Implemented equality in StatefulShellRouteState and ShellRouteBranchS…
tolo e542a05
Documentation updates.
tolo 2215a51
Removed field navigatorKeys from StatefulShellRoute and fixed issue w…
tolo b180653
Removed the use of top GoRouterState as a way of getting the current …
tolo 8fdfb82
Updated example to use the default constructors of StatefulShellRoute…
tolo 9240ea4
Added check when pushing a new route to ensure you cannot push a rout…
tolo 93bce8e
Minor renaming.
tolo 20dc0c6
Added restorationScopeId to ShellRouteBranch and ShellRoute.
tolo 376e80f
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 2b2ff91
Added support for maintaining any extra navigation object passed to t…
tolo 5c9fe04
Moved NEXT info 5.2.0 in changelog
tolo 81e1296
Added assertion in RouteConfiguration for field defaultLocation of Sh…
tolo 59e3b66
Added field preloadBranches to StatefulShellRoute, to enable support …
tolo 8636bf8
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 1c509f1
Various updates from PR feedback:
tolo 42c7b7d
Changed the way switching between route branches works - switching is…
tolo 62e7fc1
Reverted restriction around pushing sub-routes of a StatefulShellRoute.
tolo 9a7069a
Doc fixes/updates for StatefulShellRoute.
tolo ae48ede
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 141fdc1
Added handling of redirection when switching and preloading route bra…
tolo b6b289f
Reintroduced validation of defaultLocation of StatefulShellRoute (in …
tolo 4d05d99
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo d4edd47
Removed replaceMatchList in GoRouterDelegate (using setNewRoutePath i…
tolo 7b9de47
Added additional test for redirection with StatefulShellRoute.
tolo 703815c
Updated ShellRouteBranch to accept list of routes instead of only a s…
tolo 9f88928
Added support for resetting StatefulShellRouteState.
tolo 5ca533d
Renamed and changed signature of the navigator getters of StatefulShe…
tolo f5f0ecb
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 4a2eac3
Added temporary workaround due to duplication of encodedParams of Rou…
tolo fc7bd54
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo a65f9df
Refactoring of StatefulShellRoute to support dynamic branches, as wel…
tolo 816acb2
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo ee2a845
Introduced an internal branch Navigator proxy widget to make the API …
tolo 89b82c5
Renamed StatefulShellRoute example file to stateful_shell_route.dart
tolo 90b9d62
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 7392264
Reduced unnecessary rebuilds of child Widgets of StatefulShellRoute, …
tolo c0253f6
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 2c4afa1
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 845c052
Minor refactoring - moved StatefulShellBranchResolver to route.dart.
tolo 193a267
Fixed issue in StatefulShellBranch.isBranchFor (accidental use of inc…
tolo 37c4969
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo c562482
Reverted workaround regarding pop.
tolo 38b5772
Equality fix in UnmodifiableRouteMatchList.
tolo db22bac
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo d8d1641
Corrected invalid sample file names.
tolo 4c4b7b0
Additional rebuild improvement.
tolo f08f548
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 6f1b047
Minor documentation fix.
tolo 07ee030
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 9ffff5c
Removed AppRouterProvider from sample code.
tolo e9d40ee
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 0ea48cb
Update packages/go_router/CHANGELOG.md
tolo 4abcaa9
Update packages/go_router/CHANGELOG.md
tolo ce23558
Update packages/go_router/CHANGELOG.md
tolo 351ceb2
Update packages/go_router/lib/src/route.dart
tolo 4cb0f1e
Partially reverted the StatefulShellRoute API back to the previous so…
tolo e6a4f71
Documentation updates and some renaming.
tolo 873bf34
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 5b668f8
Fix for error in _preloadShellBranchNavigator due to recent changes i…
tolo 565c3cd
Updated _routeMatchLookUp to handle reused/cached Navigators.
tolo 5ee1a8f
Added support for resetting state for single branch (resetBranch).
tolo 358551f
Added examples of pushing modal routes above the stateful shell.
tolo f9a2608
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 87211aa
Alternative StatefulShellRoute implementation, were either a builder …
tolo 257a272
Extracted construction of StatefulNavigationShell and Navigators out …
tolo 08148e5
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo c18941f
Added NavigatorObserver support to StatefulShellRoute.
tolo b1ce762
Refactored the builder methods of the shell route classes to improve …
tolo 75e43d0
Various refactoring.
tolo 9f54b4e
Minor renaming.
tolo 1226f44
Updated equals method in GoRouterState to properly compare Map fields.
tolo 881be86
Updated handling of RouteMatch lookup for pages/routes (replaced Expa…
tolo 6bbbd29
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo fd5412f
Add type annotation to listEquals
tolo a5234a6
Moved RouteNavigatorBuilder into builder.dart and made private.
tolo b9428cb
Moved StatefulNavigationShell and support classes into route.dart and…
tolo ee047c8
Refactoring of StatefulShellRoute and related classes to simplify bui…
tolo ddc71f0
Re-introduced proper validation of parent Navigator keys for routes i…
tolo 5041bea
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 01cce04
Updated constructors in sample code to use super parameters.
tolo 9315373
Removed preload support.
tolo 89341ef
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 2c298cd
Refactored state management for StatefulShellRoute.
tolo 4c22b53
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo a7d419f
Moved branch state management back into StatefulShellRoute and simpli…
tolo 7285788
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 9983887
Renamed StatefulShellRoute to StackedShellRoute
tolo ad43837
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 3a83007
Merge remote-tracking branch 'upstream/main' into nested-persistent-n…
tolo ec6722c
Update packages/go_router/lib/src/route.dart
tolo 9bb0da9
Update packages/go_router/lib/src/route.dart
tolo a1c7a8f
Update packages/go_router/lib/src/route.dart
tolo 477b47c
Removed StackedShellRouteState and moved functionality into StackedNa…
tolo 7f25f0c
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 6f35636
Doc updates - removed/replaced references to StackedShellRouteState.
tolo bb5c08f
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 16c095c
Refactoring due to review feedback.
tolo a18a5a5
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo abbd01b
Removed matchListEquals from RouteMatchList and replaced with the now…
tolo 0f36623
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 316cf8c
Removed obsolete copy method from RouteMatchList.
tolo 79a0c63
Updated StatefulNavigationShell to only save the part of the RouteMat…
tolo 3696448
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 763b136
Minor sample code refactoring (documentation and renaming).
tolo 2f48831
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 709ee7a
Apply suggestions from code review
tolo bb7fd9e
Implemented review feedback
tolo 9eaf1af
Some additional cleanup
tolo 527a806
Merge branch 'main' of github.com:flutter/packages into nested-persis…
tolo 86a72e1
Merge branch 'main' into nested-persistent-navigation
johnpryan 57b761f
Apply suggestions from code review
tolo 85fa0b6
Apply suggestions from code review.
tolo d75c5e2
Reintroduced resetLocation parameter to goBranch.
tolo bd1c018
Merge remote-tracking branch 'upstream/main' into nested-persistent-n…
tolo c13cd71
Renamed parameter resetLocation in goBranch to initialLocation.
tolo c7b1295
Fixed future deprecation warning workaround
tolo 0f842ee
Merge remote-tracking branch 'upstream/main' into nested-persistent-n…
tolo 80c396f
Merge branch 'main' into nested-persistent-navigation
chunhtai 04b549a
Merge branch 'main' into nested-persistent-navigation
johnpryan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
295 changes: 295 additions & 0 deletions
295
packages/go_router/example/lib/stateful_nested_navigation.dart
This file contains hidden or 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,295 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:flutter/material.dart'; | ||
| import 'package:go_router/go_router.dart'; | ||
|
|
||
| final GlobalKey<NavigatorState> _sectionANavigatorKey = | ||
| GlobalKey<NavigatorState>(debugLabel: 'sectionANav'); | ||
| final GlobalKey<NavigatorState> _sectionBNavigatorKey = | ||
| GlobalKey<NavigatorState>(debugLabel: 'sectionBNav'); | ||
|
|
||
| // This example demonstrates how to setup nested navigation using a | ||
| // BottomNavigationBar, where each tab uses its own persistent navigator, i.e. | ||
| // navigation state is maintained separately for each tab. This setup also | ||
| // enables deep linking into nested pages. | ||
| // | ||
| // This example demonstrates how to display routes within a ShellRoute using a | ||
| // `nestedNavigationBuilder`. Navigators for the tabs ('Section A' and | ||
| // 'Section B') are created via nested ShellRoutes. Note that no navigator will | ||
| // be created by the "top" ShellRoute. This example is similar to the ShellRoute | ||
| // example, but differs in that it is able to maintain the navigation state of | ||
| // each tab. | ||
|
|
||
| void main() { | ||
| runApp(NestedTabNavigationExampleApp()); | ||
| } | ||
|
|
||
| /// An example demonstrating how to use nested navigators | ||
| class NestedTabNavigationExampleApp extends StatelessWidget { | ||
| /// Creates a NestedTabNavigationExampleApp | ||
| NestedTabNavigationExampleApp({Key? key}) : super(key: key); | ||
|
|
||
| static final List<ScaffoldWithNavBarTabItem> _tabs = | ||
| <ScaffoldWithNavBarTabItem>[ | ||
| ScaffoldWithNavBarTabItem( | ||
| navigationItem: StackedNavigationItem( | ||
| rootRoutePath: '/a', navigatorKey: _sectionANavigatorKey), | ||
| icon: const Icon(Icons.home), | ||
| label: 'Section A'), | ||
| ScaffoldWithNavBarTabItem( | ||
| navigationItem: StackedNavigationItem( | ||
| rootRoutePath: '/b', navigatorKey: _sectionBNavigatorKey), | ||
| icon: const Icon(Icons.settings), | ||
| label: 'Section B', | ||
| ), | ||
| ]; | ||
|
|
||
| final GoRouter _router = GoRouter( | ||
| initialLocation: '/a', | ||
| routes: <RouteBase>[ | ||
| /// Custom top shell route - wraps the below routes in a scaffold with | ||
| /// a bottom tab navigator (ScaffoldWithNavBar). Each tab will use its own | ||
| /// Navigator, provided by MultiPathShellRoute. | ||
| PartitionedShellRoute.stackedNavigation( | ||
| stackItems: _tabs | ||
| .map((ScaffoldWithNavBarTabItem e) => e.navigationItem) | ||
| .toList(), | ||
| scaffoldBuilder: (BuildContext context, int currentIndex, | ||
| List<StackedNavigationItemState> itemsState, Widget scaffoldBody) { | ||
| return ScaffoldWithNavBar( | ||
| tabs: _tabs, | ||
| currentIndex: currentIndex, | ||
| itemsState: itemsState, | ||
| body: scaffoldBody); | ||
| }, | ||
|
|
||
| /// A transition builder is optional, only included here for | ||
| /// demonstration purposes. | ||
| transitionBuilder: | ||
| (BuildContext context, Animation<double> animation, Widget child) => | ||
| FadeTransition(opacity: animation, child: child), | ||
| routes: <GoRoute>[ | ||
| /// The screen to display as the root in the first tab of the bottom | ||
| /// navigation bar. Note that the root route must specify the | ||
| /// `parentNavigatorKey` | ||
| GoRoute( | ||
| parentNavigatorKey: _sectionANavigatorKey, | ||
| path: '/a', | ||
| builder: (BuildContext context, GoRouterState state) => | ||
| const RootScreen(label: 'A', detailsPath: '/a/details'), | ||
| routes: <RouteBase>[ | ||
| /// The details screen to display stacked on navigator of the | ||
| /// first tab. This will cover screen A but not the application | ||
| /// shell (bottom navigation bar). | ||
| GoRoute( | ||
| path: 'details', | ||
| builder: (BuildContext context, GoRouterState state) => | ||
| const DetailsScreen(label: 'A'), | ||
| ), | ||
| ], | ||
| ), | ||
|
|
||
| /// The screen to display as the root in the second tab of the bottom | ||
| /// navigation bar. | ||
| GoRoute( | ||
| parentNavigatorKey: _sectionBNavigatorKey, | ||
| path: '/b', | ||
| builder: (BuildContext context, GoRouterState state) => | ||
| const RootScreen( | ||
| label: 'B', | ||
| detailsPath: '/b/details/1', | ||
| detailsPath2: '/b/details/2'), | ||
| routes: <RouteBase>[ | ||
| /// The details screen to display stacked on navigator of the | ||
| /// second tab. This will cover screen B but not the application | ||
| /// shell (bottom navigation bar). | ||
| GoRoute( | ||
| path: 'details/:param', | ||
| builder: (BuildContext context, GoRouterState state) => | ||
| DetailsScreen(label: 'B', param: state.params['param']), | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| ), | ||
| ], | ||
| ); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return MaterialApp.router( | ||
| title: 'Flutter Demo', | ||
| theme: ThemeData( | ||
| primarySwatch: Colors.blue, | ||
| ), | ||
| routerConfig: _router, | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// Representation of a tab item in a [ScaffoldWithNavBar] | ||
| class ScaffoldWithNavBarTabItem extends BottomNavigationBarItem { | ||
| /// Constructs an [ScaffoldWithNavBarTabItem]. | ||
| const ScaffoldWithNavBarTabItem( | ||
| {required this.navigationItem, required Widget icon, String? label}) | ||
| : super(icon: icon, label: label); | ||
|
|
||
| /// The [StackedNavigationItem] | ||
| final StackedNavigationItem navigationItem; | ||
|
|
||
| /// Gets the associated navigator key | ||
| GlobalKey<NavigatorState> get navigatorKey => navigationItem.navigatorKey; | ||
| } | ||
|
|
||
| /// Builds the "shell" for the app by building a Scaffold with a | ||
| /// BottomNavigationBar, where [child] is placed in the body of the Scaffold. | ||
| class ScaffoldWithNavBar extends StatelessWidget { | ||
| /// Constructs an [ScaffoldWithNavBar]. | ||
| const ScaffoldWithNavBar({ | ||
| required this.currentIndex, | ||
| required this.itemsState, | ||
| required this.body, | ||
| required this.tabs, | ||
| Key? key, | ||
| }) : super(key: key ?? const ValueKey<String>('ScaffoldWithNavBar')); | ||
|
|
||
| /// Currently active tab index | ||
| final int currentIndex; | ||
|
|
||
| /// Route state | ||
| final List<StackedNavigationItemState> itemsState; | ||
|
|
||
| /// Body, i.e. the index stack | ||
| final Widget body; | ||
|
|
||
| /// The tabs | ||
| final List<ScaffoldWithNavBarTabItem> tabs; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| body: body, | ||
| bottomNavigationBar: BottomNavigationBar( | ||
| items: tabs, | ||
| currentIndex: currentIndex, | ||
| onTap: (int tappedIndex) => | ||
| _onItemTapped(context, itemsState[tappedIndex]), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| void _onItemTapped( | ||
| BuildContext context, StackedNavigationItemState itemState) { | ||
| GoRouter.of(context).go(itemState.currentLocation); | ||
| } | ||
| } | ||
tolo marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// Widget for the root/initial pages in the bottom navigation bar. | ||
| class RootScreen extends StatelessWidget { | ||
| /// Creates a RootScreen | ||
| const RootScreen( | ||
| {required this.label, | ||
| required this.detailsPath, | ||
| this.detailsPath2, | ||
| Key? key}) | ||
| : super(key: key); | ||
|
|
||
| /// The label | ||
| final String label; | ||
|
|
||
| /// The path to the detail page | ||
| final String detailsPath; | ||
|
|
||
| /// The path to another detail page | ||
| final String? detailsPath2; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: Text('Tab root - $label'), | ||
| ), | ||
| body: Center( | ||
| child: Column( | ||
| mainAxisSize: MainAxisSize.min, | ||
| children: <Widget>[ | ||
| Text('Screen $label', | ||
| style: Theme.of(context).textTheme.titleLarge), | ||
| const Padding(padding: EdgeInsets.all(4)), | ||
| TextButton( | ||
| onPressed: () { | ||
| GoRouter.of(context).go(detailsPath); | ||
| }, | ||
| child: const Text('View details'), | ||
| ), | ||
| const Padding(padding: EdgeInsets.all(4)), | ||
| if (detailsPath2 != null) | ||
| TextButton( | ||
| onPressed: () { | ||
| GoRouter.of(context).go(detailsPath2!); | ||
| }, | ||
| child: const Text('View more details'), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| /// The details screen for either the A or B screen. | ||
| class DetailsScreen extends StatefulWidget { | ||
| /// Constructs a [DetailsScreen]. | ||
| const DetailsScreen({ | ||
| required this.label, | ||
| this.param, | ||
| Key? key, | ||
| }) : super(key: key); | ||
|
|
||
| /// The label to display in the center of the screen. | ||
| final String label; | ||
|
|
||
| /// Optional param | ||
| final String? param; | ||
|
|
||
| @override | ||
| State<StatefulWidget> createState() => DetailsScreenState(); | ||
| } | ||
|
|
||
| /// The state for DetailsScreen | ||
| class DetailsScreenState extends State<DetailsScreen> { | ||
| int _counter = 0; | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| return Scaffold( | ||
| appBar: AppBar( | ||
| title: Text('Details Screen - ${widget.label}'), | ||
| ), | ||
| body: Center( | ||
| child: Column( | ||
| mainAxisSize: MainAxisSize.min, | ||
| children: <Widget>[ | ||
| if (widget.param != null) | ||
| Text('Parameter: ${widget.param!}', | ||
| style: Theme.of(context).textTheme.titleLarge), | ||
| const Padding(padding: EdgeInsets.all(4)), | ||
| Text('Details for ${widget.label} - Counter: $_counter', | ||
| style: Theme.of(context).textTheme.titleLarge), | ||
| const Padding(padding: EdgeInsets.all(4)), | ||
| TextButton( | ||
| onPressed: () { | ||
| setState(() { | ||
| _counter++; | ||
| }); | ||
| }, | ||
| child: const Text('Increment counter'), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or 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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.