zl程序教程

您现在的位置是:首页 >  其他

当前栏目

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

2023-04-18 14:39:59 时间

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

Flutter - Alert Dialog

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

Container(
  height: 120.0,
  width: 120.0,
  color: Colors.blue[50],
  child: Align(
    alignment: Alignment.topRight,
    child: FlutterLogo(
      size: 60,
    ),
  ),
)

Flutter - AnimatedAlign Widget

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!",
        ),
      )
    ],
  );
}