Пользовательская кнопка со стилем FAB - PullRequest
0 голосов
/ 27 марта 2020

Я хочу сделать набор кнопок с эффектом ряби, возвышением и формой, как кнопка FAB. Я прочитал, что могу использовать только одну кнопку FAB на экран, поэтому мне нужно создавать свои собственные, а не использовать набор кнопок FAB. The icons design

Как мне добиться эффекта? Можно ли изменить код FAB на это?

Ответы [ 2 ]

2 голосов
/ 27 марта 2020

Итак, если вы хотите, чтобы фабрики были расположены в вертикальном порядке, оберните их в Столбец , например,

class RandomFabScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: Column(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          FloatingActionButton(
            child: Icon(Icons.home, color: Colors.white,),
            onPressed: (){},
            backgroundColor: Colors.cyan,
          ),
          SizedBox(height: 10,),
          FloatingActionButton(
            child: Icon(Icons.playlist_play, color: Colors.white,),
            onPressed: (){},
            backgroundColor: Colors.red,
          ),
          SizedBox(height: 10,),
          FloatingActionButton(
            child: Icon(Icons.person, color: Colors.white,),
            backgroundColor: Colors.yellow,
            onPressed: (){},
          ),
          SizedBox(height: 10,),
          FloatingActionButton(
            child: Icon(Icons.warning, color: Colors.white,),
            onPressed: (){},
            backgroundColor: Colors.blue,
          ),
        ],
      ),
    );
  }
}

Вывод enter image description here:

И если вы хотите, чтобы они были в горизонтальном порядке, оберните их в Строку

вот так

class RandomFabScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      floatingActionButton: Row(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          FloatingActionButton(
            child: Icon(Icons.home, color: Colors.white,),
            onPressed: (){},
            backgroundColor: Colors.cyan,
          ),
          SizedBox(width: 10,),
          FloatingActionButton(
            child: Icon(Icons.playlist_play, color: Colors.white,),
            onPressed: (){},
            backgroundColor: Colors.red,
          ),
          SizedBox(width: 10,),
          FloatingActionButton(
            child: Icon(Icons.person, color: Colors.white,),
            backgroundColor: Colors.yellow,
            onPressed: (){},
          ),
          SizedBox(width: 10,),
          FloatingActionButton(
            child: Icon(Icons.warning, color: Colors.white,),
            onPressed: (){},
            backgroundColor: Colors.blue,
          ),
        ],
      ),
    );
  }
}

Вывод: enter image description here

0 голосов
/ 27 марта 2020

Вы можете использовать Row для переноса FloatingActionButton

фрагмент кода

Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  FloatingActionButton(
                    onPressed: () {
                      print("click 1");
                    },
                    child: Icon(Icons.navigation),
                    backgroundColor: Colors.green,
                  ),
                  FloatingActionButton(
                    onPressed: () {
                      print("click 2");
                    },
                    child: Icon(Icons.event),
                    backgroundColor: Colors.red,
                  ),
                  FloatingActionButton(
                    onPressed: () {
                      print("click 3");
                    },
                    child: Icon(Icons.gradient),
                    backgroundColor: Colors.yellow,
                  ),
                  FloatingActionButton(
                    onPressed: () {
                      print("click 4");
                    },
                    child: Icon(Icons.album),
                    backgroundColor: Colors.blue,
                  ),
                ]),

рабочая демонстрация

enter image description here

полный код

import 'package:flutter/material.dart';

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

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

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

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Row(
                mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                children: <Widget>[
                  FloatingActionButton(
                    onPressed: () {
                      print("click 1");
                    },
                    child: Icon(Icons.navigation),
                    backgroundColor: Colors.green,
                  ),
                  FloatingActionButton(
                    onPressed: () {
                      print("click 2");
                    },
                    child: Icon(Icons.event),
                    backgroundColor: Colors.red,
                  ),
                  FloatingActionButton(
                    onPressed: () {
                      print("click 3");
                    },
                    child: Icon(Icons.gradient),
                    backgroundColor: Colors.yellow,
                  ),
                  FloatingActionButton(
                    onPressed: () {
                      print("click 4");
                    },
                    child: Icon(Icons.album),
                    backgroundColor: Colors.blue,
                  ),
                ]),
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...