-
Notifications
You must be signed in to change notification settings - Fork 65
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
Add SliverSizeTransition #94
Comments
@akshdeep-singh Perhaps you are looking for my SliverAnimatedPaintExtent ? |
My use case is to hide/show sliver list like this: sliver: show ? SliverList() : null I will try with |
@Kavantix
I was actually looking for something to use in |
|
I missed the curve option. Method 1: neither expand nor collapse animation works as intended import 'package:flutter/material.dart';
import 'package:sliver_tools/sliver_tools.dart';
void main() {
runApp(_TestApp());
}
class _TestApp extends StatefulWidget {
@override
State<StatefulWidget> createState() => _State();
}
class _State extends State<_TestApp> {
var _expanded = false;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: Switch(
value: _expanded,
onChanged: (value) {
setState(() {
_expanded = value;
});
},
),
),
AnimatedSwitcher(
duration: const Duration(seconds: 1),
layoutBuilder: SliverAnimatedSwitcher.defaultLayoutBuilder,
transitionBuilder: (child, animation) {
return SliverFadeTransition(
opacity: animation,
sliver: SliverAnimatedPaintExtent(
duration: const Duration(seconds: 1),
curve: Curves.easeInOut,
child: child,
),
);
},
child: _expanded
? SliverList.builder(
itemCount: 10,
itemBuilder: (context, index) {
return Container(
height: 40,
color: Colors.red,
padding: const EdgeInsets.all(10),
child: Text('$index'),
);
},
)
: const SliverToBoxAdapter(),
),
SliverToBoxAdapter(
child: Container(
height: 40,
color: Colors.green,
padding: const EdgeInsets.all(10),
child: const Text('**'),
),
)
],
),
),
),
);
}
} Method 2: expand animation works, but collapse animation is not as intended import 'package:flutter/material.dart';
import 'package:sliver_tools/sliver_tools.dart';
void main() {
runApp(_TestApp());
}
class _TestApp extends StatefulWidget {
@override
State<StatefulWidget> createState() => _State();
}
class _State extends State<_TestApp> {
var _expanded = false;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: Switch(
value: _expanded,
onChanged: (value) {
setState(() {
_expanded = value;
});
},
),
),
SliverAnimatedPaintExtent(
duration: const Duration(seconds: 1),
curve: Curves.easeInOut,
child: SliverAnimatedSwitcher(
duration: const Duration(seconds: 1),
child: _expanded
? SliverList.builder(
itemCount: 10,
itemBuilder: (context, index) {
return Container(
height: 40,
color: Colors.red,
padding: const EdgeInsets.all(10),
child: Text('$index'),
);
},
)
: const SliverToBoxAdapter(),
),
),
SliverToBoxAdapter(
child: Container(
height: 40,
color: Colors.green,
padding: const EdgeInsets.all(10),
child: const Text('**'),
),
)
],
),
),
),
);
}
} |
I see it seems you need more control to get the effect you are looking for, I would be open for a PR with tests for a SliverPaintExtentTransition. I believe the basis for it could be the SliverAnimatedPaintExtent |
To animate sliver sizes, for example when using
SliverAnimatedSwitcher
, flutter providesSliverFadeTransition
but there is nothing for animating sizes.The text was updated successfully, but these errors were encountered: