gpt4 book ai didi

flutter - 如何在双击时动态隐藏 AppBar?

转载 作者:行者123 更新时间:2023-12-03 02:50:43 28 4
gpt4 key购买 nike

我想在容器上的 DoubleTap 上动态隐藏和显示 App Bar,并在隐藏时使用一些动画,但此链接的解决方案不适用于我的项目:Flutter - How can I dynamically show or hide App Bars on pages

应用图片: image

代码:

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',)
],
)
],
)
),
));
}
}

最佳答案

使用setState

onDoubleTap: () {
setState(() => ShowAppBar = false); // you missed setState
}

更新(完整代码):

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,
),
),
),
);
}
}

关于flutter - 如何在双击时动态隐藏 AppBar?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57895277/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com