答案 0 :(得分:1)
您可以在有状态的小部件内使用堆栈小部件。
下面的示例明确了您的想法。
按一下浮动操作按钮,您可以将前景置于背景之上。
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
MyHomePageState createState() {
return new MyHomePageState();
}
}
class MyHomePageState extends State<MyHomePage> {
int change=0;
dialog(){
return Center(
child: new Container(
height: 200.0,
width: 200.0,
color: Colors.amber,
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
new Container(
color: Colors.lightBlueAccent,
width: double.infinity,
height: double.infinity,
),
change==1?dialog():Container()
],
),
floatingActionButton: FloatingActionButton(
onPressed: (){
setState(() {
if(change==0){
change=1;
}else{
change=0;
}
});
}
),
);
}
}