Improve group manage page animation.
This commit is contained in:
parent
29f989e384
commit
74468bf35c
|
@ -35,29 +35,26 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
Animation _menuAnimation;
|
||||
double _fraction;
|
||||
int _index;
|
||||
double _scroll;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_showSetting = false;
|
||||
_fraction = 0;
|
||||
_menuValue = 0;
|
||||
_scroll = 0;
|
||||
_index = 0;
|
||||
_menuController = AnimationController(
|
||||
duration: const Duration(milliseconds: 300), vsync: this);
|
||||
duration: const Duration(milliseconds: 150), vsync: this);
|
||||
_controller = AnimationController(
|
||||
duration: const Duration(milliseconds: 500), vsync: this);
|
||||
_animation = Tween(begin: 0.0, end: 1.0).animate(_controller)
|
||||
..addListener(() {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_fraction = _animation.value;
|
||||
});
|
||||
setState(() => _fraction = _animation.value);
|
||||
}
|
||||
});
|
||||
_menuAnimation = Tween(begin: 0.0, end: 1.0)
|
||||
.animate(CurvedAnimation(parent: _menuController, curve: Curves.easeIn))
|
||||
_menuAnimation = Tween(begin: 0.0, end: 1.0).animate(
|
||||
CurvedAnimation(parent: _menuController, curve: Curves.elasticInOut))
|
||||
..addListener(() {
|
||||
if (mounted) setState(() => _menuValue = _menuAnimation.value);
|
||||
});
|
||||
|
@ -89,7 +86,7 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
Widget _saveButton(BuildContext context) {
|
||||
Widget _saveButton() {
|
||||
final s = context.s;
|
||||
return Consumer<GroupList>(
|
||||
builder: (_, groupList, __) {
|
||||
|
@ -138,8 +135,27 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
child: Transform(
|
||||
alignment: FractionalOffset(0.5, 0.5),
|
||||
transform: Matrix4.rotationY(math.pi * _fraction),
|
||||
child: Container(
|
||||
child: InkWell(
|
||||
onTap: () async {
|
||||
if (_fraction == 0) {
|
||||
!_showSetting
|
||||
? _menuController.forward()
|
||||
: await _menuController.reverse();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_showSetting = !_showSetting;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
groupList.saveOrder(groupList.groups[_index]);
|
||||
groupList.drlFromOrderChanged(groupList.groups[_index].name);
|
||||
Fluttertoast.showToast(
|
||||
msg: context.s.toastSettingSaved,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
);
|
||||
_controller.reverse();
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
|
@ -165,26 +181,6 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
),
|
||||
// color: Colors.white,
|
||||
),
|
||||
onTap: () async {
|
||||
if (_fraction == 0) {
|
||||
!_showSetting
|
||||
? _menuController.forward()
|
||||
: await _menuController.reverse();
|
||||
setState(() {
|
||||
_showSetting = !_showSetting;
|
||||
});
|
||||
} else {
|
||||
groupList.saveOrder(groupList.groups[_index]);
|
||||
groupList
|
||||
.drlFromOrderChanged(groupList.groups[_index].name);
|
||||
Fluttertoast.showToast(
|
||||
msg: context.s.toastSettingSaved,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
);
|
||||
_controller.reverse();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
@ -192,6 +188,7 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = context.s;
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
|
@ -253,7 +250,7 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
AddGroup()),
|
||||
icon: Icon(Icons.add)),
|
||||
),
|
||||
OrderMenu(),
|
||||
_OrderMenu(),
|
||||
],
|
||||
),
|
||||
body: WillPopScope(
|
||||
|
@ -262,7 +259,8 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
.clearOrderChanged();
|
||||
return true;
|
||||
},
|
||||
child: Consumer<GroupList>(builder: (_, groupList, __) {
|
||||
child: Consumer<GroupList>(
|
||||
builder: (_, groupList, __) {
|
||||
var _isLoading = groupList.isLoading;
|
||||
var _groups = groupList.groups;
|
||||
return _isLoading
|
||||
|
@ -276,15 +274,12 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
tabBuilder: (context, index) => Tab(
|
||||
child: Container(
|
||||
height: 30.0,
|
||||
padding: EdgeInsets.symmetric(horizontal: 10.0),
|
||||
padding:
|
||||
EdgeInsets.symmetric(horizontal: 10.0),
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: (_scroll - index).abs() > 1
|
||||
? Colors.grey[300]
|
||||
: Colors.grey[300]
|
||||
.withOpacity((_scroll - index).abs()),
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.circular(15)),
|
||||
color: Colors.grey[600].withOpacity(0.3),
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
),
|
||||
child: Text(
|
||||
_groups[index].name,
|
||||
|
@ -307,9 +302,7 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
color: Colors.cyan[500],
|
||||
padding: const EdgeInsets.all(0),
|
||||
child: Text(context.s.understood,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.button
|
||||
style: context.textTheme.button
|
||||
.copyWith(color: Colors.white)),
|
||||
onPressed: () async =>
|
||||
FeatureDiscovery.completeCurrentStep(
|
||||
|
@ -319,9 +312,7 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
color: Colors.cyan[500],
|
||||
padding: const EdgeInsets.all(0),
|
||||
child: Text(context.s.dismiss,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.button
|
||||
style: context.textTheme.button
|
||||
.copyWith(color: Colors.white)),
|
||||
onPressed: () =>
|
||||
FeatureDiscovery.dismissAll(context),
|
||||
|
@ -329,41 +320,42 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
],
|
||||
),
|
||||
child: Container(
|
||||
key: ValueKey(_groups[index].name),
|
||||
child: PodcastGroupList(group: _groups[index])),
|
||||
key: ValueKey<String>(_groups[index].name),
|
||||
child:
|
||||
PodcastGroupList(group: _groups[index])),
|
||||
),
|
||||
onPositionChange: (value) =>
|
||||
setState(() => _index = value),
|
||||
onScroll: (value) => setState(() => _scroll = value),
|
||||
// setState(() =>
|
||||
_index = value,
|
||||
),
|
||||
),
|
||||
_showSetting
|
||||
? Positioned.fill(
|
||||
if (_showSetting)
|
||||
Positioned.fill(
|
||||
top: 50,
|
||||
child: GestureDetector(
|
||||
onTap: () async {
|
||||
await _menuController.reverse();
|
||||
if (mounted) {
|
||||
setState(() => _showSetting = false);
|
||||
}
|
||||
},
|
||||
child: Container(
|
||||
color: Theme.of(context)
|
||||
.scaffoldBackgroundColor
|
||||
.withOpacity(0.5 * _menuController.value),
|
||||
color: context.scaffoldBackgroundColor
|
||||
.withOpacity(0.8 *
|
||||
math.min(
|
||||
_menuController.value * 2, 1.0)),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Center(),
|
||||
Positioned(
|
||||
right: 30,
|
||||
bottom: 30,
|
||||
child: _saveButton(context),
|
||||
child: _saveButton(),
|
||||
),
|
||||
_showSetting
|
||||
? Positioned(
|
||||
right: 30 * _menuValue,
|
||||
if (_showSetting)
|
||||
Positioned(
|
||||
right: 100 * _menuValue - 70,
|
||||
bottom: 100,
|
||||
child: Container(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
|
@ -376,8 +368,7 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
setState(() => _showSetting = false);
|
||||
_index == 0
|
||||
? Fluttertoast.showToast(
|
||||
msg: s
|
||||
.toastHomeGroupNotSupport,
|
||||
msg: s.toastHomeGroupNotSupport,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
)
|
||||
: showGeneralDialog(
|
||||
|
@ -391,8 +382,7 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
transitionDuration:
|
||||
const Duration(
|
||||
milliseconds: 300),
|
||||
pageBuilder: (context,
|
||||
animaiton,
|
||||
pageBuilder: (context, animaiton,
|
||||
secondaryAnimation) =>
|
||||
RenameGroup(
|
||||
group: _groups[_index],
|
||||
|
@ -402,10 +392,10 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
height: 30.0,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[700],
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10.0))),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 10),
|
||||
borderRadius:
|
||||
BorderRadius.circular(10.0)),
|
||||
padding:
|
||||
EdgeInsets.symmetric(horizontal: 10),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
|
@ -426,8 +416,8 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 10.0)),
|
||||
padding:
|
||||
EdgeInsets.symmetric(vertical: 10.0)),
|
||||
Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
|
@ -436,15 +426,14 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
setState(() => _showSetting = false);
|
||||
_index == 0
|
||||
? Fluttertoast.showToast(
|
||||
msg: s
|
||||
.toastHomeGroupNotSupport,
|
||||
msg: s.toastHomeGroupNotSupport,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
)
|
||||
: generalDialog(
|
||||
context,
|
||||
title: Text(s.removeConfirm),
|
||||
content: Text(
|
||||
s.groupRemoveConfirm),
|
||||
content:
|
||||
Text(s.groupRemoveConfirm),
|
||||
actions: <Widget>[
|
||||
FlatButton(
|
||||
splashColor: context
|
||||
|
@ -456,8 +445,8 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
child: Text(
|
||||
context.s.cancel,
|
||||
style: TextStyle(
|
||||
color: Colors
|
||||
.grey[600]),
|
||||
color:
|
||||
Colors.grey[600]),
|
||||
),
|
||||
),
|
||||
FlatButton(
|
||||
|
@ -466,22 +455,19 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
.withAlpha(70),
|
||||
onPressed: () {
|
||||
if (_index ==
|
||||
groupList.groups
|
||||
.length -
|
||||
groupList
|
||||
.groups.length -
|
||||
1) {
|
||||
setState(() {
|
||||
_index = _index - 1;
|
||||
_scroll = 0;
|
||||
});
|
||||
groupList.delGroup(
|
||||
_groups[
|
||||
_index + 1]);
|
||||
_groups[_index + 1]);
|
||||
} else {
|
||||
groupList.delGroup(
|
||||
_groups[_index]);
|
||||
}
|
||||
Navigator.of(context)
|
||||
.pop();
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(
|
||||
context.s.confirm,
|
||||
|
@ -498,8 +484,8 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
color: Colors.grey[700],
|
||||
borderRadius: BorderRadius.all(
|
||||
Radius.circular(10.0))),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 10),
|
||||
padding:
|
||||
EdgeInsets.symmetric(horizontal: 10),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
|
@ -512,8 +498,8 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
horizontal: 5.0),
|
||||
),
|
||||
Text(s.remove,
|
||||
style: TextStyle(
|
||||
color: Colors.red)),
|
||||
style:
|
||||
TextStyle(color: Colors.red)),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -522,18 +508,17 @@ class _PodcastManageState extends State<PodcastManage>
|
|||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: Center(),
|
||||
],
|
||||
);
|
||||
}),
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class OrderMenu extends StatelessWidget {
|
||||
class _OrderMenu extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final s = context.s;
|
||||
|
|
Loading…
Reference in New Issue