Flutter - FloatingActionButton in the center

前端 未结 10 1290
无人及你
无人及你 2020-12-15 18:18

Is it possible to make the FloatingActionButton in the centre instead of the right side?

import \'package:flutter/material.dart\';
import \'numb         


        
10条回答
  •  一个人的身影
    2020-12-15 19:01

    Use the Property floatingActionButtonLocation of scaffold class.

    floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,

    Full Example:

    import 'package:flutter/material.dart';
    
    final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
    
    void main() {
      runApp(MyApp());
    }
    
    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
          debugShowCheckedModeBanner: false,
          home: HomePage()
        );
      }
    }
    
    class HomePage extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(),
          body: Container(child: Center(child: Text('Hello World')),),
          floatingActionButton: FloatingActionButton(
            onPressed: () {},
            child: Icon(Icons.camera, color: Colors.white, size: 29,),
            backgroundColor: Colors.black,
            tooltip: 'Capture Picture',
            elevation: 5,
            splashColor: Colors.grey,
          ),
          floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
        );
      }
    }
    

提交回复
热议问题