Created
February 16, 2020 13:46
-
-
Save ryanlid/793a9815f2d091f0e6299550c8bded00 to your computer and use it in GitHub Desktop.
Offstage 控制是否显示组件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
final appTitle = "Offstage控制是否显示组件"; | |
return MaterialApp( | |
title: appTitle, | |
home: MyHomePage(title: appTitle), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
final String title; | |
MyHomePage({Key key, this.title}) : super(key: key); | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
// 状态控制是否显示文本组件 | |
bool offstage = true; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(widget.title), | |
), | |
body: Center( | |
child: Offstage( | |
// 控制是否显示 | |
offstage: offstage, | |
child: Text( | |
'我出来啦!', | |
style: TextStyle( | |
fontSize: 36.0, | |
), | |
), | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
// 设置是否显示文本组件 | |
setState(() { | |
offstage = !offstage; | |
}); | |
}, | |
tooltip: "显示隐藏", | |
child: Icon(Icons.flip), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment