我正在尝试在我的颤振应用程序中添加Flaoting操作按钮,因为只有一个孩子可以实现,所以我无法确定应该将浮动操作按钮的代码放在哪里。
我可以把它作为孩子放在列中,但是它不会出现在屏幕的左下角。我还尝试创建另一个类,然后将其放入scaffold小部件中,但我的favcity不会包含在内。
....
class _favCity extends State<favCity> {
String city1, city2;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Email Login"),
centerTitle: true,
),
backgroundColor: Colors.cyan,
body: Container(
margin: EdgeInsets.all(40.0),
color: Colors.brown,
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(10.0),
//color: Colors.white,
child: TextField(
decoration: new InputDecoration(
labelText: "Enter City 1",
fillColor: Colors.orange,
border: new OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
),
),
onSubmitted: (String userInput) {
setState(() {
city1 = userInput;
});
},
),
),
Container(
padding: EdgeInsets.all(10.0),
// color: Colors.white,
child: TextField(
decoration: InputDecoration(
labelText: "Enter city 2",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
),
fillColor: Colors.orange,
),
onChanged: (String UserInput) {
setState(() {
city2 = UserInput;
});
},
),
),
Text("$city1 Is better than $city2"),
],
),
),
);
}
}
最佳答案
floating action button
也是一个widget
并且可以使用下面的代码放在应用程序中。
import 'package:flutter/material.dart';
class FAButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('FAB Button Example'),
),
body: Center(
child: Text('Floating Action Button Screen'),
),
//FAB is a property of the `Scaffold` Widget
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
//Widget to display inside Floating Action Button, can be `Text`, `Icon` or any widget.
onPressed: () {
//Code to execute when Floating Action Button is clicked
//...
},
),
);
}
}
有关FAB的更多参考或进一步定制,请参见此Link
关于flutter - 如何在代码中添加 float 操作按钮,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57091845/