import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
final apptitle = "Offstage控制是否显示组件示例";
return MaterialApp(
title: apptitle,
home: MyHomePage(
title: apptitle,
),
);
}
}
class MyHomePage extends StatefulWidget {
@override
final String title;
MyHomePage({Key key, this.title}) : super(key: key);
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool Offstagex = true;
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Offstage(
offstage: Offstagex,
child: Text(
'天王盖地虎',
style: TextStyle(fontSize: 36),
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState(() {
Offstagex = !Offstagex;
});
},
tooltip: "显示隐藏",
child: Icon(Icons.flip),
),
);
}
}
网友评论