forked from man-want-fly/do_you_want_to_learn_flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
217 additions
and
2 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
lib/animation/implicitly/implicitly_animated_cross_fade.dart
This file contains 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,108 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class ImplicitlyAnimatedCrossFade extends StatefulWidget { | ||
final String title; | ||
|
||
ImplicitlyAnimatedCrossFade({Key? key, required this.title}) | ||
: super(key: key); | ||
|
||
@override | ||
State<StatefulWidget> createState() { | ||
return _ImplicitlyAnimatedCrossFadeState(); | ||
} | ||
} | ||
|
||
class _ImplicitlyAnimatedCrossFadeState | ||
extends State<ImplicitlyAnimatedCrossFade> { | ||
bool _showFirst = true; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text(widget.title), | ||
), | ||
body: Container( | ||
padding: EdgeInsets.all(16), | ||
child: Column( | ||
children: [ | ||
Container( | ||
height: 60, | ||
decoration: BoxDecoration( | ||
color: Colors.red, borderRadius: BorderRadius.circular(20)), | ||
), | ||
SizedBox( | ||
height: 20, | ||
), | ||
AnimatedCrossFade( | ||
duration: Duration(seconds: 1), | ||
crossFadeState: _showFirst | ||
? CrossFadeState.showFirst | ||
: CrossFadeState.showSecond, | ||
firstChild: Container( | ||
height: 150, | ||
width: 150, | ||
alignment: Alignment.center, | ||
decoration: BoxDecoration( | ||
shape: BoxShape.circle, | ||
color: Colors.blue, | ||
), | ||
child: Text( | ||
'first child', | ||
style: TextStyle(color: Colors.white), | ||
), | ||
), | ||
secondChild: Container( | ||
height: 60, | ||
alignment: Alignment.center, | ||
decoration: BoxDecoration( | ||
shape: BoxShape.rectangle, | ||
color: Colors.red, | ||
borderRadius: BorderRadius.circular(20)), | ||
child: Text( | ||
'second child', | ||
style: TextStyle(color: Colors.white), | ||
), | ||
), | ||
layoutBuilder: (Widget topChild, Key topChildKey, Widget bottomChild, Key bottomChildKey) { | ||
return Stack( | ||
alignment: Alignment.center, | ||
children: <Widget>[ | ||
Positioned( | ||
top: 0, | ||
bottom: 0, | ||
key: bottomChildKey, | ||
child: bottomChild, | ||
), | ||
Positioned( | ||
key: topChildKey, | ||
child: topChild, | ||
), | ||
], | ||
); | ||
}, | ||
), | ||
SizedBox( | ||
height: 20, | ||
), | ||
Container( | ||
height: 60, | ||
decoration: BoxDecoration( | ||
color: Colors.red, borderRadius: BorderRadius.circular(20)), | ||
), | ||
], | ||
), | ||
), | ||
floatingActionButton: FloatingActionButton( | ||
onPressed: () { | ||
setState(() { | ||
_showFirst = !_showFirst; | ||
}); | ||
}, | ||
child: Icon( | ||
_showFirst ? Icons.swipe_rounded : Icons.swipe_outlined | ||
), | ||
), | ||
); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
lib/animation/implicitly/implicitly_animated_default_text_style.dart
This file contains 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,98 @@ | ||
import 'dart:math'; | ||
|
||
import 'package:flutter/material.dart'; | ||
|
||
class ImplicitlyAnimatedDefaultTextStyle extends StatefulWidget { | ||
final String title; | ||
|
||
ImplicitlyAnimatedDefaultTextStyle({Key? key, required this.title}) | ||
: super(key: key); | ||
|
||
@override | ||
State<StatefulWidget> createState() { | ||
return _ImplicitlyAnimatedDefaultTextStyleState(); | ||
} | ||
} | ||
|
||
class _ImplicitlyAnimatedDefaultTextStyleState | ||
extends State<ImplicitlyAnimatedDefaultTextStyle> | ||
with SingleTickerProviderStateMixin { | ||
late AnimationController _animationController; | ||
late Animation<TextStyle> _animation; | ||
|
||
late TextStyle _style; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
|
||
_style = TextStyle( | ||
color: Colors.blue, | ||
fontSize: 14, | ||
); | ||
|
||
_animationController = | ||
AnimationController(duration: Duration(seconds: 2), vsync: this); | ||
|
||
_animation = TextStyleTween( | ||
begin: TextStyle(color: Colors.blue, fontSize: 14), | ||
end: TextStyle(color: Colors.red, fontSize: 24)) | ||
.animate(_animationController); | ||
|
||
_animationController.forward(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text(widget.title), | ||
), | ||
body: Container( | ||
padding: EdgeInsets.all(16), | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.start, | ||
mainAxisSize: MainAxisSize.max, | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
DefaultTextStyle( | ||
style: _style, | ||
overflow: TextOverflow.ellipsis, | ||
child: Text("DefaultTextStyle"), | ||
), | ||
SizedBox( | ||
height: 20, | ||
), | ||
DefaultTextStyleTransition( | ||
style: _animation, | ||
child: Text("DefaultTextStyleTransition"), | ||
), | ||
SizedBox( | ||
height: 20, | ||
), | ||
AnimatedDefaultTextStyle( | ||
duration: Duration(seconds: 1), | ||
style: _style, | ||
child: Text("AnimatedDefaultTextStyle"), | ||
), | ||
SizedBox( | ||
height: 20, | ||
), | ||
ElevatedButton( | ||
onPressed: () { | ||
setState(() { | ||
_style = TextStyle( | ||
color: Colors | ||
.primaries[Random().nextInt(Colors.primaries.length)], | ||
fontSize: (Random().nextDouble() * 20 + 10), | ||
); | ||
}); | ||
}, | ||
child: Text("change style"), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains 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 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