首页 文章

如何在背景打开/关闭颤动期间更改AppBar文本

提问于
浏览
0

我在我的应用中实现了背景 . 我想在背景打开/关闭期间更改AppBar文本 . 我尝试使用Boolean isOpen在IconButton onPressed工作时使其为true / false,但我想知道哪种是完美的方式 . 是否有任何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),
    );
  }
}

1 回答

  • 0

    最后我用isPanelVisible bool完成了自己 .

    appBar: AppBar(
        title: Text('$mTitle'),
        elevation: 0.0,
        leading: new IconButton(
          onPressed: () {
            controller.fling(velocity: isPanelVisible ? -1.0 : 1.0);
            setState(() {
              if (isPanelVisible) {
                mTitle = "Home";
              } else {
                mTitle = "Menu";
              }
            });
          },
          icon: new AnimatedIcon(
            icon: AnimatedIcons.close_menu,
            progress: controller.view,
          ),
        ),
      ),
    

相关问题