简体   繁体   English

带有文本标签的浮动操作按钮。 扑

[英]Floating action button with text label. Flutter

I need floating action button like this:我需要像这样的浮动操作按钮:

图片 . .

Are there standard tools for implementation?是否有标准的实施工具? I watched both the standard version of the button and the extended one, but did not find anything我看了按钮的标准版和扩展版,但没有找到任何东西

You don't need to use an external library because it will grow the size of your bundle.你不需要使用外部库,因为它会增加你的包的大小。

This is the code:这是代码:

FloatingActionButton.extended(
    onPressed: () {
      // Add your onPressed code here!
    },
    label: Text('Approve'),
    icon: Icon(Icons.thumb_up),
    backgroundColor: Colors.pink,
) 

你可以使用这个flutter包flutter_fab或者你可以参考这篇文章在flutter中创建动画FAB

You can also use this flutter_speed_dial你也可以使用这个flutter_speed_dial

https://pub.dev/packages/flutter_speed_dial#-readme-tab- https://pub.dev/packages/flutter_speed_dial#-readme-tab-

You can use FloatingActionButton.Extended.您可以使用 FloatingActionButton.Extended。

just copy and paste the code and see the result itself只需复制并粘贴代码并查看结果本身

  import 'package:flutter/material.dart';

class TestClass extends StatefulWidget {
  @override
  _TestClassState createState() => _TestClassState();
}

class _TestClassState extends State<TestClass> {
  bool floatExtended = false;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
          child: Container(
        width: 272,
        height: 168,
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(20), color: Colors.indigo),
      )),
      floatingActionButton: FloatingActionButton.extended(
        tooltip: 'Create Card',
        label: Row(
          children: [
            IconButton(onPressed: () {}, icon: Icon(Icons.save)),
            IconButton(onPressed: () {}, icon: Icon(Icons.library_add_check)),

            // Text('1'),
            // Text('2'),
            // Text('3'),
          ],
        ),
        isExtended: floatExtended,
        icon: Icon(
          floatExtended == true ? Icons.close : Icons.radio_button_on,
          color: floatExtended == true ? Colors.red : Colors.black,
        ),
        onPressed: () {
          setState(() {
            floatExtended = !floatExtended;
          });
        },
        backgroundColor: floatExtended == true
            ? Colors.blueGrey
            : Colors.white.withOpacity(.7),
      ),
    );
  }
}

Add a Text("YourText") widget in child of FloatingActionButton.在 FloatingActionButton 的子项中添加一个 Text("YourText") 小部件。 Then it will work.然后它将起作用。

FloatingActionButton.extended(
     child: Text('Login'),
     backgroundColor: Colors.pink,
     onPressed: null,) 

Use Flow class.使用 Flow 类。 It's built-in flutter No need for an external package.它是内置的 Flutter 不需要外部封装。 The flow was built for this kind of feature.该流程是为这种功能而构建的。

Here is the doc link https://api.flutter.dev/flutter/widgets/Flow-class.html这是文档链接https://api.flutter.dev/flutter/widgets/Flow-class.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM