some time delayed functon is shunt in flutter









up vote
-1
down vote

favorite












hello I tried to run code after received sms, if sms isn't reveived before 60s I show an alertdialog. Currently my problem is, when I send some sms ( about 20 ) my alert dialog is show directly after press the sms sending button without waiting the 60s of delay.



Here is my complet exemple:



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

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget
// This widget is the root of your application.
@override
Widget build(BuildContext context)
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new SettingsPage()
);


class SettingsPage extends StatefulWidget
@override
_SettingsPageState createState() => new _SettingsPageState();


class _SettingsPageState extends State<SettingsPage>
bool visibility_waiting;
String group_last_sms;
SmsMessage _lastMessage = new SmsMessage('', '');


@override
void initState()
super.initState();
visibility_waiting=false;
new SmsReceiver().onSmsReceived.listen((SmsMessage msg) //create an sms listener

if (msg.address == "your phone number") //for the test, I wait to receive my owm message to make action
setState(()
_lastMessage = msg;
);

RegExp regExp = new RegExp( // regexp function to extract particular string in the sms and make an action
r"(test)",
);
var match = regExp.firstMatch(_lastMessage.body); // listen the last sms
group_last_sms = match.group(1);
if (group_last_sms=="test")
setState(()
_changed(false, "waiting"); // hide visibility of text and circular progress indicator
visibility_waiting=false;
);


);


Widget build(BuildContext context)
return Scaffold(

body: Stack (


children: <Widget>[
_buildWidgetContent(), // widget with my raised button , to send test sms

visibility_waiting?Positioned( // when i press raised button , I show progres indicator, If "test" sms is received I hide circular progress indicator,

child: Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.lightBlue),
),
),


): new Container(),


visibility_waiting? // when i press raised button , I show text, If "test" sms is received I hide text,
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Column (
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Container(
padding: const EdgeInsets.all(80.0),),
Text('sending sms, please wait', style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 18.0,
)),
],
),
],
): new Container(),
],
)
);


void _changed(bool visibility, String field) // function for hide or show circular progress indicator
setState(()
if (field == "waiting")
visibility_waiting = visibility;


);


@override
Widget _buildWidgetContent( )

return new Scaffold(
appBar: new AppBar(
),
body: new Stack(
children: <Widget>[

new Center(
child : new RaisedButton(

onPressed: ()

visibility_waiting=true;
_changed(true, "waiting");
handleSignIn();

new SmsSender().sendSms(new SmsMessage(
"your phone number","test;" )
);

)

)
],
));


Future<Null> handleSignIn() async

await new Future.delayed(const Duration(seconds:20)); //wait the sms
if ( visibility_waiting ==true) // if sms is not received before 60s _chargement is true so I show an error dialog
setState(()
visibility_waiting =false;
_changed(false, "waiting");
erreurcommunication();

);





Future<Null>erreurcommunication() async // alerte dialog when I have waited more than 60s

await showDialog<String>(
context: context,
barrierDismissible: false,
child: new AlertDialog(
title: new Text("Problème de reseau"),
content: new SingleChildScrollView(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text("veuillez reessayer"),

new OutlineButton(
child: new Text('ok', style: TextStyle(color: Colors.black)),
onPressed: ()
setState(()
Navigator.pop(context);


);
,
highlightElevation: 4.0,
borderSide: new BorderSide(width: 3.0, color: Colors.grey.shade300),
highlightColor : Colors.white,
shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
),
Container ( padding: const EdgeInsets.all(2.0),),
],
),
),
)
);





You can copy past this code and try with your phone number. After about 20 press the delay function shunt the 60s of delays and show the alert dialog.










share|improve this question



























    up vote
    -1
    down vote

    favorite












    hello I tried to run code after received sms, if sms isn't reveived before 60s I show an alertdialog. Currently my problem is, when I send some sms ( about 20 ) my alert dialog is show directly after press the sms sending button without waiting the 60s of delay.



    Here is my complet exemple:



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

    void main() => runApp(new MyApp());

    class MyApp extends StatelessWidget
    // This widget is the root of your application.
    @override
    Widget build(BuildContext context)
    return new MaterialApp(
    title: 'Flutter Demo',
    theme: new ThemeData(
    primarySwatch: Colors.blue,
    ),
    home: new SettingsPage()
    );


    class SettingsPage extends StatefulWidget
    @override
    _SettingsPageState createState() => new _SettingsPageState();


    class _SettingsPageState extends State<SettingsPage>
    bool visibility_waiting;
    String group_last_sms;
    SmsMessage _lastMessage = new SmsMessage('', '');


    @override
    void initState()
    super.initState();
    visibility_waiting=false;
    new SmsReceiver().onSmsReceived.listen((SmsMessage msg) //create an sms listener

    if (msg.address == "your phone number") //for the test, I wait to receive my owm message to make action
    setState(()
    _lastMessage = msg;
    );

    RegExp regExp = new RegExp( // regexp function to extract particular string in the sms and make an action
    r"(test)",
    );
    var match = regExp.firstMatch(_lastMessage.body); // listen the last sms
    group_last_sms = match.group(1);
    if (group_last_sms=="test")
    setState(()
    _changed(false, "waiting"); // hide visibility of text and circular progress indicator
    visibility_waiting=false;
    );


    );


    Widget build(BuildContext context)
    return Scaffold(

    body: Stack (


    children: <Widget>[
    _buildWidgetContent(), // widget with my raised button , to send test sms

    visibility_waiting?Positioned( // when i press raised button , I show progres indicator, If "test" sms is received I hide circular progress indicator,

    child: Center(
    child: CircularProgressIndicator(
    valueColor: AlwaysStoppedAnimation<Color>(Colors.lightBlue),
    ),
    ),


    ): new Container(),


    visibility_waiting? // when i press raised button , I show text, If "test" sms is received I hide text,
    new Row(
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
    Column (
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
    new Container(
    padding: const EdgeInsets.all(80.0),),
    Text('sending sms, please wait', style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 18.0,
    )),
    ],
    ),
    ],
    ): new Container(),
    ],
    )
    );


    void _changed(bool visibility, String field) // function for hide or show circular progress indicator
    setState(()
    if (field == "waiting")
    visibility_waiting = visibility;


    );


    @override
    Widget _buildWidgetContent( )

    return new Scaffold(
    appBar: new AppBar(
    ),
    body: new Stack(
    children: <Widget>[

    new Center(
    child : new RaisedButton(

    onPressed: ()

    visibility_waiting=true;
    _changed(true, "waiting");
    handleSignIn();

    new SmsSender().sendSms(new SmsMessage(
    "your phone number","test;" )
    );

    )

    )
    ],
    ));


    Future<Null> handleSignIn() async

    await new Future.delayed(const Duration(seconds:20)); //wait the sms
    if ( visibility_waiting ==true) // if sms is not received before 60s _chargement is true so I show an error dialog
    setState(()
    visibility_waiting =false;
    _changed(false, "waiting");
    erreurcommunication();

    );





    Future<Null>erreurcommunication() async // alerte dialog when I have waited more than 60s

    await showDialog<String>(
    context: context,
    barrierDismissible: false,
    child: new AlertDialog(
    title: new Text("Problème de reseau"),
    content: new SingleChildScrollView(
    child: new Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
    new Text("veuillez reessayer"),

    new OutlineButton(
    child: new Text('ok', style: TextStyle(color: Colors.black)),
    onPressed: ()
    setState(()
    Navigator.pop(context);


    );
    ,
    highlightElevation: 4.0,
    borderSide: new BorderSide(width: 3.0, color: Colors.grey.shade300),
    highlightColor : Colors.white,
    shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
    ),
    Container ( padding: const EdgeInsets.all(2.0),),
    ],
    ),
    ),
    )
    );





    You can copy past this code and try with your phone number. After about 20 press the delay function shunt the 60s of delays and show the alert dialog.










    share|improve this question

























      up vote
      -1
      down vote

      favorite









      up vote
      -1
      down vote

      favorite











      hello I tried to run code after received sms, if sms isn't reveived before 60s I show an alertdialog. Currently my problem is, when I send some sms ( about 20 ) my alert dialog is show directly after press the sms sending button without waiting the 60s of delay.



      Here is my complet exemple:



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

      void main() => runApp(new MyApp());

      class MyApp extends StatelessWidget
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context)
      return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
      primarySwatch: Colors.blue,
      ),
      home: new SettingsPage()
      );


      class SettingsPage extends StatefulWidget
      @override
      _SettingsPageState createState() => new _SettingsPageState();


      class _SettingsPageState extends State<SettingsPage>
      bool visibility_waiting;
      String group_last_sms;
      SmsMessage _lastMessage = new SmsMessage('', '');


      @override
      void initState()
      super.initState();
      visibility_waiting=false;
      new SmsReceiver().onSmsReceived.listen((SmsMessage msg) //create an sms listener

      if (msg.address == "your phone number") //for the test, I wait to receive my owm message to make action
      setState(()
      _lastMessage = msg;
      );

      RegExp regExp = new RegExp( // regexp function to extract particular string in the sms and make an action
      r"(test)",
      );
      var match = regExp.firstMatch(_lastMessage.body); // listen the last sms
      group_last_sms = match.group(1);
      if (group_last_sms=="test")
      setState(()
      _changed(false, "waiting"); // hide visibility of text and circular progress indicator
      visibility_waiting=false;
      );


      );


      Widget build(BuildContext context)
      return Scaffold(

      body: Stack (


      children: <Widget>[
      _buildWidgetContent(), // widget with my raised button , to send test sms

      visibility_waiting?Positioned( // when i press raised button , I show progres indicator, If "test" sms is received I hide circular progress indicator,

      child: Center(
      child: CircularProgressIndicator(
      valueColor: AlwaysStoppedAnimation<Color>(Colors.lightBlue),
      ),
      ),


      ): new Container(),


      visibility_waiting? // when i press raised button , I show text, If "test" sms is received I hide text,
      new Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
      Column (
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
      new Container(
      padding: const EdgeInsets.all(80.0),),
      Text('sending sms, please wait', style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 18.0,
      )),
      ],
      ),
      ],
      ): new Container(),
      ],
      )
      );


      void _changed(bool visibility, String field) // function for hide or show circular progress indicator
      setState(()
      if (field == "waiting")
      visibility_waiting = visibility;


      );


      @override
      Widget _buildWidgetContent( )

      return new Scaffold(
      appBar: new AppBar(
      ),
      body: new Stack(
      children: <Widget>[

      new Center(
      child : new RaisedButton(

      onPressed: ()

      visibility_waiting=true;
      _changed(true, "waiting");
      handleSignIn();

      new SmsSender().sendSms(new SmsMessage(
      "your phone number","test;" )
      );

      )

      )
      ],
      ));


      Future<Null> handleSignIn() async

      await new Future.delayed(const Duration(seconds:20)); //wait the sms
      if ( visibility_waiting ==true) // if sms is not received before 60s _chargement is true so I show an error dialog
      setState(()
      visibility_waiting =false;
      _changed(false, "waiting");
      erreurcommunication();

      );





      Future<Null>erreurcommunication() async // alerte dialog when I have waited more than 60s

      await showDialog<String>(
      context: context,
      barrierDismissible: false,
      child: new AlertDialog(
      title: new Text("Problème de reseau"),
      content: new SingleChildScrollView(
      child: new Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
      new Text("veuillez reessayer"),

      new OutlineButton(
      child: new Text('ok', style: TextStyle(color: Colors.black)),
      onPressed: ()
      setState(()
      Navigator.pop(context);


      );
      ,
      highlightElevation: 4.0,
      borderSide: new BorderSide(width: 3.0, color: Colors.grey.shade300),
      highlightColor : Colors.white,
      shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
      ),
      Container ( padding: const EdgeInsets.all(2.0),),
      ],
      ),
      ),
      )
      );





      You can copy past this code and try with your phone number. After about 20 press the delay function shunt the 60s of delays and show the alert dialog.










      share|improve this question















      hello I tried to run code after received sms, if sms isn't reveived before 60s I show an alertdialog. Currently my problem is, when I send some sms ( about 20 ) my alert dialog is show directly after press the sms sending button without waiting the 60s of delay.



      Here is my complet exemple:



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

      void main() => runApp(new MyApp());

      class MyApp extends StatelessWidget
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context)
      return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
      primarySwatch: Colors.blue,
      ),
      home: new SettingsPage()
      );


      class SettingsPage extends StatefulWidget
      @override
      _SettingsPageState createState() => new _SettingsPageState();


      class _SettingsPageState extends State<SettingsPage>
      bool visibility_waiting;
      String group_last_sms;
      SmsMessage _lastMessage = new SmsMessage('', '');


      @override
      void initState()
      super.initState();
      visibility_waiting=false;
      new SmsReceiver().onSmsReceived.listen((SmsMessage msg) //create an sms listener

      if (msg.address == "your phone number") //for the test, I wait to receive my owm message to make action
      setState(()
      _lastMessage = msg;
      );

      RegExp regExp = new RegExp( // regexp function to extract particular string in the sms and make an action
      r"(test)",
      );
      var match = regExp.firstMatch(_lastMessage.body); // listen the last sms
      group_last_sms = match.group(1);
      if (group_last_sms=="test")
      setState(()
      _changed(false, "waiting"); // hide visibility of text and circular progress indicator
      visibility_waiting=false;
      );


      );


      Widget build(BuildContext context)
      return Scaffold(

      body: Stack (


      children: <Widget>[
      _buildWidgetContent(), // widget with my raised button , to send test sms

      visibility_waiting?Positioned( // when i press raised button , I show progres indicator, If "test" sms is received I hide circular progress indicator,

      child: Center(
      child: CircularProgressIndicator(
      valueColor: AlwaysStoppedAnimation<Color>(Colors.lightBlue),
      ),
      ),


      ): new Container(),


      visibility_waiting? // when i press raised button , I show text, If "test" sms is received I hide text,
      new Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
      Column (
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
      new Container(
      padding: const EdgeInsets.all(80.0),),
      Text('sending sms, please wait', style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 18.0,
      )),
      ],
      ),
      ],
      ): new Container(),
      ],
      )
      );


      void _changed(bool visibility, String field) // function for hide or show circular progress indicator
      setState(()
      if (field == "waiting")
      visibility_waiting = visibility;


      );


      @override
      Widget _buildWidgetContent( )

      return new Scaffold(
      appBar: new AppBar(
      ),
      body: new Stack(
      children: <Widget>[

      new Center(
      child : new RaisedButton(

      onPressed: ()

      visibility_waiting=true;
      _changed(true, "waiting");
      handleSignIn();

      new SmsSender().sendSms(new SmsMessage(
      "your phone number","test;" )
      );

      )

      )
      ],
      ));


      Future<Null> handleSignIn() async

      await new Future.delayed(const Duration(seconds:20)); //wait the sms
      if ( visibility_waiting ==true) // if sms is not received before 60s _chargement is true so I show an error dialog
      setState(()
      visibility_waiting =false;
      _changed(false, "waiting");
      erreurcommunication();

      );





      Future<Null>erreurcommunication() async // alerte dialog when I have waited more than 60s

      await showDialog<String>(
      context: context,
      barrierDismissible: false,
      child: new AlertDialog(
      title: new Text("Problème de reseau"),
      content: new SingleChildScrollView(
      child: new Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
      new Text("veuillez reessayer"),

      new OutlineButton(
      child: new Text('ok', style: TextStyle(color: Colors.black)),
      onPressed: ()
      setState(()
      Navigator.pop(context);


      );
      ,
      highlightElevation: 4.0,
      borderSide: new BorderSide(width: 3.0, color: Colors.grey.shade300),
      highlightColor : Colors.white,
      shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
      ),
      Container ( padding: const EdgeInsets.all(2.0),),
      ],
      ),
      ),
      )
      );





      You can copy past this code and try with your phone number. After about 20 press the delay function shunt the 60s of delays and show the alert dialog.







      flutter sms delay






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 17 hours ago

























      asked 18 hours ago









      Quentin Guichot

      899




      899






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          enter image description here
          I tried to isolate more the issue. I have remove the sms function and I add a delay to simulate the sms reception. Result : same issue,some time erreurcommunication() is call before 20s of delays.



           import 'package:flutter/material.dart';


          void main() => runApp(new MyApp());

          class MyApp extends StatelessWidget
          // This widget is the root of your application.
          @override
          Widget build(BuildContext context)
          return new MaterialApp(
          title: 'Flutter Demo',
          theme: new ThemeData(
          primarySwatch: Colors.blue,
          ),
          home: new SettingsPage()
          );


          class SettingsPage extends StatefulWidget
          @override
          _SettingsPageState createState() => new _SettingsPageState();


          class _SettingsPageState extends State<SettingsPage>
          bool visibility_waiting;


          @override
          void initState()
          super.initState();
          visibility_waiting=false;

          Widget build(BuildContext context)
          return Scaffold(

          body: Stack (


          children: <Widget>[
          _buildWidgetContent(), // widget with my raised button , to send test sms

          visibility_waiting?Positioned( // when i press raised button , I show progres indicator, If "test" sms is received I hide circular progress indicator,

          child: Center(
          child: CircularProgressIndicator(
          valueColor: AlwaysStoppedAnimation<Color>(Colors.lightBlue),
          ),
          ),


          ): new Container(),


          visibility_waiting? // when i press raised button , I show text, If "test" sms is received I hide text,
          new Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          Column (
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          new Container(
          padding: const EdgeInsets.all(80.0),),
          Text('sending sms, please wait', style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 18.0,
          )),
          ],
          ),
          ],
          ): new Container(),
          ],
          )
          );


          void _changed(bool visibility, String field) // function for hide or show circular progress indicator
          setState(()
          if (field == "waiting")
          visibility_waiting = visibility;


          );


          @override
          Widget _buildWidgetContent( )

          return new Scaffold(
          appBar: new AppBar(
          ),
          body: new Stack(
          children: <Widget>[

          new Center(
          child : new RaisedButton(
          onPressed: ()

          setState(()
          visibility_waiting=true;
          _changed(true, "waiting");
          handleSignIn1(); //waiting 2s before hide progress indicator
          );

          )

          )
          ],
          ));

          Future<Null> handleSignIn1() async

          await new Future.delayed(const Duration(seconds:2)); //simulate the sms received

          visibility_waiting =false;
          _changed(false, "waiting");
          handleSignIn2(); // waitig 20s before show error dialog. the issue = error dialog is show before 20s



          Future<Null> handleSignIn2() async

          await new Future.delayed(const Duration(seconds:20)); //wait the sms 20s
          if ( visibility_waiting ==true) // in this case visibility_waiting is always false before 20s, so erreurcommunication() can't be call. currently some time erreurcommunication() is call directly after press raisedbutton
          setState(()
          visibility_waiting =false;
          _changed(false, "waiting");
          erreurcommunication();

          );




          Future<Null>erreurcommunication() async // alerte dialog when I have waited more than 60s

          await showDialog<String>(
          context: context,
          barrierDismissible: false,
          child: new AlertDialog(
          title: new Text("Problème de reseau"),
          content: new SingleChildScrollView(
          child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          new Text("veuillez reessayer"),

          new OutlineButton(
          child: new Text('ok', style: TextStyle(color: Colors.black)),
          onPressed: ()
          setState(()
          Navigator.pop(context);


          );
          ,
          highlightElevation: 4.0,
          borderSide: new BorderSide(width: 3.0, color: Colors.grey.shade300),
          highlightColor : Colors.white,
          shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
          ),
          Container ( padding: const EdgeInsets.all(2.0),),
          ],
          ),
          ),
          )
          );







          share|improve this answer






















          • If I reduce the second delay, error is show more quickly. I think I need to close the timer or some thing like this or complet the timer. but I don't know how to do this
            – Quentin Guichot
            16 hours ago










          • I have create timer instead of delayed and problem seems to be solved with timer.cancel().
            – Quentin Guichot
            13 hours ago










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237167%2fsome-time-delayed-functon-is-shunt-in-flutter%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          enter image description here
          I tried to isolate more the issue. I have remove the sms function and I add a delay to simulate the sms reception. Result : same issue,some time erreurcommunication() is call before 20s of delays.



           import 'package:flutter/material.dart';


          void main() => runApp(new MyApp());

          class MyApp extends StatelessWidget
          // This widget is the root of your application.
          @override
          Widget build(BuildContext context)
          return new MaterialApp(
          title: 'Flutter Demo',
          theme: new ThemeData(
          primarySwatch: Colors.blue,
          ),
          home: new SettingsPage()
          );


          class SettingsPage extends StatefulWidget
          @override
          _SettingsPageState createState() => new _SettingsPageState();


          class _SettingsPageState extends State<SettingsPage>
          bool visibility_waiting;


          @override
          void initState()
          super.initState();
          visibility_waiting=false;

          Widget build(BuildContext context)
          return Scaffold(

          body: Stack (


          children: <Widget>[
          _buildWidgetContent(), // widget with my raised button , to send test sms

          visibility_waiting?Positioned( // when i press raised button , I show progres indicator, If "test" sms is received I hide circular progress indicator,

          child: Center(
          child: CircularProgressIndicator(
          valueColor: AlwaysStoppedAnimation<Color>(Colors.lightBlue),
          ),
          ),


          ): new Container(),


          visibility_waiting? // when i press raised button , I show text, If "test" sms is received I hide text,
          new Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          Column (
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          new Container(
          padding: const EdgeInsets.all(80.0),),
          Text('sending sms, please wait', style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 18.0,
          )),
          ],
          ),
          ],
          ): new Container(),
          ],
          )
          );


          void _changed(bool visibility, String field) // function for hide or show circular progress indicator
          setState(()
          if (field == "waiting")
          visibility_waiting = visibility;


          );


          @override
          Widget _buildWidgetContent( )

          return new Scaffold(
          appBar: new AppBar(
          ),
          body: new Stack(
          children: <Widget>[

          new Center(
          child : new RaisedButton(
          onPressed: ()

          setState(()
          visibility_waiting=true;
          _changed(true, "waiting");
          handleSignIn1(); //waiting 2s before hide progress indicator
          );

          )

          )
          ],
          ));

          Future<Null> handleSignIn1() async

          await new Future.delayed(const Duration(seconds:2)); //simulate the sms received

          visibility_waiting =false;
          _changed(false, "waiting");
          handleSignIn2(); // waitig 20s before show error dialog. the issue = error dialog is show before 20s



          Future<Null> handleSignIn2() async

          await new Future.delayed(const Duration(seconds:20)); //wait the sms 20s
          if ( visibility_waiting ==true) // in this case visibility_waiting is always false before 20s, so erreurcommunication() can't be call. currently some time erreurcommunication() is call directly after press raisedbutton
          setState(()
          visibility_waiting =false;
          _changed(false, "waiting");
          erreurcommunication();

          );




          Future<Null>erreurcommunication() async // alerte dialog when I have waited more than 60s

          await showDialog<String>(
          context: context,
          barrierDismissible: false,
          child: new AlertDialog(
          title: new Text("Problème de reseau"),
          content: new SingleChildScrollView(
          child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          new Text("veuillez reessayer"),

          new OutlineButton(
          child: new Text('ok', style: TextStyle(color: Colors.black)),
          onPressed: ()
          setState(()
          Navigator.pop(context);


          );
          ,
          highlightElevation: 4.0,
          borderSide: new BorderSide(width: 3.0, color: Colors.grey.shade300),
          highlightColor : Colors.white,
          shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
          ),
          Container ( padding: const EdgeInsets.all(2.0),),
          ],
          ),
          ),
          )
          );







          share|improve this answer






















          • If I reduce the second delay, error is show more quickly. I think I need to close the timer or some thing like this or complet the timer. but I don't know how to do this
            – Quentin Guichot
            16 hours ago










          • I have create timer instead of delayed and problem seems to be solved with timer.cancel().
            – Quentin Guichot
            13 hours ago














          up vote
          0
          down vote













          enter image description here
          I tried to isolate more the issue. I have remove the sms function and I add a delay to simulate the sms reception. Result : same issue,some time erreurcommunication() is call before 20s of delays.



           import 'package:flutter/material.dart';


          void main() => runApp(new MyApp());

          class MyApp extends StatelessWidget
          // This widget is the root of your application.
          @override
          Widget build(BuildContext context)
          return new MaterialApp(
          title: 'Flutter Demo',
          theme: new ThemeData(
          primarySwatch: Colors.blue,
          ),
          home: new SettingsPage()
          );


          class SettingsPage extends StatefulWidget
          @override
          _SettingsPageState createState() => new _SettingsPageState();


          class _SettingsPageState extends State<SettingsPage>
          bool visibility_waiting;


          @override
          void initState()
          super.initState();
          visibility_waiting=false;

          Widget build(BuildContext context)
          return Scaffold(

          body: Stack (


          children: <Widget>[
          _buildWidgetContent(), // widget with my raised button , to send test sms

          visibility_waiting?Positioned( // when i press raised button , I show progres indicator, If "test" sms is received I hide circular progress indicator,

          child: Center(
          child: CircularProgressIndicator(
          valueColor: AlwaysStoppedAnimation<Color>(Colors.lightBlue),
          ),
          ),


          ): new Container(),


          visibility_waiting? // when i press raised button , I show text, If "test" sms is received I hide text,
          new Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          Column (
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          new Container(
          padding: const EdgeInsets.all(80.0),),
          Text('sending sms, please wait', style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 18.0,
          )),
          ],
          ),
          ],
          ): new Container(),
          ],
          )
          );


          void _changed(bool visibility, String field) // function for hide or show circular progress indicator
          setState(()
          if (field == "waiting")
          visibility_waiting = visibility;


          );


          @override
          Widget _buildWidgetContent( )

          return new Scaffold(
          appBar: new AppBar(
          ),
          body: new Stack(
          children: <Widget>[

          new Center(
          child : new RaisedButton(
          onPressed: ()

          setState(()
          visibility_waiting=true;
          _changed(true, "waiting");
          handleSignIn1(); //waiting 2s before hide progress indicator
          );

          )

          )
          ],
          ));

          Future<Null> handleSignIn1() async

          await new Future.delayed(const Duration(seconds:2)); //simulate the sms received

          visibility_waiting =false;
          _changed(false, "waiting");
          handleSignIn2(); // waitig 20s before show error dialog. the issue = error dialog is show before 20s



          Future<Null> handleSignIn2() async

          await new Future.delayed(const Duration(seconds:20)); //wait the sms 20s
          if ( visibility_waiting ==true) // in this case visibility_waiting is always false before 20s, so erreurcommunication() can't be call. currently some time erreurcommunication() is call directly after press raisedbutton
          setState(()
          visibility_waiting =false;
          _changed(false, "waiting");
          erreurcommunication();

          );




          Future<Null>erreurcommunication() async // alerte dialog when I have waited more than 60s

          await showDialog<String>(
          context: context,
          barrierDismissible: false,
          child: new AlertDialog(
          title: new Text("Problème de reseau"),
          content: new SingleChildScrollView(
          child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          new Text("veuillez reessayer"),

          new OutlineButton(
          child: new Text('ok', style: TextStyle(color: Colors.black)),
          onPressed: ()
          setState(()
          Navigator.pop(context);


          );
          ,
          highlightElevation: 4.0,
          borderSide: new BorderSide(width: 3.0, color: Colors.grey.shade300),
          highlightColor : Colors.white,
          shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
          ),
          Container ( padding: const EdgeInsets.all(2.0),),
          ],
          ),
          ),
          )
          );







          share|improve this answer






















          • If I reduce the second delay, error is show more quickly. I think I need to close the timer or some thing like this or complet the timer. but I don't know how to do this
            – Quentin Guichot
            16 hours ago










          • I have create timer instead of delayed and problem seems to be solved with timer.cancel().
            – Quentin Guichot
            13 hours ago












          up vote
          0
          down vote










          up vote
          0
          down vote









          enter image description here
          I tried to isolate more the issue. I have remove the sms function and I add a delay to simulate the sms reception. Result : same issue,some time erreurcommunication() is call before 20s of delays.



           import 'package:flutter/material.dart';


          void main() => runApp(new MyApp());

          class MyApp extends StatelessWidget
          // This widget is the root of your application.
          @override
          Widget build(BuildContext context)
          return new MaterialApp(
          title: 'Flutter Demo',
          theme: new ThemeData(
          primarySwatch: Colors.blue,
          ),
          home: new SettingsPage()
          );


          class SettingsPage extends StatefulWidget
          @override
          _SettingsPageState createState() => new _SettingsPageState();


          class _SettingsPageState extends State<SettingsPage>
          bool visibility_waiting;


          @override
          void initState()
          super.initState();
          visibility_waiting=false;

          Widget build(BuildContext context)
          return Scaffold(

          body: Stack (


          children: <Widget>[
          _buildWidgetContent(), // widget with my raised button , to send test sms

          visibility_waiting?Positioned( // when i press raised button , I show progres indicator, If "test" sms is received I hide circular progress indicator,

          child: Center(
          child: CircularProgressIndicator(
          valueColor: AlwaysStoppedAnimation<Color>(Colors.lightBlue),
          ),
          ),


          ): new Container(),


          visibility_waiting? // when i press raised button , I show text, If "test" sms is received I hide text,
          new Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          Column (
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          new Container(
          padding: const EdgeInsets.all(80.0),),
          Text('sending sms, please wait', style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 18.0,
          )),
          ],
          ),
          ],
          ): new Container(),
          ],
          )
          );


          void _changed(bool visibility, String field) // function for hide or show circular progress indicator
          setState(()
          if (field == "waiting")
          visibility_waiting = visibility;


          );


          @override
          Widget _buildWidgetContent( )

          return new Scaffold(
          appBar: new AppBar(
          ),
          body: new Stack(
          children: <Widget>[

          new Center(
          child : new RaisedButton(
          onPressed: ()

          setState(()
          visibility_waiting=true;
          _changed(true, "waiting");
          handleSignIn1(); //waiting 2s before hide progress indicator
          );

          )

          )
          ],
          ));

          Future<Null> handleSignIn1() async

          await new Future.delayed(const Duration(seconds:2)); //simulate the sms received

          visibility_waiting =false;
          _changed(false, "waiting");
          handleSignIn2(); // waitig 20s before show error dialog. the issue = error dialog is show before 20s



          Future<Null> handleSignIn2() async

          await new Future.delayed(const Duration(seconds:20)); //wait the sms 20s
          if ( visibility_waiting ==true) // in this case visibility_waiting is always false before 20s, so erreurcommunication() can't be call. currently some time erreurcommunication() is call directly after press raisedbutton
          setState(()
          visibility_waiting =false;
          _changed(false, "waiting");
          erreurcommunication();

          );




          Future<Null>erreurcommunication() async // alerte dialog when I have waited more than 60s

          await showDialog<String>(
          context: context,
          barrierDismissible: false,
          child: new AlertDialog(
          title: new Text("Problème de reseau"),
          content: new SingleChildScrollView(
          child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          new Text("veuillez reessayer"),

          new OutlineButton(
          child: new Text('ok', style: TextStyle(color: Colors.black)),
          onPressed: ()
          setState(()
          Navigator.pop(context);


          );
          ,
          highlightElevation: 4.0,
          borderSide: new BorderSide(width: 3.0, color: Colors.grey.shade300),
          highlightColor : Colors.white,
          shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
          ),
          Container ( padding: const EdgeInsets.all(2.0),),
          ],
          ),
          ),
          )
          );







          share|improve this answer














          enter image description here
          I tried to isolate more the issue. I have remove the sms function and I add a delay to simulate the sms reception. Result : same issue,some time erreurcommunication() is call before 20s of delays.



           import 'package:flutter/material.dart';


          void main() => runApp(new MyApp());

          class MyApp extends StatelessWidget
          // This widget is the root of your application.
          @override
          Widget build(BuildContext context)
          return new MaterialApp(
          title: 'Flutter Demo',
          theme: new ThemeData(
          primarySwatch: Colors.blue,
          ),
          home: new SettingsPage()
          );


          class SettingsPage extends StatefulWidget
          @override
          _SettingsPageState createState() => new _SettingsPageState();


          class _SettingsPageState extends State<SettingsPage>
          bool visibility_waiting;


          @override
          void initState()
          super.initState();
          visibility_waiting=false;

          Widget build(BuildContext context)
          return Scaffold(

          body: Stack (


          children: <Widget>[
          _buildWidgetContent(), // widget with my raised button , to send test sms

          visibility_waiting?Positioned( // when i press raised button , I show progres indicator, If "test" sms is received I hide circular progress indicator,

          child: Center(
          child: CircularProgressIndicator(
          valueColor: AlwaysStoppedAnimation<Color>(Colors.lightBlue),
          ),
          ),


          ): new Container(),


          visibility_waiting? // when i press raised button , I show text, If "test" sms is received I hide text,
          new Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          Column (
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          new Container(
          padding: const EdgeInsets.all(80.0),),
          Text('sending sms, please wait', style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600, fontSize: 18.0,
          )),
          ],
          ),
          ],
          ): new Container(),
          ],
          )
          );


          void _changed(bool visibility, String field) // function for hide or show circular progress indicator
          setState(()
          if (field == "waiting")
          visibility_waiting = visibility;


          );


          @override
          Widget _buildWidgetContent( )

          return new Scaffold(
          appBar: new AppBar(
          ),
          body: new Stack(
          children: <Widget>[

          new Center(
          child : new RaisedButton(
          onPressed: ()

          setState(()
          visibility_waiting=true;
          _changed(true, "waiting");
          handleSignIn1(); //waiting 2s before hide progress indicator
          );

          )

          )
          ],
          ));

          Future<Null> handleSignIn1() async

          await new Future.delayed(const Duration(seconds:2)); //simulate the sms received

          visibility_waiting =false;
          _changed(false, "waiting");
          handleSignIn2(); // waitig 20s before show error dialog. the issue = error dialog is show before 20s



          Future<Null> handleSignIn2() async

          await new Future.delayed(const Duration(seconds:20)); //wait the sms 20s
          if ( visibility_waiting ==true) // in this case visibility_waiting is always false before 20s, so erreurcommunication() can't be call. currently some time erreurcommunication() is call directly after press raisedbutton
          setState(()
          visibility_waiting =false;
          _changed(false, "waiting");
          erreurcommunication();

          );




          Future<Null>erreurcommunication() async // alerte dialog when I have waited more than 60s

          await showDialog<String>(
          context: context,
          barrierDismissible: false,
          child: new AlertDialog(
          title: new Text("Problème de reseau"),
          content: new SingleChildScrollView(
          child: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
          new Text("veuillez reessayer"),

          new OutlineButton(
          child: new Text('ok', style: TextStyle(color: Colors.black)),
          onPressed: ()
          setState(()
          Navigator.pop(context);


          );
          ,
          highlightElevation: 4.0,
          borderSide: new BorderSide(width: 3.0, color: Colors.grey.shade300),
          highlightColor : Colors.white,
          shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0))
          ),
          Container ( padding: const EdgeInsets.all(2.0),),
          ],
          ),
          ),
          )
          );








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 16 hours ago

























          answered 17 hours ago









          Quentin Guichot

          899




          899











          • If I reduce the second delay, error is show more quickly. I think I need to close the timer or some thing like this or complet the timer. but I don't know how to do this
            – Quentin Guichot
            16 hours ago










          • I have create timer instead of delayed and problem seems to be solved with timer.cancel().
            – Quentin Guichot
            13 hours ago
















          • If I reduce the second delay, error is show more quickly. I think I need to close the timer or some thing like this or complet the timer. but I don't know how to do this
            – Quentin Guichot
            16 hours ago










          • I have create timer instead of delayed and problem seems to be solved with timer.cancel().
            – Quentin Guichot
            13 hours ago















          If I reduce the second delay, error is show more quickly. I think I need to close the timer or some thing like this or complet the timer. but I don't know how to do this
          – Quentin Guichot
          16 hours ago




          If I reduce the second delay, error is show more quickly. I think I need to close the timer or some thing like this or complet the timer. but I don't know how to do this
          – Quentin Guichot
          16 hours ago












          I have create timer instead of delayed and problem seems to be solved with timer.cancel().
          – Quentin Guichot
          13 hours ago




          I have create timer instead of delayed and problem seems to be solved with timer.cancel().
          – Quentin Guichot
          13 hours ago

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237167%2fsome-time-delayed-functon-is-shunt-in-flutter%23new-answer', 'question_page');

          );

          Post as a guest














































































          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

          Museum of Modern and Contemporary Art of Trento and Rovereto