小编a2e*_*2en的帖子

转换小部件后 OnPressed 在 Stack 小部件内不起作用

在给定的代码中,onPressed 在凸起的按钮上起作用并将 FlatButton 转换到顶部。但是 FlatButton 上的 onPressed 不起作用

@override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        Transform(
          transform: Matrix4.translationValues(
            0.0,
            _translateButton.value,
            0.0,
          ),
          child: FlatButton(
            onPressed: () {
              print('tapped Flat button');
            },
            child: Text('upper'),
          ),
        ),
          RaisedButton(
            onPressed: () {
              animate();
              print('tapped Raised button');
            },
            child: Text('lower'))
      ],
    );
  }
Run Code Online (Sandbox Code Playgroud)

当 animate() 被调用时,这里 _translatebutton 值从 0 变为 -60

 _animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 500))
      ..addListener(() {
        setState(() {});
      });
    _translateButton = Tween<double>(
      begin: 0,
      end: -60,
    ).animate(CurvedAnimation(
      parent: …
Run Code Online (Sandbox Code Playgroud)

flutter

8
推荐指数
1
解决办法
6382
查看次数

在Dart / Flutter中将DateTime转换为时间之前

问题是如何将Dart DateTime格式化为字符串,说明经过的时间,类似于您看到Stack Overflow上显示的时间的方式。

有没有比这更简单的方法

String timeAgo(DateTime d) {
 Duration diff = DateTime.now().difference(d);
 if (diff.inDays > 365)
  return "${(diff.inDays / 365).floor()} ${(diff.inDays / 365).floor() == 1 ? "year" : "years"} ago";
 if (diff.inDays > 30)
  return "${(diff.inDays / 30).floor()} ${(diff.inDays / 30).floor() == 1 ? "month" : "months"} ago";
 if (diff.inDays > 7)
  return "${(diff.inDays / 7).floor()} ${(diff.inDays / 7).floor() == 1 ? "week" : "weeks"} ago";
 if (diff.inDays > 0)
  return "${diff.inDays} ${diff.inDays == 1 ? "day" : "days"} ago"; …
Run Code Online (Sandbox Code Playgroud)

dart flutter

3
推荐指数
4
解决办法
2721
查看次数

标签 统计

flutter ×2

dart ×1