1

I need to know if there is a way to update its content like a value of a linear progress indicator, is that possible, I searched for this problem but didn't find a satisfying answer.

code

else {
              setState(() {
                percentage = (event.snapshot.bytesTransferred /
                    event.snapshot.totalByteCount);
              });
              print(percentage);
            }
          });
          return showDialog(
            context: context,
            builder: (BuildContext context) {
              return AlertDialog(
                title: Text('Uploading'),
                content: Column(
                  children: [
                    Center(
                      child: Text('Uploading .... Please Be Patient'),
                    ),
                    SizedBox(
                      height: height * 0.02,
                    ),
                    LinearProgressIndicator(
                      value: percentage != null ? percentage : 0.0,
                    )
                  ],
                ),
              );
            },
            barrierDismissible: false,
          );

2 Answers2

0

if I'm not mistaken, you can use StatefulBuilder widget and use setmodalState instead of setState, I used it with modal bottom sheet

Yakhyo Mashrapov
  • 360
  • 2
  • 13
0

Here is a working code with StatefulBuilder:


class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int number = 0;
  StateSetter _setModalState;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Material(
          child: Center(
            child: FlatButton(
              color: Colors.green,
              child: Padding(
                padding: EdgeInsets.all(12),
                child: Text('press me'),
              ),
              onPressed: () {
                showDialog(
                  context: context,
                  builder: (BuildContext context) {
                    return StatefulBuilder(builder:
                        (BuildContext context, StateSetter setModalState) {
                      this._setModalState = setModalState;
                      return AlertDialog(
                        content: Wrap(
                          children: [
                            Column(
                              children: [
                                Center(
                                  child: Text(number.toString()),
                                ),
                                SizedBox(
                                  height: 100,
                                ),
                                FlatButton(
                                  color: Colors.red,
                                  onPressed: () {
                                    _setModalState(() {
                                      number++;
                                    });
                                  },
                                  child: (Text("++")),
                                )
                              ],
                            ),
                          ],
                        ),
                      );
                    });
                  },
                  barrierDismissible: false,
                );
              },
            ),
          ),
        ));
  }
}
Yakhyo Mashrapov
  • 360
  • 2
  • 13