演示应用程序中的默认fab在触摸时具有阴影和波纹效果。
flutter -  flutter :FloatingActionButton没有阴影和触摸动画-LMLPHP
然而,当Fab被转移到另一个类时,它突然失去了这种效果,这使得它看起来相当简单。
flutter -  flutter :FloatingActionButton没有阴影和触摸动画-LMLPHP
是否可以将阴影和涟漪动画带到外观简单的Fab中,同时将其保留在单独的类中?
主.dart

import 'package:test_app/TestItem1.dart';
import 'package:flutter/material.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text(widget.title),
      ),
      body: new TestItem1(),
    );
  }
}

测试1.dart
import 'package:flutter/material.dart';

class TestItem1 extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        body: new Center(
          child: new Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              new Text(
                'test 1',
              ),
              new Text(
                'test1',
                style: Theme.of(context).textTheme.display1,
              ),
            ],
          ),
        ),
        floatingActionButton: new FloatingActionButton(
          tooltip: 'Increment',
          onPressed: null,
          child: new Icon(Icons.add),
        ),
      );
  }
}

最佳答案

默认情况下,如果没有给浮动操作按钮
onPresss()
如果你不想让步,只需通过一个匿名方法

10-07 19:27