Animation 在同一屏幕上设置多个窗口小部件的动画
我需要从左向右滑动动画,反之亦然 谁能给我一些指导,我应该在其中使用哪个小部件? 我试过一些方法,比如:- 我使用了类,但它没有给我预期的结果,我也尝试了不同的偏移范围/值,但没有运气Animation 在同一屏幕上设置多个窗口小部件的动画,animation,flutter,transition,slide,Animation,Flutter,Transition,Slide,我需要从左向右滑动动画,反之亦然 谁能给我一些指导,我应该在其中使用哪个小部件? 我试过一些方法,比如:- 我使用了类,但它没有给我预期的结果,我也尝试了不同的偏移范围/值,但没有运气 import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:sliding_up_panel/sliding_up_panel.dart'; class HomePage ext
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:sliding_up_panel/sliding_up_panel.dart';
class HomePage extends StatefulWidget {
const HomePage({Key key}) : super(key: key);
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
AnimationController _controller;
Animation<Offset> _offsetAnimation;
AnimationController _controllerTwo;
Animation<Offset> _offsetAnimationTwo;
@override
void initState() {
_controller = AnimationController(
duration: const Duration(seconds: 1),
vsync: this,
);
_offsetAnimation = Tween<Offset>(
begin: const Offset(-0.00001, 0.0),
end: const Offset(0.09, 0.0),
).animate(CurvedAnimation(
parent: _controller,
curve: Curves.easeInOut,
));
_controllerTwo = AnimationController(
duration: const Duration(seconds: 1),
vsync: this,
);
_offsetAnimationTwo = Tween<Offset>(
begin: const Offset(-0.85, 0.0),
end: const Offset(-0.00001, 0.0),
).animate(CurvedAnimation(
parent: _controllerTwo,
curve: Curves.easeInOut,
));
super.initState();
}
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
child: new GestureDetector(
onHorizontalDragUpdate: (details) {
if (details.primaryDelta > 0) {
_controller..reverse();
_controllerTwo..reverse();
}
if (details.primaryDelta < 0) {
_controller..forward();
_controllerTwo..forward();
}
print(details.primaryDelta);
},
child: Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
SlideTransition(
position: _offsetAnimationTwo,
child: Card(
color: Colors.black54,
child: Container(),
),
),
Flexible(
child: SlideTransition(
position: _offsetAnimation,
child: Container(
child: SlidingUpPanel(
renderPanelSheet: false,
panel: _floatingStatement(),
body: CardsStack(context),
),
),
),
),
],
),
),
)
],
);
}
Widget _floatingStatement() {
return Container(
margin: const EdgeInsets.all(24.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(24.0)),
boxShadow: [
BoxShadow(
blurRadius: 20.0,
color: Colors.grey,
),
],
),
);
}
}
class CardsStack extends StatelessWidget {
const CardsStack(BuildContext context, {Key key}) : super(key: key);
@override
Widget build(BuildContext context) {
return new Stack(
alignment: Alignment.center,
children: <Widget>[
Positioned(
top: 20,
left: 10,
right: 10,
child: Card(
color: Colors.black54,
child: Container(),
),
),
Positioned(
top: 70,
left: 10,
right: 10,
child: Card(
color: Colors.black54,
child: Container(),
),
),
Positioned(
top: 120,
left: 10,
right: 10,
child: Card(
color: Colors.black54,
child: Container(),
),
),
],
);
}
}
import'包装:flift/cupertino.dart';
进口“包装:颤振/材料.省道”;
导入“包装:向上滑动面板/向上滑动面板.dart”;
类主页扩展了StatefulWidget{
const主页({Key}):超级(Key:Key);
@凌驾
_HomePageState createState()=>\u HomePageState();
}
类_HomePageState使用TickerProviderStateMixin扩展状态{
动画控制器_控制器;
动画(非动画化),;
动画控制器_controllerTwo;
动画(二);
@凌驾
void initState(){
_控制器=动画控制器(
持续时间:常数持续时间(秒数:1),
vsync:这个,,
);
_偏移量=吐温(
开始:常数偏移(-0.00001,0.0),
结束:常数偏移(0.09,0.0),
).动画(曲线动画)(
父节点:_控制器,
曲线:Curves.easeInOut,
));
_controllerTwo=动画控制器(
持续时间:常数持续时间(秒数:1),
vsync:这个,,
);
_偏移量2=吐温(
开始:常数偏移(-0.85,0.0),
结束:常数偏移(-0.00001,0.0),
).动画(曲线动画)(
父项:_controllerTwo,
曲线:Curves.easeInOut,
));
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回列(
crossAxisAlignment:crossAxisAlignment.start,
mainAxisAlignment:mainAxisAlignment.start,
mainAxisSize:mainAxisSize.min,
儿童:[
扩大(
儿童:新的手势检测器(
onHorizontalDragUpdate:(详细信息){
如果(details.primaryDelta>0){
_控制器..反向();
_controllerTwo..reverse();
}
if(details.primaryDelta<0){
_控制器..前进();
_controllerTwo..forward();
}
打印(详情:primaryDelta);
},
孩子:排(
mainAxisSize:mainAxisSize.max,
儿童:[
幻灯片转换(
位置:_偏移量2,
孩子:卡片(
颜色:颜色。黑色54,
子级:容器(),
),
),
灵活的(
子:幻灯片转换(
位置:_偏置,
子:容器(
孩子:滑梯(
renderPanelSheet:false,
面板:_floatingStatement(),
正文:CardsStack(上下文),
),
),
),
),
],
),
),
)
],
);
}
控件_floatingStatement(){
返回容器(
边距:所有常数边集(24.0),
装饰:盒子装饰(
颜色:颜色,白色,
borderRadius:borderRadius.all(半径圆形(24.0)),
boxShadow:[
箱形阴影(
半径:20.0,
颜色:颜色。灰色,
),
],
),
);
}
}
类CardsStack扩展了无状态小部件{
constcardsstack(BuildContext,{Key}):super(Key:Key);
@凌驾
小部件构建(构建上下文){
返回新堆栈(
对齐:对齐.center,
儿童:[
定位(
前20名,
左:10,,
右:10,,
孩子:卡片(
颜色:颜色。黑色54,
子级:容器(),
),
),
定位(
前70名,
左:10,,
右:10,,
孩子:卡片(
颜色:颜色。黑色54,
子级:容器(),
),
),
定位(
排名:120,
左:10,,
右:10,,
孩子:卡片(
颜色:颜色。黑色54,
子级:容器(),
),
),
],
);
}
}
您可以使用PageView
在页面之间水平(甚至垂直)滑动
或者您可以使用TabBarView
实现底部导航
示例代码:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
debugShowCheckedModeBanner: false,
);
}
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
body: TabBarView(
children: <Widget>[
Center(child: Text("Page1")),
Center(child: Text("Page2")),
Center(child: Text("Page3")),
],
),
bottomNavigationBar: Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(10.0),
),
boxShadow: [
BoxShadow(
color: Colors.black,
offset: Offset(0, 0),
blurRadius: 10.0,
),
],
),
child: TabBar(
indicatorColor: Colors.red,
indicatorWeight: 5.0,
indicatorSize: TabBarIndicatorSize.label,
labelColor: Colors.black,
tabs: <Widget>[
Tab(icon: Icon(Icons.home)),
Tab(icon: Icon(Icons.category)),
Tab(icon: Icon(Icons.account_circle)),
],
),
),
),
);
}
}
导入“包装:颤振/材料.省道”;
void main()=>runApp(MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
主页:主页(),
debugShowCheckedModeBanner:false,
);
}
}
类主页扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回DefaultTabController(
长度:3,
孩子:脚手架(
正文:选项卡视图(
儿童:[
居中(子项:文本(“第1页”),
居中(子项:文本(“第2页”),
居中(子项:文本(“第3页”),
],
),
底部导航栏:容器(
装饰:康斯特盒子装饰(
颜色:颜色,白色,
borderRadius:仅限borderRadius(
左上:半径。圆形(10.0),
右上角:半径。圆形(10.0),
),
boxShadow:[
箱形阴影(
颜色:颜色,黑色,
偏移量:偏移量(0,0),
半径:10.0,
),
],
),
孩子:TabBar(
指示颜色:颜色。红色,
指示器重量:5.0,
indicatorSize:TabBarIndicatorSize.label,
labelColor:Colors.black,
选项卡:[
选项卡(图标:图标(Icons.home)),
选项卡(图标:图标(图标.类别)),
选项卡(图标:图标(Icons.account\u circle)),
],