扑动圆形进度指示器未在appbar中显示

问题描述 投票:2回答:4

我正在创建一个项目,我需要在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,
          ))

    ],
  )

这是onpressed方法

void _add_data(){ 
final _formstate = _form_key.currentState;
if (_formstate.validate()) {
  _form_key.currentState.save();
  setState(() {
    loader_saver=true;
  });
  }
}
dart flutter
4个回答
0
投票

这将在appbar中显示您的CircularProgressIndicator,根据您的要求进行更改

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

1
投票

看起来你有bool loader_saver=false;作为build方法中的局部变量。它应该是一个state变量。

当您调用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)

状态小部件将仅针对state变量进行重建。不适用于本地/全局变量。


1
投票

我得到了答案...感谢所有人的回复..解决方案也是如此。

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

0
投票

你可以验证或更改AppBarCircularProgressIndicator的颜色我记得他们有相同的默认颜色蓝色。

请先做其他事情验证。

© www.soinside.com 2019 - 2024. All rights reserved.