Search code examples
flutterdartflutter-dependenciesflutter-web

flutter circular progressbar with navigator


I have two pages P1 and P2 .P1 has a button that navigates to P2. P2 has a function to list all pdf from the device. I want to show the circular progress bar with P1 button and want to navigate and remove the circular bar once all files get


Solution

  • This is just Example That can help you.

    // Test1 page

    import 'package:demostack/test2page.dart';
    import 'package:flutter/material.dart';
    
    class Test1Page extends StatelessWidget {
      const Test1Page({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: TextButton(
                onPressed: () {
    
                 // Navigat to Other Page
    
                  Navigator.of(context).push(MaterialPageRoute(
                    builder: (context) => const Test2Page(),
                  ));
                },
                child: const Text('goto 2',style: TextStyle(fontSize: 30),)),
          ),
        );
      }
    }
    

    //Test2Page

    import 'package:demostack/test3page.dart';
    import 'package:flutter/material.dart';
    
    class Test2Page extends StatefulWidget {
      const Test2Page({Key? key}) : super(key: key);
    
      @override
      _Test2PageState createState() => _Test2PageState();
    }
    
        class _Test2PageState extends State<Test2Page> {
        //one bool var to know is processing or not
        //you can make this variable when your files are processing
        bool isProgress=false;
        
          @override
          void initState() {
        
            Future.delayed(Duration(seconds: 3),(){
             setState(() {
                //make this variable true when you get your files
               isProgress=true;
             });
            });
            super.initState();
          }
          @override
          Widget build(BuildContext context) {
            return Scaffold(
              body: Center(
        
                //set this condition where you are showing your files.
                child:isProgress==false?CircularProgressIndicator(color: Colors.red,): TextButton(
                    onPressed: () => Navigator.of(context).push(MaterialPageRoute(
                      builder: (context) => const Test3Page(),
                    )),
                    child: const Text('goto 3',style: TextStyle(fontSize: 30))),
              ),
            );
          }
        }