正常に動作するContainer
をAnimatedBuilder
で囲うと非表示になってしまいます。
-(アニメーションのあるRaisedButton
を表示させる予定)
-エラーはないです。
解決策を教えて頂けると嬉しいです。
ButtonAnimation.dart
1 @override 2 Widget build(BuildContext context) { 3 return AnimatedBuilder( <------------------AnimatedBuilderで囲うと、Containerが表示されない???? 4 animation: _scaleAnimationController, 5 builder: (context, child) => Transform.scale( 6 scale: _scaleAnimation.value, 7 ), 8 child: Container( <------------------Containerのみだと正常に表示 9 margin: EdgeInsets.only(bottom: 20), 10 child: Center( 11 child: RaisedButton( 12 onPressed: () { 13 _scaleAnimationController.forward(); 14 }, 15 padding: EdgeInsets.zero, 16 color: widget.primaryColor, 17 splashColor: widget.primaryColor, 18 highlightColor: widget.primaryColor, 19 child: Container( 20 width: 200, 21 height: 50, 22 child: Row( 23 children: [ 24 Expanded( 25 flex: 3, 26 child: Center( 27 child: Text( 28 'Download', 29 style: TextStyle(color: Colors.white, fontSize: 16), 30 ), 31 ), 32 ), 33 Expanded( 34 flex: 1, 35 child: Container( 36 decoration: BoxDecoration( 37 color: widget.darkPrimaryColor, 38 borderRadius: BorderRadius.only( 39 bottomRight: Radius.circular(4), 40 topRight: Radius.circular(4), 41 )), 42 child: Center( 43 child: Icon( 44 Icons.arrow_downward, 45 color: Colors.white, 46 )), 47 ), 48 ), 49 ], 50 ), 51 ), 52 ), 53 ), 54 ), 55 ); 56 }
????以下、home.dart
, ButtonAnimation.dart
の全文を掲載します。
ご検証にお使いくださいませ。
-home.dart
からButtonAnimationクラスを呼んでいます。
home
1import 'package:flutter/material.dart'; 2import 'ButtonAnimation.dart'; 3 4class HomePage extends StatelessWidget { 5 @override 6 Widget build(BuildContext context) { 7 return Scaffold( 8 body: Column( 9 mainAxisAlignment: MainAxisAlignment.center, 10 children: [ 11 ButtonAnimation( 12 primaryColor: Colors.indigo, 13 darkPrimaryColor: Colors.indigo[900], 14 ), 15 ButtonAnimation( 16 primaryColor: Colors.orange, 17 darkPrimaryColor: Colors.orange[900], 18 ), 19 ButtonAnimation( 20 primaryColor: Colors.green, 21 darkPrimaryColor: Colors.green[900], 22 ), 23 ButtonAnimation( 24 primaryColor: Colors.red, 25 darkPrimaryColor: Colors.red[900], 26 ), 27 ], 28 ), 29 ); 30 } 31} 32
ButtonAnimation
1import 'package:flutter/material.dart'; 2 3class ButtonAnimation extends StatefulWidget { 4 final Color primaryColor; 5 final Color darkPrimaryColor; 6 7 const ButtonAnimation({Key key, this.primaryColor, this.darkPrimaryColor}) 8 : super(key: key); 9 10 @override 11 _ButtonAnimationState createState() => _ButtonAnimationState(); 12} 13 14class _ButtonAnimationState extends State<ButtonAnimation> 15 with TickerProviderStateMixin { 16 AnimationController _animationController; 17 AnimationController _scaleAnimationController; 18 AnimationController _fadeAnimationController; 19 20 Animation<double> _animation; 21 Animation<double> _scaleAnimation; 22 Animation<double> _fadeAnimation; 23 24 double buttonWidth = 200; 25 double scale = 1.0; 26 double barColorOpacity = 0.6; 27 bool animationComplete = false; 28 bool animationStart = false; 29 30 @override 31 void initState() { 32 _animationController = 33 AnimationController(vsync: this, duration: Duration(seconds: 3)); 34 _scaleAnimationController = 35 AnimationController(vsync: this, duration: Duration(milliseconds: 300)); 36 _fadeAnimationController = 37 AnimationController(vsync: this, duration: Duration(milliseconds: 400)); 38 39 _animation = Tween<double>(begin: 0, end: buttonWidth) 40 .animate(_animationController) 41 ..addStatusListener((status) {}); 42 43 _scaleAnimation = Tween<double>(begin: 1, end: 1.5) 44 .animate(_fadeAnimationController) 45 ..addStatusListener((status) {}); 46 47 _fadeAnimation = 48 Tween<double>(begin: 50, end: 0).animate(_fadeAnimationController); 49 50 super.initState(); 51 } 52 53 @override 54 void dispose() { 55 _animationController.dispose(); 56 _scaleAnimationController.dispose(); 57 _fadeAnimationController.dispose(); 58 super.dispose(); 59 } 60 61 @override 62 Widget build(BuildContext context) { 63 return AnimatedBuilder( 64 animation: _scaleAnimationController, 65 builder: (context, child) => Transform.scale( 66 scale: _scaleAnimation.value, 67 ), 68 child: Container( 69 margin: EdgeInsets.only(bottom: 20), 70 child: Center( 71 child: RaisedButton( 72 onPressed: () { 73 _scaleAnimationController.forward(); 74 }, 75 padding: EdgeInsets.zero, 76 color: widget.primaryColor, 77 splashColor: widget.primaryColor, 78 highlightColor: widget.primaryColor, 79 child: Container( 80 width: 200, 81 height: 50, 82 child: Row( 83 children: [ 84 Expanded( 85 flex: 3, 86 child: Center( 87 child: Text( 88 'Download', 89 style: TextStyle(color: Colors.white, fontSize: 16), 90 ), 91 ), 92 ), 93 Expanded( 94 flex: 1, 95 child: Container( 96 decoration: BoxDecoration( 97 color: widget.darkPrimaryColor, 98 borderRadius: BorderRadius.only( 99 bottomRight: Radius.circular(4), 100 topRight: Radius.circular(4), 101 )), 102 child: Center( 103 child: Icon( 104 Icons.arrow_downward, 105 color: Colors.white, 106 )), 107 ), 108 ), 109 ], 110 ), 111 ), 112 ), 113 ), 114 ), 115 ); 116 } 117} 118
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/07/24 04:36