Flutter 如何在脚手架中添加另一个按钮?
我是新来的颤栗,我试图重建演示应用程序。如何将floatingActionButton添加到应用程序中似乎无法添加其他主体或其他内容。我该怎么做Flutter 如何在脚手架中添加另一个按钮?,flutter,dart,Flutter,Dart,我是新来的颤栗,我试图重建演示应用程序。如何将floatingActionButton添加到应用程序中似乎无法添加其他主体或其他内容。我该怎么做 import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; void main() { runApp(MyApp()); } class MyApp extends StatefulWidget { @override _MyAppSt
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,)
),)
,
);
}
}
import'包装:flift/cupertino.dart';
进口“包装:颤振/材料.省道”;
void main(){
runApp(MyApp());
}
类MyApp扩展了StatefulWidget{
@凌驾
_MyAppState createState()=>\u MyAppState();
}
类MyAppState扩展了状态{
@凌驾
int _计数器=0;
无效增加计数器(){
设置状态(){
_计数器+=1;
});
}
小部件构建(构建上下文){
返回材料PP(主页:脚手架)(
appBar:appBar(
标题:文本(“演示应用程序”),
),
正文:中(
子项:文本(“您的按钮$计数器时间”),)
主体:(浮动操作按钮(按下:增加计数器)
),)
,
);
}
}
您可以检查以下代码。浮动动作按钮总是进入脚手架内部
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,
),
);
}
你也可以跟着学,以获得更好的理解