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.
flutter sms delay
add a comment |
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.
flutter sms delay
add a comment |
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.
flutter sms delay
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
flutter sms delay
edited 17 hours ago
asked 18 hours ago
Quentin Guichot
899
899
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
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),),
],
),
),
)
);
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
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
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),),
],
),
),
)
);
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
add a comment |
up vote
0
down vote
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),),
],
),
),
)
);
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
add a comment |
up vote
0
down vote
up vote
0
down vote
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),),
],
),
),
)
);
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),),
],
),
),
)
);
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password