From 2e5582800a7fdbe0a3a1df39ac686288f4c24b07 Mon Sep 17 00:00:00 2001 From: toly <1981462002@qq.com> Date: Thu, 17 Jun 2021 11:11:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20SlideTransition=20?= =?UTF-8?q?=E6=A1=88=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SlideTransition/node1_base.dart | 43 +++++++++++++------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/lib/views/widgets/StatefulWidget/SlideTransition/node1_base.dart b/lib/views/widgets/StatefulWidget/SlideTransition/node1_base.dart index 3d55abb..1828987 100644 --- a/lib/views/widgets/StatefulWidget/SlideTransition/node1_base.dart +++ b/lib/views/widgets/StatefulWidget/SlideTransition/node1_base.dart @@ -5,7 +5,7 @@ import 'package:flutter/material.dart'; /// 说明: // { // "widgetId": 112, -// "name": 'SlideTransition基本使用', +// "name": 'SlideTransition 基本使用', // "priority": 1, // "subtitle": // "【child】 : 孩子组件 【Widget】\n" @@ -20,12 +20,20 @@ class CustomSlideTransition extends StatefulWidget { class _CustomSlideTransitionState extends State with SingleTickerProviderStateMixin { AnimationController _ctrl; + Animation animation; @override void initState() { - _ctrl = AnimationController(vsync: this, duration: Duration(seconds: 1)); - _ctrl.forward(); super.initState(); + _ctrl = AnimationController( + vsync: this, + duration: const Duration(seconds: 2), + )..forward(); + + animation = Tween( + begin: Offset.zero, + end: Offset(0.5, 0.5), + ).animate(_ctrl); } @override @@ -39,18 +47,29 @@ class _CustomSlideTransitionState extends State return GestureDetector( onTap: () => _ctrl.forward(from: 0), child: Container( - width: MediaQuery.of(context).size.width, + width: 200, color: Colors.grey.withAlpha(33), height: 100, - child: SlideTransition( - textDirection: TextDirection.ltr, - position: Tween( - begin: Offset.zero, - end: Offset(0.2, 0.2), - ).animate(_ctrl), - child: Container( - child: Icon(Icons.android, color: Colors.green, size: 60)), + child: Stack( + fit: StackFit.expand, + children: [ + SlideTransition( + textDirection: TextDirection.ltr, + position: animation, + child: _buildChild(), + ), + SlideTransition( + textDirection: TextDirection.rtl, + position: animation, + child: _buildChild(), + ), + ], ), )); } + Widget _buildChild() => const Icon( + Icons.accessible_forward_sharp, + color: Colors.green, + size: 25, + ); }