sza*_*es1 4 dart flutter flutter-layout
我想在容器上的 DoubleTap 上动态隐藏和显示应用程序栏,并带有一些隐藏动画,但此链接的解决方案不适用于我的项目:Flutter - How can Idynamic show or hide App Bars onpages
该应用程序的图片:
代码:
import 'package:flutter/material.dart';
class GeneratedCouponScreen extends StatelessWidget {
bool ShowAppBar = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: ShowAppBar ? AppBar(
title: Text('Makdolan Flutter'),
) : null ,
backgroundColor: Colors.white,
body: GestureDetector(
onDoubleTap: () {
ShowAppBar = false;
},
child: Container(
padding: EdgeInsets.all(16.0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('DATA WYDANIA:', style: TextStyle(color: Colors.black),),
Text('10/09/2019', style: TextStyle(color: Colors.black))
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('UNIKALNY KOD:', style: TextStyle(color: Colors.black)),
Text('e-86-tC-9', style: TextStyle(color: Colors.black))
],
)
],
),
Column(
children: [
SizedBox(height: 8.0),
Image.asset('assets/images/coupon_hamburger.png',)
],
)
],
)
),
));
}
}
Run Code Online (Sandbox Code Playgroud)
使用setState
onDoubleTap: () {
setState(() => ShowAppBar = false); // you missed setState
}
Run Code Online (Sandbox Code Playgroud)
更新(完整代码):
void main() => runApp(MaterialApp(home: YourPage()));
class YourPage extends StatefulWidget {
@override
_YourPageState createState() => _YourPageState();
}
class _YourPageState extends State<YourPage> {
bool _showAppBar = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: _showAppBar ? AppBar() : null,
body: Center(
child: GestureDetector(
onDoubleTap: () => setState(() => _showAppBar = !_showAppBar),
child: Container(
width: 200,
height: 200,
color: Colors.blue,
),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3448 次 |
最近记录: |