I am showing bottom sheet on a button tap. The bottom sheet contains a button. On that press of button I change the state of _isButtonPressed variable which is of type bool. Now I want to show CircularProgreesIndicator which is not happening. But the bottom sheet pops after 5 seconds. What am I doing wrong?
showModalBottomSheet<dynamic>(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(20.0),
topRight: const Radius.circular(20.0),
)),
isScrollControlled: true,
context: context,
builder: (BuildContext context) {
return Wrap(children: [
Column(
children: [
!_isButtonPressed
? FlatButton(
onPressed: () async {
setState(() {
_isButtonPressed = true;
});
await Future.delayed(Duration(seconds: 5));
setState(() {
_isButtonPressed = false;
});
Navigator.pop(context);
},
child: Row(
children: [
Icon(Icons.share),
SizedBox(
width: 12.0,
),
Text('Share'),
],
))
: Row(
children: [
Icon(Icons.share),
SizedBox(
width: 12.0,
),
CircularProgressIndicator(
strokeWidth: 3.0,
),
],
),],),],);)
Update: Here is complete code to test.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Bottom sheet'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool _isButtonPressed;
@override
void initState() {
super.initState();
_isButtonPressed = false;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
showModalBottomSheet(
context: context,
builder: (BuildContext bc) {
return Container(
child: Wrap(
children: <Widget>[
!_isButtonPressed
? FlatButton(
onPressed: () async {
setState(() {
_isButtonPressed = true;
});
print(_isButtonPressed);
await Future.delayed(Duration(seconds: 5));
setState(() {
_isButtonPressed = false;
});
Navigator.pop(context);
},
child: Row(
children: [
Icon(Icons.share),
SizedBox(
width: 12.0,
),
!_isButtonPressed
? Text('Share')
: Text('Wait'),
],
))
: Row(
children: [
Icon(Icons.share),
SizedBox(
width: 12.0,
),
CircularProgressIndicator(
strokeWidth: 3.0,
),
],
),
],
),
);
});
},
child: Icon(Icons.add),
),
);
}
}