【发布时间】:2021-04-03 12:15:05
【问题描述】:
每当我点击屏幕时,我一直在尝试使用 GestureDetector 小部件在 Flutter 中隐藏 AppBar。
但它不起作用。以下是我的代码:
import 'package:flutter/material.dart';
// This is the page widget
class PageWidget extends StatefulWidget {
final String title;
PageWidget({Key key, this.title}) : super(key: key);
@override
_PageWidgetState createState() => _PageWidgetState();
}
class _PageWidgetState extends State<PageWidget> {
Widget build(BuildContext context) {
// making the AppBar
bool _showAppBar = true;
final appBar = AppBar(
title: Text("Page one"),
centerTitle: true,
backgroundColor: Colors.teal,
);
final body = Container(
child: GestureDetector(
onTap: () {
setState(() => {_showAppBar = !_showAppBar});
print("This GestureDetector");
},
behavior: HitTestBehavior.translucent,
// content of the page.
child: SingleChildScrollView(
),
),
);
return Scaffold(
appBar: _showAppBar ? appBar : null,
body: body,
);
}
}
这是怎么回事?
【问题讨论】:
标签: android flutter user-interface dart flutter-animation