Skip to content

Commit

Permalink
Fix cupertino sample
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpryan committed Apr 11, 2022
1 parent 221c948 commit 956be1c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions example/lib/cupertino.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final _router = TreeRouter(
builder: (context) => const HomeScreen(),
routes: [
StackedRoute(
path: 'details',
path: 'details/:id',
builder: (context) => const DetailsScreen(),
),
],
Expand All @@ -43,7 +43,7 @@ final _router = TreeRouter(
builder: (context) => const ChatScreen(),
routes: [
StackedRoute(
path: 'details',
path: 'details/:id',
builder: (context) => const DetailsScreen(),
),
],
Expand All @@ -53,7 +53,7 @@ final _router = TreeRouter(
builder: (context) => const ProfileScreen(),
routes: [
StackedRoute(
path: 'details',
path: 'details/:id',
builder: (context) => const DetailsScreen(),
),
],
Expand All @@ -67,9 +67,10 @@ int _selectedIndex(BuildContext context) {
final route = RouteState.of(context)!;
final activeChild = route.activeChild;
if (activeChild != null) {
print('activeChild.path = ${activeChild.path}');
if (activeChild.path == 'home') return 0;
if (activeChild.path == 'chat') return 1;
if (activeChild.path == 'profile') return 1;
if (activeChild.path == 'profile') return 2;
}
return 0;
}
Expand Down Expand Up @@ -177,7 +178,7 @@ class HomeScreen extends StatelessWidget {
),
CupertinoButton(
onPressed: () {
RouteState.of(context)!.goTo('details');
RouteState.of(context)!.goTo('details/10');
},
child: const Text('Show a new screen'),
),
Expand Down Expand Up @@ -207,7 +208,7 @@ class ChatScreen extends StatelessWidget {
),
CupertinoButton(
onPressed: () {
RouteState.of(context)!.goTo('details');
RouteState.of(context)!.goTo('details/42');
},
child: const Text('Show a new screen'),
),
Expand Down Expand Up @@ -237,7 +238,7 @@ class ProfileScreen extends StatelessWidget {
),
CupertinoButton(
onPressed: () {
RouteState.of(context)!.goTo('details');
RouteState.of(context)!.goTo('details/100');
},
child: const Text('Show a new screen'),
),
Expand Down Expand Up @@ -292,13 +293,14 @@ class _DetailsScreenState extends State<DetailsScreen> with RestorationMixin {

@override
Widget build(BuildContext context) {
final id = int.tryParse(RouteState.of(context)?.pathParameters['id'] ?? '');
return UnmanagedRestorationScope(
bucket: bucket,
child: CupertinoPageScaffold(
navigationBar: const CupertinoNavigationBar(),
child: Center(
child: Text(
'Item ${widget.id}',
'Item $id',
style: CupertinoTheme.of(context).textTheme.navLargeTitleTextStyle,
),
),
Expand Down

0 comments on commit 956be1c

Please sign in to comment.