flutter - 如何在 Scaffold 中添加另一个按钮?
问题描述
我是新来的,我正在尝试重建演示应用程序。如何将 FloatingActioButton 添加到应用程序中,我似乎无法添加其他主体或其他东西。我怎样才能做到这一点 ?
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
int _counter = 0;
void increase_Counter() {
setState(() {
_counter += 1;
});
}
Widget build(BuildContext context) {
return MaterialApp(home: Scaffold(
appBar: AppBar(
title: Text("Demo App"),
),
body: Center(
child: Text("Your press button $_counter times"),)
body:(FloatingActionButton(onPressed: increase_Counter,)
),)
,
);
}
}
解决方案
您可以检查以下代码。浮动操作按钮总是在脚手架内。
Widget build(BuildContext context) {
return MaterialApp(home: Scaffold(
appBar: AppBar(
title: Text("Demo App"),
),
body: Center(
child: Text("Your press button $_counter times"),),
floatingActionButton: FloatingActionButton(
onPressed: () {
// Add your onPressed code here!
},
child: Icon(Icons.navigation),
backgroundColor: Colors.green,
),
);
}
并且您也可以关注FloatingActionButton以获得更好的理解。
推荐阅读
- c++ - PFYvv 代表什么?(不是 PFvv!)
- sparql - 使用 Jena 的 SPARQL FILTER() 无法正常工作
- reactjs - 页面在重新渲染时不保留其状态
- javascript - 为什么更改 window.location.href 在 onbeforeunload 中不起作用?
- python - 无论如何要在本地保存从网站链接自动下载的文件?
- r - 基于当前上一个和下一个值的新变量的 R 规则
- python - 为什么 Tkinter 不调用绑定到根窗口的函数?
- python - 为什么它给我 TypeError: Expected cv::UMat for argument 'src'?
- python-3.x - 如何通过索引名称访问数据框中新添加(生成)的行?
- java - Java8 时间库无法正确解释 BST 时区