我在我的应用程序中实现了背景。我想在背景打开/关闭期间更改 AppBar 文本。我尝试在 IconButton onPressed 工作期间使用 Boolean isOpen 使其为真/假,但我想知道哪种方法是完美的。是否有任何 api 来检测背景打开/关闭?
import 'package:expense_manager_app/widget/navigation_panel.dart';
import 'package:flutter/material.dart';
class BackDropPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _BackDropState();
}
}
class _BackDropState extends State<BackDropPage>
with SingleTickerProviderStateMixin {
AnimationController controller;
var mTitle = "Home";
var mIsOpen = false;
@override
void initState() {
super.initState();
controller = AnimationController(
vsync: this, duration: Duration(milliseconds: 100), value: 1.0);
}
@override
void dispose() {
super.dispose();
controller.dispose();
}
bool get isPanelVisible {
final AnimationStatus status = controller.status;
return status == AnimationStatus.completed ||
status == AnimationStatus.forward;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('$mTitle'),
elevation: 0.0,
leading: new IconButton(
onPressed: () {
controller.fling(velocity: isPanelVisible ? -1.0 : 1.0);
setState(() {
if (mIsOpen) {
mIsOpen = false;
mTitle = "Home";
} else {
mTitle = "Menu";
mIsOpen = true;
}
});
},
icon: new AnimatedIcon(
icon: AnimatedIcons.close_menu,
progress: controller.view,
),
),
),
body: NavigationPanelPage(controller: controller),
);
}
}