【问题标题】:How to place a Progress bar over or inside an App Bar in Flutter?如何在 Flutter 中的 App Bar 上方或内部放置进度条?
【发布时间】:2021-04-27 03:16:51
【问题描述】:

有人知道我是否可以在应用栏中包含进度条吗?请参阅我正在尝试实现的屏幕截图。我正在尝试重用代码,如果我可以创建一个带有进度指示器的应用栏,那么没有。这将使用户能够在注册时完成此屏幕,然后在他们拥有帐户后在没有进度条的情况下编辑此屏幕。这甚至可能吗?

【问题讨论】:

    标签: flutter progress-bar appbar


    【解决方案1】:

    如果您想在应用栏中制作进度指示器,您可以使用应用栏标题中的进度指示器,但是:

    如果你想像图片那样制作,我会告诉你如何在进度指示器下方制作自定义应用栏

    class Myapplication extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        Size size = MediaQuery.of(context).size;
        return Scaffold(
          body: SafeArea(
              child: Column(
                children: [
                  LinearProgressIndicator(),
                  Row(
                    children: [
                      Icon(Icons.arrow_back_outlined, color: Colors.black),
                    ],
                  ),
                ],
            ),
          ),
        );
      }
    }
    

    【讨论】:

      【解决方案2】:

      您最好的选择是使用 appBar 小部件的“底部”属性,它看起来像这样

      class HomeScreen extends StatelessWidget {
      // this is to hide the progress inidecator once the account is created
        bool isSignUpComplete = false;
        @override
        Widget build(BuildContext context) {
      // this is to retrieve the device screen size
          final Size size = MediaQuery.of(context).size;
          return Scaffold(
            appBar: AppBar(
              bottom: !isSignUpComplete ? PreferredSize(
                child: LinearProgressIndicator(
                  backgroundColor: Colors.red,
                ),
                preferredSize: Size(size.width, 0),
              ) : null,
            ),
          );
        }
      }
      
      

      【讨论】:

        【解决方案3】:

        我通过将进度条放在正文中解决了这个问题,将正文延伸到应用栏后面,然后使应用栏透明。

        class SignUpForm extends StatelessWidget {
          double progress = 0.22;
        
          @override
          Widget build(BuildContext context) => Scaffold(
            backgroundColor: Colors.white,
            extendBodyBehindAppBar: true,
        
            appBar: BasicFormAppBar(),
        
            body: Column(
              children: [
                SizedBox(height: 45),
                Container(
                  child: LinearProgressIndicator(
                    value: progress,
                    valueColor: AlwaysStoppedAnimation(Colors.Blue),
                    backgroundColor: Colors.Grey,
                  ),
                ), //column & scaffold are not closed in this snippet
        

        【讨论】:

        • 请分享您的解决方案的简短示例
        猜你喜欢
        • 2021-05-20
        • 2023-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-02-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多