当前位置: 首页 > 面试题库 >

带有快速拨盘的Flutter浮动动作按钮

李嘉胜
2023-03-14
问题内容

在Flutter中是否有任何现成的小部件或从何处开始(https://material.io/guidelines/components/buttons-
floating-action-button.html#buttons-floating-action-button-transitions) in
Flutter.


问题答案:

这是有关如何使用进行快速拨号的示意图FloatingActionButton.

video

import 'package:flutter/material.dart';
import 'dart:math' as math;

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new MyHomePage(),
    );
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State createState() => new MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> with TickerProviderStateMixin {
  AnimationController _controller;

  static const List<IconData> icons = const [ Icons.sms, Icons.mail, Icons.phone ];

  @override
  void initState() {
    _controller = new AnimationController(
      vsync: this,
      duration: const Duration(milliseconds: 500),
    );
  }

  Widget build(BuildContext context) {
    Color backgroundColor = Theme.of(context).cardColor;
    Color foregroundColor = Theme.of(context).accentColor;
    return new Scaffold(
      appBar: new AppBar(title: new Text('Speed Dial Example')),
      floatingActionButton: new Column(
        mainAxisSize: MainAxisSize.min,
        children: new List.generate(icons.length, (int index) {
          Widget child = new Container(
            height: 70.0,
            width: 56.0,
            alignment: FractionalOffset.topCenter,
            child: new ScaleTransition(
              scale: new CurvedAnimation(
                parent: _controller,
                curve: new Interval(
                  0.0,
                  1.0 - index / icons.length / 2.0,
                  curve: Curves.easeOut
                ),
              ),
              child: new FloatingActionButton(
                heroTag: null,
                backgroundColor: backgroundColor,
                mini: true,
                child: new Icon(icons[index], color: foregroundColor),
                onPressed: () {},
              ),
            ),
          );
          return child;
        }).toList()..add(
          new FloatingActionButton(
            heroTag: null,
            child: new AnimatedBuilder(
              animation: _controller,
              builder: (BuildContext context, Widget child) {
                return new Transform(
                  transform: new Matrix4.rotationZ(_controller.value * 0.5 * math.pi),
                  alignment: FractionalOffset.center,
                  child: new Icon(_controller.isDismissed ? Icons.share : Icons.close),
                );
              },
            ),
            onPressed: () {
              if (_controller.isDismissed) {
                _controller.forward();
              } else {
                _controller.reverse();
              }
            },
          ),
        ),
      ),
    );
  }
}


 类似资料:
  • 我有这个浮动动作按钮(GitHub链接),当我打开一个(软件)键盘时,浮动动作按钮隐藏在键盘后面。

  • Floating Action Button is supported only in Material Theme Floating action buttons are used for a promoted action. They are distinguished by a circled icon floating above the UI and have motion behavi

  • 我想为我的工厂制作动画,就像材料设计原理中的这个例子,我意识到工厂里的图标有两个动画。一个是旋转共享图标,另一个是alpha动画同步。之后,另一个图标被替换。但当我为这个目标创建动画集时,整个晶圆厂旋转并消失,但我希望晶圆厂内的图标拍摄这个动画。我怎样才能创建这个动画?谢谢

  • 我的应用程序出现了这个错误

  • 我正在使用材料组件FloatingActionButton https://material.io/develop/android/components/floading-action-button/ 在这一点上,我无法为我的晶圆厂添加elevation我尝试使用下面的代码,但它不工作 下面是我的XML。

  • null 这似乎并不复杂,但我就是做不到 有什么想法吗?