Skip to content
This repository was archived by the owner on Nov 24, 2020. It is now read-only.

ProgressDialog CircularProgressIndicator stops animation when await future #47

Closed
bobosette opened this issue Apr 9, 2020 · 16 comments
Closed
Assignees

Comments

@bobosette
Copy link

Hi everybody. I have this problem with progressdailog: I have to load a big txt file (30mb) and I want to show the dialog till is loaded, but when I tap on the button the dialog starts showing and after 1 second the circularprogressindicator stops his animation; when the file is loaded (it takes almost 30 sec) the dialog hides correctly. How can I fix that?
Here is my code, the future:

Future<PatData> getPatData(String path) async { patData = await dataManager.getData(await file.readFile(path)); return patData; }

and the onTap:

pr.show().then((onValue) { getPatData(dataPath).then((value) { pr.hide(); Navigator.push( context, MaterialPageRoute( builder: (context) => GraphPage( patData: value, )), ); }); });

Can somebody help me?
Thank u!!!!

@fayaz07
Copy link
Owner

fayaz07 commented Apr 15, 2020

@bobosette , please use await pr.show();

@fayaz07 fayaz07 closed this as completed Apr 15, 2020
@bobosette
Copy link
Author

Sorry but also if I use await pr.show() I have the same issue

@fayaz07
Copy link
Owner

fayaz07 commented Apr 16, 2020

@bobosette did you update to the latest version v1.2.2

@bobosette
Copy link
Author

yes but nothing changes

@fayaz07 fayaz07 reopened this Apr 16, 2020
@fayaz07
Copy link
Owner

fayaz07 commented Apr 16, 2020

Can you post sample code along with the method where you're writing it?

@fayaz07 fayaz07 self-assigned this Apr 16, 2020
@bobosette
Copy link
Author

my onTap:

onTap: () async {
                      //pr.show();
                      if (dataPath == null) {
                        Future.delayed(Duration(seconds: 1)).then((value) {
                          //pr.hide().whenComplete(() {
                            Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (context) =>
                                      GraphPage(text: 'no data')),
                            );
                         // });
                        });
                      } else {

                        await pr.show().then((onValue) {
                          getPatData(dataPath).then((value) {
                            pr.hide();
                             Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (context) => GraphPage(
                                        patData: value,
                                      )),
                            );
                          });
                        });
                     }

the future:

Future<PatData> getPatData(String path) async {
    patData = await dataManager.getData(await file.readFile(path));
    return patData;
  }

@fayaz07
Copy link
Owner

fayaz07 commented Apr 16, 2020

where did you write the initialization of pr ?

@bobosette
Copy link
Author

bobosette commented Apr 16, 2020 via email

@fayaz07
Copy link
Owner

fayaz07 commented Apr 16, 2020

Sorry, I didn't get your issue. If possible please post whole .dart file, which will hep me better to solve your issue. Otherwise just use below code. I can't help you without clearly stating the issue

import 'package:flutter/material.dart';
import 'dart:async';

class Test extends StatefulWidget {
  @override
  _TestState createState() => _TestState();
}

class _TestState extends State<Test> {
  ProgressDialog pr;

 void loadData() async{
    await pr.show();
    // run your load operation here
    await pr.hide(); 
}

  @override
  Widget build(BuildContext context) {
    pr = ProgressDialog(context);
    loadData();
    return Container();
  }
}

@bobosette
Copy link
Author

bobosette commented Apr 16, 2020 via email

@fayaz07
Copy link
Owner

fayaz07 commented Apr 16, 2020

How can I reproduce the issue if you're not proving me basic code snippet

@bobosette
Copy link
Author

Sorry I didn't read the all mail and I lost the last part of the message.
Here it is:

import 'package:drawer_example/class/aad_oauth_manager.dart';
import 'package:drawer_example/class/data_manager.dart';
import 'package:drawer_example/pages/graphpage.dart';
import 'package:drawer_example/routes/routes.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:drawer_example/class/file_manager.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:progress_dialog/progress_dialog.dart';
import 'package:shared_preferences/shared_preferences.dart';


class AppDrawer extends StatefulWidget {
  @override
  _AppDrawerState createState() => _AppDrawerState();
}

class _AppDrawerState extends State<AppDrawer> {
  
  String name;
  String surname;
  String role;
  String address;
  String image = 'images/user.png';
  double headerHeight;
  String dataPath;
  PatData patData;
  ProgressDialog pr;

//SHARE PREFS--------------------------------------------------------------
 
  Future<Null> getSharedPrefs() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    setState(() {
      name = prefs.getString("name");
      surname = prefs.getString('surname');
      role = prefs.getString('role');
      address = prefs.getString('address');

      switch (prefs.getString('role')) {
        case 'Doctor':
          image = 'images/doctor.png';
          break;
        case 'Admin':
          image = 'images/admin.jpg';
          break;
        default:
          image = 'images/user.png';
          break;
      }
    });
  }

  Future<Null> getPath() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    setState(() {
      dataPath = prefs.getString('path');
    });
  }

  Future<Null> clearPrefs() async {
    SharedPreferences prefs = await SharedPreferences.getInstance();
    prefs.clear();
  }
//-------------------------------------------------------------------------------


  final AadOAuth oauth = AadOAuth();

  void logout() async {
    await oauth.logout();
    //showMessage("Logged out");
  }
  //-----------------------------------------------------------------------------------

  FileManager file = new FileManager();
  DataManager dataManager = new DataManager();

  Future<PatData> getPatData(String path) async {
   
    patData = await dataManager.getData(await file.readFile(path));
  
    return patData;
  }
  //----------------------------------------------------------------------------------

  @override
  void initState() {
    super.initState();
    getSharedPrefs();
    getPath();
  }

  @override
  Widget build(BuildContext context) {
    pr = new ProgressDialog(context,
        type: ProgressDialogType.Normal, isDismissible: true);
    pr.style(
        message: 'Charts Data Loading',
        borderRadius: 10.0,
        backgroundColor: Colors.white,
        progressWidget: CircularProgressIndicator(
          strokeWidth: 3.0,
        ),
        elevation: 10.0,
        insetAnimCurve: Curves.easeInOut,
        progress: 0.0,
        maxProgress: 100.0,
        progressTextStyle: TextStyle(
            color: Colors.black, fontSize: 13.0, fontWeight: FontWeight.w400),
        messageTextStyle: TextStyle(
            color: Colors.black, fontSize: 19.0, fontWeight: FontWeight.w600));

    return Drawer(
        child: Container(
            child: ListView(padding: EdgeInsets.zero, children: <Widget>[
      _createHeader(),
      Container(
          height: MediaQuery.of(context).size.height - headerHeight,
          decoration: BoxDecoration(
            color: Colors.white,
          ),
          child: SingleChildScrollView(
            scrollDirection: Axis.vertical,
            child: Column(
              children: <Widget>[
                _createDrawerItem(
                    icon: FontAwesomeIcons.home,
                    text: 'Home',
                    onTap: () =>
                        Navigator.pushReplacementNamed(context, Routes.home)
                   
                    ),
                _createDrawerItem(
                    icon: FontAwesomeIcons.bluetoothB,
                    text: 'Connect to Device',
                    onTap: () =>
                        Navigator.pushReplacementNamed(context, Routes.connect)
                   
                    ),
                _createDrawerItem(
                    icon: FontAwesomeIcons.usb,
                    text: 'Select Data from Storage',
                    onTap: () =>
                      
                        Navigator.pushReplacementNamed(context, Routes.data)
                   
                    ),
                _createDrawerItem(
                    icon: FontAwesomeIcons.chartLine,
                    text: 'Graph',
                    onTap: () async {
                      
                      if (dataPath == null) {
                        Future.delayed(Duration(seconds: 1)).then((value) {
                          
                            Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (context) =>
                                      GraphPage(text: 'no data')),
                            );
                       
                        });
                      } else {

                        await pr.show().then((onValue) {
                          getPatData(dataPath).then((value) {
                            pr.hide();
                             Navigator.push(
                              context,
                              MaterialPageRoute(
                                  builder: (context) => GraphPage(
                                        patData: value,
                                      )),
                            );
                          });
                        });
                        
                      }
                    }

                    ),
                _createDrawerDisabledItem(
                    icon: FontAwesomeIcons.calculator,
                    text: 'Analysis',
                    onTap: () =>
                        Navigator.pushReplacementNamed(context, Routes.analysis)
                   
                    ),
                _createDrawerDisabledItem(
                    icon: FontAwesomeIcons.pills,
                    text: 'Set ON/OFF',
                    onTap: () =>
                        Navigator.pushReplacementNamed(context, Routes.status)
                   
                    ),
                _createDrawerItem(
                    icon: FontAwesomeIcons.clipboard,
                    text: 'Clipboard',
                    onTap: () => Navigator.pushReplacementNamed(
                        context, Routes.clipboard)
                    
                    ),
                _createDrawerItem(
                    icon: FontAwesomeIcons.signOutAlt,
                    text: 'Logout',
                    onTap: () {
                      Navigator.pushReplacementNamed(context, Routes.logout);

                      FileManager file = new FileManager();
                    
                      String log = 'Logout: $role $name $surname;\n\n';
                      String logName = 'log.txt';
                      file.writeLogFile(DateTime.now(), log, logName);
                     
                      clearPrefs();
                      
                      file.deleteLocalDirFile('file.txt');
                      logout();
                    }),
                _createDrawerDisabledItem(
                    icon: FontAwesomeIcons.question,
                    text: 'Help',
                    onTap: () =>
                        Navigator.pushReplacementNamed(context, Routes.help)
                 
                    )
              ],
            ),
          ))
    ])));
  }

  Widget _createDrawerItem(
      {IconData icon, String text, GestureTapCallback onTap}) {
    return ListTile(
      title: Row(
        children: <Widget>[
          Icon(icon),
          Padding(
            padding: EdgeInsets.only(left: 8.0),
            child: Text(text),
          )
        ],
      ),
      onTap: onTap,
    );
  }

  Widget _createDrawerDisabledItem(
      {IconData icon, String text, GestureTapCallback onTap}) {
    return ListTile(
      title: Row(
        children: <Widget>[
          Icon(
            icon,
            color: Colors.grey,
          ),
          Padding(
            padding: EdgeInsets.only(left: 8.0),
            child: Text(
              text,
              style: TextStyle(color: Colors.grey),
            ),
          )
        ],
      ),
    );
  }

  Widget _createHeader() {
    Widget child;
    if (MediaQuery.of(context).orientation == Orientation.portrait) {
      headerHeight = 200;
      child = _portraitView(headerHeight);
    } else {
      headerHeight = 110;
      child = _landscapeView(headerHeight);
    }

    return child;
  }

  Widget _portraitView(double h) {
    return Container(
        height: h,
        child: UserAccountsDrawerHeader(
            accountName: Text('$role\n$name $surname'),
            accountEmail: Text('$address'),
            decoration: BoxDecoration(color: Colors.blueGrey[900]),
            currentAccountPicture: CircleAvatar(
                backgroundColor: Colors.white,
                foregroundColor: Colors.blueGrey[900],
                backgroundImage: AssetImage(image))));
  }

  Widget _landscapeView(double h) {
    return Container(
        height: h,
        child: UserAccountsDrawerHeader(
          accountName: Text('$role\n$name $surname'),
          accountEmail: Text('$address'),
          decoration: BoxDecoration(color: Colors.blueGrey[900]),
        ));
  }
} 

@bobosette
Copy link
Author

Hi @fayaz07. some news?? Didn't find anything??

@fayaz07
Copy link
Owner

fayaz07 commented May 9, 2020

@bobosette Can you please give me a shorter version of your code, that involves just the progressDialog, stuff

@bobosette
Copy link
Author

bobosette commented May 9, 2020 via email

@fayaz07
Copy link
Owner

fayaz07 commented May 9, 2020

Thanks, I am closing the issue now. Feel free to reopen for more questions

@fayaz07 fayaz07 closed this as completed May 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants