Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 抽屉不动了_Dart_Flutter - Fatal编程技术网

Dart 抽屉不动了

Dart 抽屉不动了,dart,flutter,Dart,Flutter,因此,我使用widgetStack创建了自己的抽屉,这样它就会出现在内容的顶部。我希望此抽屉具有与widgetScaffold抽屉相同的动画(默认设置),以便我将动画放置在此抽屉上,但当我点击菜单图标时,动画不起作用。这是我的代码 import 'dart:async'; import 'package:flutter/material.dart'; import 'package:rencana_belanja/ui/common/gradient_app_bar.dart'; import

因此,我使用widgetStack创建了自己的抽屉,这样它就会出现在内容的顶部。我希望此抽屉具有与widgetScaffold抽屉相同的动画(默认设置),以便我将动画放置在此抽屉上,但当我点击菜单图标时,动画不起作用。这是我的代码

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(''),
      ],
    ),
  );
}
}
导入'dart:async';
进口“包装:颤振/材料.省道”;
导入“包:rencana_belanja/ui/common/gradient_app_bar.dart”;
导入“包:rencana_belanja/ui/home/home_screen_body.dart”;
类主屏幕扩展StatefulWidget{
@凌驾
状态createState(){
//TODO:实现createState
返回新的HomeScreenState();
}
}
类HomeScreenState使用TickerProviderStateMixin扩展状态{
bool-isShow=false;
动画控制器(显示抽屉动画);;
动画绘制器;
@凌驾
void initState(){
//TODO:实现initState
super.initState();
_showingDrawerAnimation=新建动画控制器(
vsync:这个,,
持续时间:新的持续时间(毫秒:300)
);
_Drawer=新尺寸介于两者之间(
开始:新尺寸。fromWidth(0.0),
结束:新尺寸。fromWidth(280.0)
).动画(新曲线动画)(
父项:_显示抽屉名称,
曲线:曲线
));
}
@凌驾
小部件构建(构建上下文){
小部件抽屉=新堆栈(
儿童:[
新墨水池(
子容器:新容器(
颜色:颜色
),
onTap:()异步{
如果(_显示抽屉信息已完成){
等待显示抽屉名称。反转();
设置状态(){
isShow=假;
});
}
},
),
新动画生成器(
动画:_drawer,
生成器:(BuildContext上下文,小部件子项){
返回新的PreferredSize(
首选大小:\u drawer.value,
孩子:新尺寸的盒子(
宽度:_drawer.value.width,
子容器:新容器(
装饰:新盒子装饰(
boxShadow:[
新盒影(
颜色:颜色。黑色45,
模糊半径:7.0
)
],
渐变:新的线性渐变(
颜色:[
常量颜色(0xFF02AAB0),
常量颜色(0xFF00CDAC)
],
开始:常量分数偏移(0.0,0.7),
结束:常量分数偏移(0.6,0.3),
停止:[0.0,1.0],
tileMode:tileMode.clamp
)
),
子:新列(
crossAxisAlignment:crossAxisAlignment.stretch,
儿童:[
_showingDrawerAnimation.isAnimating?新容器():新堆栈(
儿童:[
新形象(
图片:新资产时代(
“assets/img/bokeh.jpg”,
),
),
新定位(
底部:10.0,
左:5.0,
儿童:新文本(
“让我们来看看吧!”,
样式:新文本样式(
颜色:颜色,白色,
fontFamily:“Ubuntu”,
fontWeight:fontWeight.w500,
字体大小:15.0,
)
),
)
],
),
_showingDrawerAnimation.isAnimating?新容器():新容器(
边距:仅限常量边集(顶部:12.0,底部:180.0),
填充:常量边集。对称(水平:18.0),
子:新列(
儿童:[
新行(
儿童:[
新图标(Icons.delete,颜色:Colors.white,),
新货柜(宽度:20.0,),
新文本('Tong Sampah',样式:新文本样式(
颜色:颜色,白色,
fontFamily:“Ubuntu”,
fontWeight:fontWeight.w500,
字体大小:16.0,
),)
],
),
新分隔器(颜色:Colors.white,),
新行(
儿童:[
新图标(Icons.help\u轮廓,颜色:Colors.white,),
新货柜(宽度:20.0,),
新文本('Petunjuk Penggunaan',样式:新文本样式(
颜色:颜色,白色,
fontFamily:“Ubuntu”,
fontWeight:fontWeight.w500,
字体大小:16.0,
),)
],
),
新分隔器(颜色:Colors.white,),
新行(
儿童:[
新图标(Icons.person,颜色:Colors.white,),
新货柜(宽度:20.0,),
新文本('Hubungi Author',样式:新文本样式(
颜色:颜色,白色,
fontFamily:“Ubuntu”,
fontWeight:fontWeight.w500,
字体大小:16.0,
),)
],
  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,
              );
            },
          );
    }
  }