所以我使用小部件 Stack 创建了我自己的抽屉,这样它就会出现在内容的顶部。我希望这个抽屉具有与小部件 Scaffold 抽屉(默认)相同的动画,以便我将动画放在这个抽屉上,但是当我点击菜单图标时动画不起作用。所以这是我的代码。
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:rencana_belanja/ui/common/gradient_app_bar.dart';
import 'package:rencana_belanja/ui/home/home_screen_body.dart';
class HomeScreen extends StatefulWidget {
@override
State createState() {
// TODO: implement createState
return new HomeScreenState();
}
}
class HomeScreenState extends State<HomeScreen> with TickerProviderStateMixin{
bool isShow = false;
AnimationController _showingDrawerAnimation;
Animation<Size> _theDrawer;
@override
void initState() {
// TODO: implement initState
super.initState();
_showingDrawerAnimation = new AnimationController(
vsync: this,
duration: new Duration(milliseconds: 300)
);
_theDrawer = new SizeTween(
begin: new Size.fromWidth(0.0),
end: new Size.fromWidth(280.0)
).animate(new CurvedAnimation(
parent: _showingDrawerAnimation,
curve: Curves.ease
));
}
@override
Widget build(BuildContext context) {
Widget drawer = new Stack(
children: <Widget>[
new InkWell(
child: new Container(
color: Colors.black54
),
onTap: () async {
if (_showingDrawerAnimation.isCompleted) {
await _showingDrawerAnimation.reverse();
setState(() {
isShow = false;
});
}
},
),
new AnimatedBuilder(
animation: _theDrawer,
builder: (BuildContext context, Widget child) {
return new PreferredSize(
preferredSize: _theDrawer.value,
child: new SizedBox(
width: _theDrawer.value.width,
child: new Container(
decoration: new BoxDecoration(
boxShadow: [
new BoxShadow(
color: Colors.black45,
blurRadius: 7.0
)
],
gradient: new LinearGradient(
colors: [
const Color(0xFF02AAB0),
const Color(0xFF00CDAC)
],
begin: const FractionalOffset(0.0, 0.7),
end: const FractionalOffset(0.6, 0.3),
stops: [0.0, 1.0],
tileMode: TileMode.clamp
)
),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
_showingDrawerAnimation.isAnimating ? new Container() : new Stack(
children: <Widget>[
new Image(
image: new AssetImage(
'assets/img/bokeh.jpg',
),
),
new Positioned(
bottom: 10.0,
left: 5.0,
child: new Text(
'Rencanakan kebutuhan belanjamu!',
style: new TextStyle(
color: Colors.white,
fontFamily: 'Ubuntu',
fontWeight: FontWeight.w500,
fontSize: 15.0,
)
),
)
],
),
_showingDrawerAnimation.isAnimating ? new Container() : new Container(
margin: const EdgeInsets.only(top: 12.0, bottom: 180.0),
padding: const EdgeInsets.symmetric(horizontal: 18.0),
child: new Column(
children: <Widget>[
new Row(
children: <Widget>[
new Icon(Icons.delete, color: Colors.white,),
new Container(width: 20.0,),
new Text('Tong Sampah', style: new TextStyle(
color: Colors.white,
fontFamily: 'Ubuntu',
fontWeight: FontWeight.w500,
fontSize: 16.0,
),)
],
),
new Divider(color: Colors.white,),
new Row(
children: <Widget>[
new Icon(Icons.help_outline, color: Colors.white,),
new Container(width: 20.0,),
new Text('Petunjuk Penggunaan', style: new TextStyle(
color: Colors.white,
fontFamily: 'Ubuntu',
fontWeight: FontWeight.w500,
fontSize: 16.0,
),)
],
),
new Divider(color: Colors.white,),
new Row(
children: <Widget>[
new Icon(Icons.person, color: Colors.white,),
new Container(width: 20.0,),
new Text('Hubungi Author', style: new TextStyle(
color: Colors.white,
fontFamily: 'Ubuntu',
fontWeight: FontWeight.w500,
fontSize: 16.0,
),)
],
),
new Divider(color: Colors.white,),
],
),
),
_showingDrawerAnimation.isAnimating ? new Container() : new Row(
children: <Widget>[
new Container(
width: 10.0,
),
new Text(
'Personalization',
style: new TextStyle(
color: Colors.white,
fontFamily: 'Ubuntu',
fontWeight: FontWeight.w500,
fontSize: 14.0,
)
),
],
),
_showingDrawerAnimation.isAnimating ? new Container() : new Divider(color: Colors.white,),
_showingDrawerAnimation.isAnimating ? new Container() : new Row(
children: <Widget>[
new Container(margin: const EdgeInsets.only(left: 15.0)),
new Icon(Icons.settings, color: Colors.white,),
new Container(width: 20.0,),
new Text('Pengaturan', style: new TextStyle(
color: Colors.white,
fontFamily: 'Ubuntu',
fontWeight: FontWeight.w500,
fontSize: 16.0,
),)
],
),
],
),
),
),
);
},
)
],
);
// TODO: implement build
return new Scaffold(
body: new Stack(
children: <Widget>[
new Column(
children: <Widget>[
new GradientAppBar(
title: 'Daftar Belanja',
isShow: isShow,
onDrawerShows: (bool value) async {
if (_showingDrawerAnimation.isDismissed) {
await _showingDrawerAnimation.forward();
setState(() {
isShow = true;
});
}
},
),
new HomeScreenBody()
],
),
new Positioned(
bottom: 20.0,
right: 15.0,
child: new GestureDetector(
onTap: () => print("tiesto"),
child: new CircleAvatar(
backgroundColor: Colors.red,
child: new Icon(
Icons.add,
color: Colors.white,
),
radius: 25.0,
),
)
),
isShow == true ? drawer : new Text(''),
],
),
);
}
}
唯一有效的动画是 reverse 动画。我怎样才能使前进动画工作?
注意:抱歉英语不好,这不是我的母语所以我希望你能理解。谢谢
最佳答案
您可以使用包含整个抽屉的单独类。我希望你正在寻找那个。
import 'dart:async';
import 'package:flutter/material.dart';
import 'dart:math' as math;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: "List View",
home: new HomePage(),
);
}
}
String text = "hello World";
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title:Text("Home Page"),
),
drawer: Example(),
body: new Text(text),
);
}
}
class Example extends StatefulWidget {
@override
_ExampleState createState() => new _ExampleState();
}
class _ExampleState extends State<Example> with TickerProviderStateMixin {
AnimationController _animationController;
double animationDuration = 0.0;
int totalItems = 9;
@override
void initState() {
super.initState();
final int totalDuration = 1000;
_animationController = AnimationController(
vsync: this, duration: new Duration(milliseconds: totalDuration));
animationDuration = totalDuration/(100*(totalDuration/(totalItems)));
_animationController.forward();
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container(
width: 75.0,
child: ListView.builder(
itemCount: totalItems,
itemBuilder: (BuildContext context, int index) {
return new Item(index: index, animationController: _animationController, duration: animationDuration);
},
),
);
}
}
class Item extends StatefulWidget {
final int index;
final AnimationController animationController;
final double duration;
Item({this.index, this.animationController, this.duration});
@override
_ItemState createState() => _ItemState();
}
class _ItemState extends State<Item> {
Animation _animation;
double start;
double end;
Animation<double> rotateY;
@override
void initState() {
super.initState();
start = (widget.duration * widget.index).toDouble();
end = start + widget.duration;
print("START $start , end $end");
_animation = Tween<double>(
begin: 1.0,
end: 1.0,
).animate(
CurvedAnimation(
parent: widget.animationController,
curve: Interval(
widget.index == 0 ? start : start - widget.duration/2,
widget.index == 0 ? end + widget.duration : end + widget.duration/2,
curve: Curves.easeIn,
),
),
)..addListener((){
setState(() {
});
});
rotateY = new Tween<double>(
begin: -0.5,
end: .0,
).animate(
CurvedAnimation(
parent: widget.animationController,
curve: Interval(
widget.index == 0 ? start: start - widget.duration/2,
widget.index == 0 ? end + widget.duration : end + widget.duration/2,
curve: Curves.easeIn,
),
),
);
}
Future<Null> reverse() async {
await widget.animationController
.reverse()
.orCancel;
Navigator.pop(context);
Navigator.push(
context,
MaterialPageRoute(builder: (context) => MyApp()),
);
}
@override
Widget build(BuildContext context) {
return new AnimatedBuilder(
animation: widget.animationController,
builder: (context, child) {
final card = Opacity(
opacity: _animation.value,
child: new Container(
height: 75.0,
child: RaisedButton(
color: Colors.blueGrey,
child: Icon(
Icons.ac_unit,
color: Colors.white,
size: 50.0,
),
onPressed: (){
reverse();
},
),
),
);
return new Transform(
transform: new Matrix4.rotationY(rotateY.value * math.pi),
alignment: Alignment.centerLeft,
child: card,
);
},
);
}
}
关于dart - 抽屉没有 flutter 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49849341/
我好像记得Lua有类似Ruby的method_missing的东西。还是我记错了? 最佳答案 表的metatable的__index和__newindex可以用于与Ruby的method_missing相同的效果。 关于ruby-难道Lua没有和Ruby的method_missing相媲美的东西吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/7732154/
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
大家好!我想知道Ruby中未使用语法ClassName.method_name调用的方法是如何工作的。我头脑中的一些是puts、print、gets、chomp。可以在不使用点运算符的情况下调用这些方法。为什么是这样?他们来自哪里?我怎样才能看到这些方法的完整列表? 最佳答案 Kernel中的所有方法都可用于Object类的所有对象或从Object派生的任何类。您可以使用Kernel.instance_methods列出它们。 关于没有类的Ruby方法?,我们在StackOverflow
我真的为这个而疯狂。我一直在搜索答案并尝试我找到的所有内容,包括相关问题和stackoverflow上的答案,但仍然无法正常工作。我正在使用嵌套资源,但无法使表单正常工作。我总是遇到错误,例如没有路线匹配[PUT]"/galleries/1/photos"表格在这里:/galleries/1/photos/1/edit路线.rbresources:galleriesdoresources:photosendresources:galleriesresources:photos照片Controller.rbdefnew@gallery=Gallery.find(params[:galle
我在Rails应用程序中使用CarrierWave/Fog将视频上传到AmazonS3。有没有办法判断上传的进度,让我可以显示上传进度如何? 最佳答案 CarrierWave和Fog本身没有这种功能;你需要一个前端uploader来显示进度。当我不得不解决这个问题时,我使用了jQueryfileupload因为我的堆栈中已经有jQuery。甚至还有apostonCarrierWaveintegration因此您只需按照那里的说明操作即可获得适用于您的应用的进度条。 关于ruby-on-r
如何在Ruby中获取BasicObject实例的类名?例如,假设我有这个:classMyObjectSystem我怎样才能使这段代码成功?编辑:我发现Object的实例方法class被定义为returnrb_class_real(CLASS_OF(obj));。有什么方法可以从Ruby中使用它? 最佳答案 我花了一些时间研究irb并想出了这个:classBasicObjectdefclassklass=class这将为任何从BasicObject继承的对象提供一个#class您可以调用的方法。编辑评论中要求的进一步解释:假设你有对象
Unity自动旋转动画1.开门需要门把手先动,门再动2.关门需要门先动,门把手再动3.中途播放过程中不可以再次进行操作觉得太复杂?查看我的文章开关门简易进阶版效果:如果这个门可以直接打开的话,就不需要放置"门把手"如果门把手还有钥匙需要旋转,那就可以把钥匙放在门把手的"门把手",理论上是可以无限套娃的可调整参数有:角度,反向,轴向,速度运行时点击Test进行测试自己写的代码比较垃圾,命名与结构比较拉,高手轻点喷,新手有类似的需求可以拿去做参考上代码usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;u
我在非Rails项目中使用ActiveRecord。在Rails中,我可以这样做:config.time_zone='EasternTime(US&Canada)'config.active_record.default_timezone='EasternTime(US&Canada)'但如果我不使用rails,我该如何设置时区? 最佳答案 ActiveRecord::Base.default_timezone='EasternTime(US&Canada)' 关于ruby-没有轨道的A
在我让另一个人重做我的前端UI之前,我的Rails应用程序运行平稳。我已经尝试解决此错误3天了。这是错误:Nosuchfileordirectory-identifyExtractedsource(aroundline#59):575859606162@post=Post.find(params[:id])authorize@postif@post.update_attributes(post_params)flash[:notice]="Postwasupdated."redirect_to[@topic,@post]else{"utf8"=>"✓","_method"=>"patc