-
Notifications
You must be signed in to change notification settings - Fork 14
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
context.replace
does not animate the extent of NavigationSheet
#188
Comments
Hi @samuelkubinsky, I recommend specifying a key for each pageBuilder: (context, state) {
return ScrollableNavigationSheetPage(
key: state.pageKey, // <-- this |
Thanks that helped. I don't think this question belong here but I didn't find an answer anywhere. How can i get rid of "push" animation when replacing a route? |
You can create custom transition animations by specifying a custom transition builder to |
Ok, my bad. Using default APIs Codeimport 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:smooth_sheets/smooth_sheets.dart';
void main() {
runApp(MyApp());
}
final transitionObserver = NavigationSheetTransitionObserver();
class MyApp extends StatelessWidget {
MyApp({super.key});
final router = GoRouter(
initialLocation: "/blue",
routes: [
ShellRoute(
observers: [transitionObserver],
builder: (context, state, child) {
return NavigationSheet(
transitionObserver: transitionObserver,
child: Material(
color: Theme.of(context).colorScheme.primary,
borderRadius: BorderRadius.circular(16),
clipBehavior: Clip.antiAlias,
child: child,
),
);
},
routes: [
GoRoute(
path: "/blue",
pageBuilder: (context, state) {
return ScrollableNavigationSheetPage(
key: state.pageKey,
initialExtent: const Extent.proportional(0.5),
minExtent: const Extent.proportional(0.5),
maxExtent: const Extent.proportional(0.5),
child: PageBlue(),
);
},
),
GoRoute(
path: "/red",
pageBuilder: (context, state) {
return ScrollableNavigationSheetPage(
key: state.pageKey,
initialExtent: const Extent.proportional(0.9),
minExtent: const Extent.proportional(0.9),
maxExtent: const Extent.proportional(0.9),
child: PageRed(),
);
},
),
])
],
);
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: router,
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
);
}
}
class PageBlue extends StatelessWidget {
final List<String> items = List<String>.generate(20, (index) => "Item ${index + 1}");
PageBlue({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('SmoothSheets Replace'),
backgroundColor: Colors.blue,
),
body: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
return InkWell(
onTap: () {
context.replace("/red");
},
child: ListTile(
title: Text(items[index]),
),
);
},
),
);
}
}
class PageRed extends StatelessWidget {
final List<String> items = List<String>.generate(20, (index) => "Item ${index + 1}");
PageRed({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('SmoothSheets Replace'),
backgroundColor: Colors.red,
),
body: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
return InkWell(
onTap: () {
context.replace("/blue");
},
child: ListTile(
title: Text(items[index]),
),
);
},
),
);
}
}
|
Thanks for the tip. I tried some animations and I got them to work but I ultimately lost pop by user gesture. Wouldn't it be better if this library used default animations? So out of the box it behaves as you would expect and if you want something custom, then you can tweak it to your liking. Screen.Recording.2024-07-06.at.23.15.42.mov |
Can you tell me the expected behavior? Also i want to know the code of your |
I'm not sure which comment are you referring to, so I'm going to describe both issues. 1.) On |
Oh, sorry. I replied to this (↑) comment.
You mean the expected behavior is that the sheet uses the native (material or cupertino) transition animation, while keeping the sheet height animation is also enabled? If so, the following custom transition builder could be a solution (not tested yet): // This is exactly the same implementation as MaterialPageRoute
final theme = Theme.of(context).pageTransitionsTheme;
return theme.buildTransitions<T>(ModalRoute.of(context) as PageRoute<dynamic>, context, animation, secondaryAnimation, child);
I agree with this idea. I can't remember why I didn't so :( |
Provided code works excellently, thanks! And I think this should be a default transition. So the only issue I'm having with this library is this one:
|
context.replace
does not animate the extent
To be fair, extent is animated but only sometimes - after some manual scrolling in a screen. Screen.Recording.2024-07-07.at.18.19.06.movCodeimport 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:smooth_sheets/smooth_sheets.dart';
void main() {
runApp(MyApp());
}
final transitionObserver = NavigationSheetTransitionObserver();
class MyApp extends StatelessWidget {
MyApp({super.key});
final router = GoRouter(
initialLocation: "/blue",
routes: [
ShellRoute(
observers: [transitionObserver],
builder: (context, state, child) {
return NavigationSheet(
transitionObserver: transitionObserver,
child: Material(
color: Theme.of(context).colorScheme.primary,
borderRadius: BorderRadius.circular(16),
clipBehavior: Clip.antiAlias,
child: child,
),
);
},
routes: [
GoRoute(
path: "/blue",
pageBuilder: (context, state) {
return ScrollableNavigationSheetPage(
key: state.pageKey,
initialExtent: const Extent.proportional(0.5),
minExtent: const Extent.proportional(0.5),
maxExtent: const Extent.proportional(0.5),
child: PageBlue(),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
final theme = Theme.of(context).pageTransitionsTheme;
final route = ModalRoute.of(context) as PageRoute<dynamic>;
return theme.buildTransitions(route, context, animation, secondaryAnimation, child);
},
);
},
),
GoRoute(
path: "/red",
pageBuilder: (context, state) {
return ScrollableNavigationSheetPage(
key: state.pageKey,
initialExtent: const Extent.proportional(0.9),
minExtent: const Extent.proportional(0.5),
maxExtent: const Extent.proportional(0.9),
child: PageRed(),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
final theme = Theme.of(context).pageTransitionsTheme;
final route = ModalRoute.of(context) as PageRoute<dynamic>;
return theme.buildTransitions(route, context, animation, secondaryAnimation, child);
},
);
},
),
])
],
);
@override
Widget build(BuildContext context) {
return MaterialApp.router(
routerConfig: router,
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
);
}
}
class PageBlue extends StatelessWidget {
final List<String> items = List<String>.generate(20, (index) => "Item ${index + 1}");
PageBlue({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Initial 0.5'),
backgroundColor: Colors.blue,
),
body: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
return InkWell(
onTap: () {
context.replace("/red");
},
child: ListTile(
title: Text(items[index]),
),
);
},
),
);
}
}
class PageRed extends StatelessWidget {
final List<String> items = List<String>.generate(20, (index) => "Item ${index + 1}");
PageRed({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Initial 0.9'),
backgroundColor: Colors.red,
),
body: ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
return InkWell(
onTap: () {
context.replace("/blue");
},
child: ListTile(
title: Text(items[index]),
),
);
},
),
);
}
} |
Can't we simply use |
I still think this could be fixed but I ultimately gave up on |
context.replace
does not animate the extentcontext.replace
does not animate the extent of NavigationSheet
I will keep this issue open as a bug report, not a question. |
So when using go and replace actions when navigating, two things happen:
Versions:
smooth_sheets: 0.8.1
go_router: 14.2.0
Screen.Recording.2024-07-05.at.22.31.00.mov
Blue screen has 1 proportional extent - 0.5
Red screen has 1 proportional extent - 0.9
Code
The text was updated successfully, but these errors were encountered: