Flutter - Alert Dialog Align-AnimatedAlign【flutter专题16】

2021-12-08 09:09:39 浏览数 (1)

今天给大家带来三个组件,直接贴代码,大家可以运行查看

Flutter - Alert Dialog

代码语言:javascript复制
Future<void> _neverSatisfied() async {
                      return showDialog<void>(
                        context: context,
                        barrierDismissible: false, // tap on button!
                        builder: (BuildContext context) {
                          return AlertDialog(
                            title: Text('Rewind and remember'),
                            content: SingleChildScrollView(
                              child: ListBody(
                                children: <Widget>[
                                  Text('Flutter Title.'),
                                  Text('Flutter Message for the Dialog.'),
                                ],
                              ),
                            ),
                            actions: <Widget>[
                              FlatButton(
                                child: Text('Regret'),
                                onPressed: () {
                                  Navigator.of(context).pop();
                                },
                              ),
                            ],
                          );
                        },
                      );
                    }

Flutter Align Widget

代码语言:javascript复制
Container(
  height: 120.0,
  width: 120.0,
  color: Colors.blue[50],
  child: Align(
    alignment: Alignment.topRight,
    child: FlutterLogo(
      size: 60,
    ),
  ),
)

Flutter - AnimatedAlign Widget

代码语言:javascript复制
AlignmentGeometry _alignment = Alignment.topRight;

void _changeAlignment() {
  setState(() {
    _alignment = _alignment == Alignment.topRight ? Alignment.bottomLeft : Alignment.topRight;
  });
}

@override
Widget build(BuildContext context) {
  return Column(
    mainAxisSize: MainAxisSize.min,
    children: <Widget>[
      Container(
        height: 120.0,
        width: 120.0,
        color: Colors.blue[50],
        child: AnimatedAlign(
          alignment: _alignment,
          curve: Curves.ease,
          duration: Duration(seconds: 3),
          child: FlutterLogo(
            size: 60,
          ),
        ),
      ),
      FlatButton(
        onPressed: () {
          _changeAlignment();
        },
        child: Text(
          "Click Me!",
        ),
      )
    ],
  );
}

0 人点赞