작성
·
173
0
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: ShowHide(),
);
}
}
class ShowHide extends StatefulWidget {
@override
_ShowHideState createState() => _ShowHideState();
}
class _ShowHideState extends State<ShowHide> {
@override
Widget build(BuildContext context) {
bool visible_val=true;
void showWidget() {
setState(() {
visible_val = true;
});
}
void hideWidget() {
setState(() {
visible_val = false;
});
}
return Scaffold(
appBar: AppBar(
title: Text("show hide"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Text("Show"),
onPressed: showWidget,
),
RaisedButton(
child: Text("Hide"),
onPressed: hideWidget,
),
Visibility(visible: visible_val,
child: Text("This is text",
style: TextStyle(fontSize: 30.0),
),
),
],
),
),
);
}
}