Created
February 3, 2020 05:56
-
-
Save ryanlid/b13ee4cf290239d3890584bc2357a22a to your computer and use it in GitHub Desktop.
FloatingActionButton 悬浮按钮示例
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: "FloatingActionButton 示例", | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text("FloatingActionButton 示例"), | |
), | |
body: Center( | |
child: Text( | |
"FloatingActionButton", | |
style: TextStyle(fontSize: 28.0), | |
), | |
), | |
floatingActionButton: Builder( | |
builder: (BuildContext context) { | |
return FloatingActionButton( | |
onPressed: () { | |
Scaffold.of(context).showSnackBar(SnackBar( | |
content: Text("你点击了 FloatingActionButton"), | |
)); | |
}, | |
child: const Icon(Icons.add), | |
tooltip: "请点击 FloatingActionButton", | |
// 前景色 | |
foregroundColor: Colors.white, | |
// 后景色 | |
backgroundColor: Colors.blue, | |
// 未点击的阴影值 | |
elevation: 7.0, | |
// 点击时的阴影值 | |
highlightElevation: 14.0, | |
mini: false, | |
shape: CircleBorder(), | |
isExtended: false, | |
); | |
}, | |
), | |
// 居中放置 | |
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment