How to display new android progress dialog in flutter plugin?

728 views Asked by At

I am building flutter plugin and try to show native progress dialog with the code below.

ProgressDialog progressDialog =new ProgressDialog(context);
progressDialog.setTitle("Downloading");
progressDialog.setMessage("Please wait while downloading map");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();   

And the dialog is displaying as below.

enter image description here

What I am expecting is default new android dialog when we create native android project like below.

enter image description here

What are the changes I need to do to make it work?

[Update] This is the default AndroidManifest.xml code

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.map_plugin">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
</manifest>

I have added application tag and added several style to this but none work

<application android:theme="@android:style/Theme.Material.Light.DarkActionBar"></application>   
3

There are 3 answers

1
Hardik Mehta On BEST ANSWER

In your styles.xml file

<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">@color/colorPrimary</item>
</style>

And to use it:

ProgressDialog progressDialog = new ProgressDialog(context, R.style.MyAlertDialogStyle);
progressDialog.setTitle("Downloading");
progressDialog.setMessage("Please wait while downloading map");
progressDialog.setCanceledOnTouchOutside(false);
progressDialog.show();  

Hope this will help you to achieve this

4
user18309290 On

Change theme in AndroidManifest.xml. See Styles and Themes for details.

<manifest ... />

    <application android:theme="<your theme>"
        ...>
...
    </application>
</manifest>

Or try to pass the theme in ProgressDialog(Context context, int theme) constructor.

1
kokoko On

you can use this library:

https://pub.dev/packages/sn_progress_dialog

or

showLoaderDialog(BuildContext context){
    AlertDialog alert=AlertDialog(
      content: new Row(
        children: [
          CircularProgressIndicator(),
          Container(margin: EdgeInsets.only(left:7),child:Text("Loading..." )),
        ],),
    );
    showDialog(barrierDismissible: false,
      context:context,
      builder:(BuildContext context){
        return alert;
      },
    );
  }

don't forget to dismiss when your data is fetched.

Navigator.pop(context);