dart - 带有快速拨号的 flutter float Action 按钮

标签 dart floating-action-button flutter

是否有任何现成的小部件或从哪里开始floating action button with speed dial actionsFlutter .

最佳答案

这里是如何使用 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();
              }
            },
          ),
        ),
      ),
    );
  }
}

关于dart - 带有快速拨号的 flutter float Action 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46480221/

相关文章:

android - float 操作按钮始终显示在顶部

android - 锚定到应用栏的 FAB 不会在向上滚动时隐藏

dart - Flutter:自定义 ExpansionTile

android-studio - Flutter:如何将值从streamprovider/listview构建器传递到另一个类

android - Flutter - 如何更改文本字段弹出菜单的样式?

Flutter无法处置VideoPlayerController

flutter - 如何在具有 flutter 透明度的 png 上应用滤色器?

android - float 操作按钮在滚动时消失

date - 昨天的日期 flutter 朔迷离

ios - 错误(Xcode): File not found:/Applications/Xcode.应用程序/内容/开发者/工具链/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphonesimulator.a