我正在创建一个项目,我需要在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;
});
}
}
这将在appbar中显示您的CircularProgressIndicator,根据您的要求进行更改
actions: <Widget>[
new Container(width: 60.0, height: 20.0, color: Colors.lightGreen,
child: new CircularProgressIndicator(),)]
看起来你有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
变量进行重建。不适用于本地/全局变量。
我得到了答案...感谢所有人的回复..解决方案也是如此。
new Theme(
data: Theme.of(context).copyWith(accentColor: Colors.yellow),
child: new CircularProgressIndicator(),
);
你可以验证或更改AppBar
或CircularProgressIndicator
的颜色我记得他们有相同的默认颜色蓝色。
请先做其他事情验证。