Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter circular progress indicator not showing in appbar

Tags:

flutter

dart

i am creating a project where i need to show a progress bar in the appbar.the code is given below

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

void _add_data(){ 
final _formstate = _form_key.currentState;
if (_formstate.validate()) {
  _form_key.currentState.save();
  setState(() {
    loader_saver=true;
  });
  }
}
like image 856
Sourav Das Avatar asked Sep 04 '18 17:09

Sourav Das


2 Answers

This will show your CircularProgressIndicator in appbar, change it as per your requirement

actions: <Widget>[
new Container(width: 60.0, height: 20.0, color: Colors.lightGreen,
child: new CircularProgressIndicator(),)]
like image 64
Zulfiqar Avatar answered Sep 24 '22 08:09

Zulfiqar


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.

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. 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: //...,
     ),
like image 41
QuinnFreedman Avatar answered Sep 23 '22 08:09

QuinnFreedman