How to show circularprogressindicator along with bottomsheet in flutter?

2.2k Views Asked by At

i am using bottomsheet in my code and due to that it is not showing my circularprogressindicator when isLoading is true but else part of ternary operator is working perfectly. Is there anyother way to do that. Or where i am doing wrong in the code?

  (isLoading==true) ? Center(
    child: Container(
      height: 24,
      width: 24,
      child: CircularProgressIndicator(
        backgroundColor: CommonColors.primaryColor,
        strokeWidth: 1,
      ),
    ),
  )
      :
  Column(
    children: <Widget>[
      Expanded(
        child: ListView.separated(
          itemCount: clist.cartlist.length,
          itemBuilder: (BuildContext context, int index) {
            return _buildCartProduct(index);
          },
          separatorBuilder: (context, index) {
            return Divider(
              color: Colors.grey[300],
            );
          },
        ),
      ),
      SizedBox(
        height: 80,
      )
    ],
  ),
  bottomSheet: isLoading?Container():Container(
    height: 80.0,
    color: CommonColors.secondaryBackgroundColor,
    child: Column(crossAxisAlignment: CrossAxisAlignment.end,
      children: <Widget>[
        Container(margin: EdgeInsets.symmetric(horizontal: 16),child:
        Text('Total: \$${clist.getSubTotal()}',
          style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16),)),
        Expanded(
          child: FlatButton(onPressed: (){},
            color: CommonColors.primaryColor,
            child: Row(mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text(
                  'PLACE',
                  style: TextStyle(
                    color: CommonColors.secondaryBackgroundColor,
                    fontSize: 20.0,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ],
            ),
          ),
        ),
      ],
    ),
  ),
2

There are 2 best solutions below

1
Bassem Abd Allah On

in this part you're showing an empty container if loading

bottomSheet: isLoading?Container():Container(

so change it to be your CircularProgressIndicator

bottomSheet: isLoading ? CircularProgressIndicator():Container(
0
codrikaz On

simple put it the code!

static void customBotFtomSheet(BuildContext context) async {
    showModalBottomSheet<void>(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.vertical(top: Radius.circular(15.0)),
      ),
      backgroundColor: BrandColors.kWhite,
      elevation: 0,
      context: context,
      // showDragHandle: true,

      isScrollControlled: true,
      isDismissible: true,
      builder: (BuildContext context) {
        return Container(
          height: 100,
          width: MediaQuery.sizeOf(context).width,
            child: CircularProgressIndicator(),
        );
      },
    );
 }