Adding CircularProgressIndicator in dart code

I am a newbie in flutter development. I would like to add a circular progress indicator when start load the Webview and the progress is more than 10 and less than 99

hence, dismiss the progress indicator. I have tried many codes, but still, I can't able to do it, So I have to clean up all code, and for your reference, I am refering to this code:

   // we will determine progress here
   onProgressChanged: (InAppWebViewController controller, int progress){
   print("Current progress > $progress");
   // progress is 10 or more but not 99
   if(progress >= 10 && progress < 99){

   }else{

    }

 },

So, the Circular Progress Indicator will be hide/show according to this logic. can you help me, please?

The progress indicator should be placed in the middle of the screen.

Here is my full code:

    import 'package:flutter/material.dart';
    import 'package:flutter_inappwebview/flutter_inappwebview.dart';
    import 'package:permission_handler/permission_handler.dart';
    import 'package:splashscreen/splashscreen.dart';
    import 'package:url_launcher/url_launcher.dart';

    Future<void> main() async {

    WidgetsFlutterBinding.ensureInitialized();

    await Permission.camera.request();
    await Permission.microphone.request();

    runApp(MyApp());
}

class MyApp extends StatelessWidget {
 // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Bing Pay Splash Screen',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: SplashScreen2(),
    );
  }
}

class SplashScreen2 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return SplashScreen(
      seconds: 6,
      navigateAfterSeconds: new SecondScreen(),
      //title: new Text('Bing Pay',textScaleFactor: 2,),
      image: new Image.asset('assets/bing_pay_splash.png'),
      loadingText: Text('Loading app now...'),
      photoSize: 100.0,
      loaderColor: Colors.blue,

    );
  }


}

class SecondScreen extends StatefulWidget {

  @override
  SecondScreenState createState() => new SecondScreenState();

}

class SecondScreenState extends State<SecondScreen> {
  InAppWebViewController _webViewController;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
            title: Text("Bing Pay")
        ),

        body: Center(
            child: Column(children: <Widget>[
              Expanded(
                child: Container(
                  child: InAppWebView(
                      initialUrlRequest:
                      URLRequest(url: Uri.parse("https://bingpay.ng/app")),

                      initialOptions: InAppWebViewGroupOptions(
                        crossPlatform: InAppWebViewOptions(
                          mediaPlaybackRequiresUserGesture: false, ), ),


                      onWebViewCreated: (InAppWebViewController controller) {
                        _webViewController = controller;
                      },


                      // we will determine progress here
                      onProgressChanged: (InAppWebViewController controller, int progress){

                        print("Current progress > $progress");
                        // progress is 10 or more but not 99
                        if(progress >= 10 && progress < 99){

                        }else{

                        }

                      },

                      // should override url loading.
                    shouldOverrideUrlLoading: (InAppWebViewController control, NavigationAction action) async{

                        // Get the URL
                      var url = action.request.url.toString();


                       if(url.startsWith("intent://")){

                       if(await canLaunch(url)){
                         await launch(url);
                       }else{

                         print('Could not launch $url');
                       }

                     }

                        return NavigationActionPolicy.ALLOW;
                    },

                      androidOnPermissionRequest: (
                          InAppWebViewController controller, String origin,
                          List<String> resources) async {
                        return PermissionRequestResponse(resources: resources,
                            action: PermissionRequestResponseAction.GRANT);
                      }


                  ),
                ),
              ),
            ]))
    );
  }


}


Read more here: https://stackoverflow.com/questions/67386718/adding-circularprogressindicator-in-dart-code

Content Attribution

This content was originally published by njpollob at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: