简体   繁体   English

颤动圆形进度指示器未显示在应用栏中

[英]flutter circular progress indicator not showing in appbar

i am creating a project where i need to show a progress bar in the appbar.the code is given below我正在创建一个项目,我需要在 appbar 中显示一个进度条。代码如下

bool loader_saver=false;
return Scaffold(
  appBar: new AppBar(
    title: new Text("add data"),
    actions: <Widget>[
      loader_saver?
          new CircularProgressIndicator()
      :
      new FlatButton(
          onPressed: () {
            _add_Data();
          },
          child: new Icon(
            Icons.save,
            color: Colors.white,
          ))

    ],
  )

here is the onpressed method这是 onpressed 方法

void _add_data(){ 
final _formstate = _form_key.currentState;
if (_formstate.validate()) {
  _form_key.currentState.save();
  setState(() {
    loader_saver=true;
  });
  }
}

This will show your CircularProgressIndicator in appbar, change it as per your requirement这将在应用栏中显示您的 CircularProgressIndicator,根据您的要求进行更改

actions: <Widget>[
new Container(width: 60.0, height: 20.0, color: Colors.lightGreen,
child: new CircularProgressIndicator(),)]

i got the answer...thanks all of you for your response..here is the solution.我得到了答案......感谢你们所有人的回应......这是解决方案。

new Theme(
    data: Theme.of(context).copyWith(accentColor: Colors.yellow),
  child: new CircularProgressIndicator(),
);

Old thread but for anyone reading now:旧线程,但对于现在阅读的任何人:

I'm guessing that it wasn't showing up because in the default material theme the appBar background is the exact same color as the circular progress indicator.我猜它没有显示出来,因为在默认材质主题中,appBar 背景与圆形进度指示器的颜色完全相同。

But, even when you change the color, putting a CircularProgressIndicator in the appBar is hard because the bar will want to stretch the things inside it.但是,即使您更改了颜色,在 appBar 中放置 CircularProgressIndicator 也很困难,因为该栏会想要拉伸其中的内容。 See this issue .看到这个问题 This is how I got it to look just like an action button and follow the correct theming:这就是我如何让它看起来像一个动作按钮并遵循正确的主题:

 class ProgressRefreshAction extends StatelessWidget {
   final bool isLoading;
   final Function() onPressed;

   ProgressRefreshAction({
     this.isLoading,
     this.onPressed,
   });
   @override
   Widget build(BuildContext context) {
     if (isLoading) {
       final theme = Theme.of(context);
       final iconTheme =
           theme.appBarTheme.actionsIconTheme ?? theme.primaryIconTheme;
       return Column(mainAxisAlignment: MainAxisAlignment.center, children: [
         Padding(
           padding: const EdgeInsets.only(right: 12),
           child: Container(
             width: iconTheme.size ?? 24,
             height: iconTheme.size ?? 24,
             child: CircularProgressIndicator(
               valueColor: AlwaysStoppedAnimation<Color>(iconTheme.color),
             ),
           ),
         ),
       ]);
     }
     return IconButton(
       icon: Icon(
         Icons.refresh,
       ),
       onPressed: onPressed,
     );
   }
 }
 //build(context) {
 return Scaffold(
     appBar: AppBar(
       title: Text("MyApp"),
       actions: [
         ProgressRefreshAction(_isLoading),
       ],
       body: //...,
     ),

Looks you are having bool loader_saver=false;看起来你有bool loader_saver=false; as a local variable inside build method.作为build方法中的局部变量。 It should be a state variable.它应该是一个state变量。

As you are calling setState you are having the above code inside StatefulWidget .当您调用setState您在StatefulWidget中有上述代码。

class MyAppState extends State<MyApp> {
 bool loader_saver=false; // add this line (state variable)

 @override
 Widget build(BuildContext context) {
 // bool loader_saver=false; remove this line (local variable)

Stateful widgets will get rebuild only for state variable change.有状态小部件将仅在state变量更改时重建 Not for local/global variable change.不适用于本地/全局变量更改。

Could you verify or change the color of the AppBar or CircularProgressIndicator i remember that they have the same default color the blue one.你能验证或更改AppBarCircularProgressIndicator的颜色吗?我记得它们的默认颜色与蓝色相同。

Please before do something else verify that.请在做其他事情之前验证这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM