error with speech to text in flutter while buiding for web - flutter

I am trying to build a speech to text app in flutter(using dart) . I get this error when I run however there are no issues with the code as far as I can tell. I've pasted the entire code below.
The error I am getting is when the onListen Handler is called. It points to an error in the speech to text package which isn't even my code. pls see image and error below.
TypeError: result[$item] is not a function
at speech_to_text_web.SpeechToTextPlugin.new.[_onResult] (http://localhost:53227/packages/speech_to_text/speech_to_text_web.dart.lib.js:143:36)
at http://localhost:53227/packages/speech_to_text/speech_to_text_web.dart.lib.js:97:98
at Object._checkAndCall (http://localhost:53227/dart_sdk.js:5242:16)
at Object.dcall (http://localhost:53227/dart_sdk.js:5247:17)
at SpeechRecognition.<anonymous> (http://localhost:53227/dart_sdk.js:100617:100)
import 'package:flutter/material.dart';
import 'package:speech_to_text/speech_to_text.dart' as stt;
import 'package:avatar_glow/avatar_glow.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter voice',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.red,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: SpeechScreen(),
);
}
}
class SpeechScreen extends StatefulWidget {
#override
_SpeechScreenState createState() => _SpeechScreenState();
}
class _SpeechScreenState extends State<SpeechScreen> {
stt.SpeechToText _speech = stt.SpeechToText();
bool _isListening = false;
String _text = 'Press the button and start speaking';
double _confidence = 1.0;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Confidence: ${(_confidence * 100.0).toStringAsFixed(1)}%'),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: AvatarGlow(
animate: _isListening,
glowColor: Theme.of(context).primaryColor,
endRadius: 75.0,
duration: const Duration(milliseconds: 2000),
repeatPauseDuration: const Duration(milliseconds: 100),
repeat: true,
child: FloatingActionButton(
onPressed: _listen,
child: Icon(_isListening ? Icons.mic : Icons.mic_none),
),
),
body: SingleChildScrollView(
reverse: true,
child: Container(
padding: const EdgeInsets.fromLTRB(30.0, 30.0, 30.0, 150.0),
child: Text(
_text,
style: const TextStyle(
fontSize: 32.0,
color: Colors.black,
fontWeight: FontWeight.w400,
),
),
),
),
);
}
void _listen() async {
if (!_isListening) {
bool available = await _speech.initialize(
onStatus: (val) => print('onStatus: $val'),
onError: (val) => print('onError: $val'),
);
if (available) {
setState(() => _isListening = true);
_speech.listen(
onResult: (val) => setState(() {
_text = val.recognizedWords;
if (val.hasConfidenceRating && val.confidence > 0) {
_confidence = val.confidence;
}
}));
}
} else {
setState(() => _isListening = false);
_speech.stop();
}
}
}
Error

Related

Missing concrete implementation of 'State.build'

I am in the learning stage of flutter and facing errors. I am watching a course on Udemy. I am trying to build a Personal Expense Tracker. It's a fundamental project but, as I already told I am currently learning and am facing an error. Any help would be appreciated.
This is the code of my main.dart file:
import 'package:flutter/material.dart';
import './widgets/transaction_list.dart';
import './widgets/new_transactions.dart';
import './widgets/chart.dart';
import './models/transaction.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
final ThemeData theme = ThemeData(
primarySwatch: Colors.primaries[1],
errorColor: Colors.red,
fontFamily: 'Quicksand',
);
return MaterialApp(
title: 'Expense Planner',
theme: theme.copyWith(
colorScheme: theme.colorScheme.copyWith(secondary: Colors.amber),
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final List<Transaction> _userTransactions = [];
List<Transaction> get _recentTransactions {
return _userTransactions.where((tx) {
return tx.date.isAfter(
DateTime.now().subtract(
Duration(days: 7),
),
);
}).toList();
}
void _addNewTransaction(
String txTitle, double txAmount, DateTime chosenDate) {
final newTx = Transaction(
title: txTitle,
amount: txAmount,
date: chosenDate,
id: DateTime.now().toString(),
);
setState(() {
_userTransactions.add(newTx);
});
}
void _startAddNewTransaction(BuildContext ctx) {
showModalBottomSheet(
context: ctx,
builder: (_) {
return GestureDetector(
onTap: () {},
child: NewTransaction(_addNewTransaction),
behavior: HitTestBehavior.opaque,
);
},
);
}
void _deleteTransaction(String id) {
setState(() {
_userTransactions.removeWhere((tx) => tx.id == id);
{
;
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
'Expense Planner',
style: TextStyle(
fontFamily: 'OpenSans',
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
actions: <Widget>[
IconButton(
icon: Icon(Icons.add),
onPressed: () => _startAddNewTransaction(context),
),
],
),
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Chart(_recentTransactions),
TransactionList(_userTransactions, _deleteTransaction),
],
),
),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerFloat,
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () => _startAddNewTransaction(context),
),
);
}
});
}
}
There's some error in the _MyHomePageState class. it shows the following error
Missing concrete implementation of 'State.build'.
Try implementing the missing method, or make the class abstract.
However when I try to make the _MyHomePageState class abstract it shows the following:
Abstract classes can't be instantiated.
Try creating an instance of a concrete subtype.
Thanks & Regards,
Harshit Chitkara
I think 'home: MyHomePage(),' is waiting for a Widget. You have to build a Widget arround the List. After that you probably need a Scaffold inside the Widget.
#override
Widget build(BuildContext context) {
return Scaffold(
child: List<Transaction> get _recentTransactions {
return _userTransactions.where((tx) {
return tx.date.isAfter(
DateTime.now().subtract(
Duration(days: 7),
),
);
}).toList();
}
);
}
This should fix the current problem, but you can't have a return inside a return.

When I use PreferredSizeWidget in flutter I got some error with the CupertinoNavigationBar?

**main.dart**
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import './widgets/transaction_list.dart';
import './widgets/new_transaction.dart';
import './widgets/chart.dart';
import './models/transaction.dart';
void main() {
// WidgetsFlutterBinding.ensureInitialized();
// SystemChrome.setPreferredOrientations([
// DeviceOrientation.portraitUp,
// DeviceOrientation.portraitDown,
// ]);
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Personal Expenses',
home: MyHomePage(),
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.purple,
accentColor: Colors.amber,
fontFamily: "Quicksand",
textTheme: ThemeData.light().textTheme.copyWith(
headline6: TextStyle(
fontFamily: "OpenSans",
fontWeight: FontWeight.bold,
fontSize: 18,
),
button: TextStyle(color: Colors.white),
),
appBarTheme: AppBarTheme(
titleTextStyle: TextStyle(
fontFamily: "OpenSans",
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
),
);
}
}
class MyHomePage extends StatefulWidget {
// late String titleInput;
// late String amountInput;
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final List<Transaction> _userTransactions = [];
List<Transaction> get _recentTransaction {
return _userTransactions.where((tx) {
return tx.date.isAfter(
DateTime.now().subtract(
Duration(days: 7),
),
);
}).toList();
}
bool _showChart = false;
void _addNewTransaction(
String txTitle, double txAmount, DateTime chosenDate) {
final newTx = Transaction(
title: txTitle,
amount: txAmount,
id: DateTime.now().toString(),
date: chosenDate,
);
setState(() {
_userTransactions.add(newTx);
});
}
void _startAddNewTransaction(BuildContext ctx) {
showModalBottomSheet(
context: ctx,
builder: (_) {
return GestureDetector(
onTap: () {},
child: NewTransaction(_addNewTransaction),
behavior: HitTestBehavior.opaque,
);
},
);
}
void _deleteTransaction(String id) {
setState(() {
_userTransactions.removeWhere((tx) {
return tx.id == id;
});
});
}
#override
Widget build(BuildContext context) {
final mediaQuery = MediaQuery.of(context);
final isLandScape = mediaQuery.orientation == Orientation.landscape;
final PreferredSizeWidget appBar = Platform.isIOS
? CupertinoNavigationBar(
middle: Text(
"Personal Expenses",
),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
GestureDetector(
child: Icon(CupertinoIcons.add),
onTap: () => _startAddNewTransaction(context),
)
],
),
)
: AppBar(
title: Text(
'Personal Expenses',
),
actions: <Widget>[
IconButton(
onPressed: () => _startAddNewTransaction(context),
icon: Icon(Icons.add),
)
],
);
final txListWidget = Container(
height: (mediaQuery.size.height -
appBar.preferredSize.height -
mediaQuery.padding.top) *
0.7,
child: TransactionList(_userTransactions, _deleteTransaction),
);
final pageBody = SingleChildScrollView(
child: Column(
// mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
if (isLandScape)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Show chart"),
Switch.adaptive(
activeColor: Theme.of(context).accentColor,
value: _showChart,
onChanged: (value) {
setState(() {
_showChart = value;
});
},
),
],
),
if (!isLandScape)
Container(
height: (mediaQuery.size.height -
appBar.preferredSize.height -
mediaQuery.padding.top) *
0.3,
child: Chart(_recentTransaction),
),
if (!isLandScape) txListWidget,
if (isLandScape)
_showChart
? Container(
height: (mediaQuery.size.height -
appBar.preferredSize.height -
mediaQuery.padding.top) *
0.7,
child: Chart(_recentTransaction),
)
: txListWidget,
],
),
);
return Platform.isIOS
? CupertinoPageScaffold(
child: pageBody,
navigationBar: appBar,
)
: Scaffold(
appBar: appBar,
body: pageBody,
floatingActionButtonLocation:
FloatingActionButtonLocation.centerFloat,
floatingActionButton: Platform.isIOS
? Container()
: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () => _startAddNewTransaction(context),
),
);
}
}
While I was using the final PreferredSizeWidget appBar = Platforn.isISO ? CupertinoNavigationBar() : AppBar();
it shows me the error in this and also in CupertinoPageScaffold(child: (), navigationBar: appBar).
The error shows me in the code is: A value of type 'Widget' can't be assigned to a variable of type 'PreferredSizeWidget'.
Try changing the type of the variable, or casting the right-hand type to 'PreferredSizeWidget'.
How can I solve this error ?
I recommend you create a separate AppbarTop Widget for yourself. The basis for doing this is in the snippet below, add your own logic and assign this to the appBar property of your Scaffold.
import 'package:flutter/material.dart';
class AppbarTop extends StatelessWidget implements PreferredSizeWidget {
const AppbarTop();
#override
Widget build(BuildContext context) {
return Platform.isIOS ? CupertinoNavigationBar() : AppBar();
}
#override
Size get preferredSize => Size.fromHeight(AppBar().preferredSize.height);
}

Flutter - Change text input type and input formatters dynamically on tap

I want to change the text input type and input formatters of a text field dynamically on tap. But the problem is once the text input type is done it is not changed on tap whereas the label text acts as expected.
I have done like below
bool joinlinkname = false;
joinchanged() {
if (joinlinkname == false) {
setState(() {
joinlinkname = true;
});
} else {
setState(() {
joinlinkname = false;
});
}
}
TextField(
keyboardType: joinlinkname? TextInputType.text : TextInputType.phone,
labelText: joinlinkname ? 'num' : "text",
inputFormatters: [joinlinkname ?
FilteringTextInputFormatter.allow(RegExp('[azAZ09]')):FilteringTextInputFormatter.allow(RegExp('[0-9]')),
],
),
GestureDetector(
onTap: () {
joinchanged();
},
child: Text(joinlinkname ? 'number' : 'text',
style: TextStyle(
color: Colors.blue,
fontSize: 12,
),
),
),
Please can anyone tell how to do it?
You can copy paste run full code below
You can use ValueListenableBuilder and ValueNotifier
You also need FocusNode to control keyboard
You can see working demo below
code snippet
final ValueNotifier<bool> joinlinkname = ValueNotifier<bool>(false);
...
joinchanged() async {
FocusManager.instance.primaryFocus.unfocus();
joinlinkname.value = !joinlinkname.value;
await Future.delayed(Duration(milliseconds: 500), () {});
myFocusNode.requestFocus();
}
...
ValueListenableBuilder(
builder: (BuildContext context, bool value, Widget child) {
return Column(
children: [
GestureDetector(
onTap: () {
joinchanged();
},
child: Text(
joinlinkname.value ? 'number' : 'text',
style: TextStyle(
color: Colors.blue,
fontSize: 12,
),
),
),
TextField(
focusNode: myFocusNode,
keyboardType: joinlinkname.value
? TextInputType.phone
working demo
full code
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final ValueNotifier<bool> joinlinkname = ValueNotifier<bool>(false);
FocusNode myFocusNode;
#override
void initState() {
super.initState();
myFocusNode = FocusNode();
}
#override
void dispose() {
myFocusNode.dispose();
super.dispose();
}
joinchanged() async {
FocusManager.instance.primaryFocus.unfocus();
joinlinkname.value = !joinlinkname.value;
await Future.delayed(Duration(milliseconds: 500), () {});
myFocusNode.requestFocus();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text(widget.title)),
body: Center(
child: ValueListenableBuilder(
builder: (BuildContext context, bool value, Widget child) {
return Column(
children: [
GestureDetector(
onTap: () {
joinchanged();
},
child: Text(
joinlinkname.value ? 'number' : 'text',
style: TextStyle(
color: Colors.blue,
fontSize: 12,
),
),
),
TextField(
focusNode: myFocusNode,
keyboardType: joinlinkname.value
? TextInputType.phone
: TextInputType.text,
decoration: InputDecoration(
labelText: joinlinkname.value ? 'num' : "text",
),
inputFormatters: [
joinlinkname.value
? FilteringTextInputFormatter.allow(RegExp('[0-9]'))
: FilteringTextInputFormatter.allow(RegExp('[azAZ09]')),
],
),
],
);
},
valueListenable: joinlinkname,
),
),
);
}
}

Flutter: How to user a DropDownButton with provider?

I have a dropDownButton where i select the theme for the entire app. I have tried two ways of actually trying to fix this. First one was using the commented line "Provider.of(context).toggleTheme();" in the "setState". Had to make the "listen" option "false" as advised in another thread but it was not working. And the second one was to just call the "toggleTheme()" inside the "Themes.dart" in order to notify listeners that way. What would be a correct implementation for a Dropdownbutton like this.
MainScreen.dart
import 'package:flutter/material.dart';
import 'package:thisismylastattempt/Misc/Themes.dart';
import 'package:provider/provider.dart';
class MainScreen extends StatefulWidget {
static const id = "main_screen";
#override
_MainScreenState createState() => _MainScreenState();
}
class ThemeOptions{
final Color themeColor;
final ThemeType enumTheme;
ThemeOptions({this.themeColor, this.enumTheme});
void callParentTheme(){
ThemeModel().changeEnumValue(enumTheme);
}
}
class _MainScreenState extends State<MainScreen> {
List<ThemeOptions> themes = [
ThemeOptions(themeColor: Colors.teal, enumTheme: ThemeType.Teal),
ThemeOptions(themeColor: Colors.green, enumTheme: ThemeType.Green),
ThemeOptions(themeColor: Colors.lightGreen, enumTheme: ThemeType.LightGreen),
];
ThemeOptions dropdownValue;
#override
void initState() {
dropdownValue = themes[0];
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('MainScreen'),
),
body: Column(
children: <Widget>[
Container(
child: DropdownButton<ThemeOptions>(
value: dropdownValue,
icon: Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
style: TextStyle(
color: Colors.deepPurple
),
underline: Container(
height: 0.0,
color: Colors.deepPurpleAccent,
),
onChanged: (ThemeOptions newValue) {
setState(() {
dropdownValue = newValue;
dropdownValue.callParentTheme();
print(newValue.themeColor);
//Provider.of<ThemeModel>(context).toggleTheme();
});
},
items: themes.map((ThemeOptions colorThemeInstance) {
return DropdownMenuItem<ThemeOptions>(
value: colorThemeInstance,
child: CircleAvatar(
backgroundColor: colorThemeInstance.themeColor,
),
);
})
.toList(),
),
),
SizedBox(height: 20.0,),
],
),
);
}
}
Themes.dart
import 'package:flutter/material.dart';
enum ThemeType {Teal, Green, LightGreen}
ThemeData tealTheme = ThemeData.light().copyWith(
primaryColor: Colors.teal.shade700,
appBarTheme: AppBarTheme(
color: Colors.teal.shade700,
),
);
ThemeData greenTheme = ThemeData.light().copyWith(
primaryColor: Colors.green.shade700,
appBarTheme: AppBarTheme(
color: Colors.green.shade700,
),
);
ThemeData lightGreenTheme = ThemeData.light().copyWith(
primaryColor: Colors.lightGreen.shade700,
appBarTheme: AppBarTheme(
color: Colors.lightGreen.shade700,
),
);
class ThemeModel extends ChangeNotifier {
ThemeData currentTheme = tealTheme;
ThemeType _themeType = ThemeType.Teal;
toggleTheme() {
if (_themeType == ThemeType.Teal) {
currentTheme = tealTheme;
_themeType = ThemeType.Teal;
print('teal');
notifyListeners();
}
if (_themeType == ThemeType.Green) {
currentTheme = greenTheme;
_themeType = ThemeType.Green;
print('green');
notifyListeners();
}
if (_themeType == ThemeType.LightGreen) {
currentTheme = lightGreenTheme;
_themeType = ThemeType.LightGreen;
print('lightGreen');
notifyListeners();
}
}
ThemeType getEnumValue(){
return _themeType;
}
void changeEnumValue(ThemeType newThemeType){
_themeType = newThemeType;
toggleTheme();
}
}
main.dart
void main() => runApp(ChangeNotifierProvider<ThemeModel>(
create: (BuildContext context) => ThemeModel(), child: MyApp()));
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return StreamProvider<User>.value(
value: AuthService().user,
child: MaterialApp(
theme: Provider.of<ThemeModel>(context).currentTheme,
title: 'Flutter Demo',
initialRoute: MainScreen.id,
routes: {
Wrapper.id: (context) => Wrapper(),
LoginPage.id: (context) => LoginPage(),
Registration.id: (context) => Registration(),
MainScreen.id: (context) => MainScreen(),
SwitchAuthenticationState.id: (context) =>
SwitchAuthenticationState(),
},
),
);
}
}
I managed to make it work by calling the changeEnumValue from the Provider in the callParentTheme of your ThemeOptionsclass :
class ThemeOptions {
final Color themeColor;
final ThemeType enumTheme;
ThemeOptions({this.themeColor, this.enumTheme});
// void callParentTheme() {
// ThemeModel().changeEnumValue(enumTheme);
void callParentTheme(context) {
Provider.of<ThemeModel>(context, listen: false).changeEnumValue(enumTheme);
}
call the method with the context in your DropDown onChanged method :
onChanged: (ThemeOptions newValue) {
setState(() {
dropdownValue = newValue;
dropdownValue.callParentTheme(context);
print(newValue.themeColor);
});
},
Hope It's help

Flutter ProgressDialog hidden

I have developed a Flutter application and I used ProgressDialog widget (progress_dialog: ^1.2.0). First, I show the ProgressDialog widget and after some code, then I try to hide ProgressDialog. But it doesn't work.
This is my code
class SignUp extends StatefulWidget {
#override
_SignUpState createState() => _SignUpState();
}
class _SignUpState extends State<SignUp> {
#override
Widget build(BuildContext context) {
pr = new ProgressDialog(context,type: ProgressDialogType.Normal);
pr.style(
message: 'Sing Up .......',
borderRadius: 20.0,
backgroundColor: Colors.white,
progressWidget: CircularProgressIndicator(),
maxProgress: 1.0,
);
return Scaffold(
backgroundColor: Color.fromRGBO(23, 63, 73, 1),
appBar: AppBar(
title: Text("Sign up"),
backgroundColor: Colors.black,
),body: Stack(
......
_addUser();
),
);
}
Future _addUser() async {
pr.show();
.........
pr.hide();
}
}
After that, I find the solution to this problem.
Future.delayed(Duration(seconds: 3)).then((value) {
pr.hide();
});
But why does ProgressDialog.hide() not work here but it works after delaying the process??
When your code execute to pr.hide() the progress_dialog still not show on screen
so your pr.hide() not work
you can see issues https://github.com/fayaz07/progress_dialog/issues/38
and check pr.isShowing() will not work because in source code of progress_dialog https://github.com/fayaz07/progress_dialog/blob/master/lib/progress_dialog.dart
bool _isShowing is ahead before real showDialog()
code snippet of progress_dialog
void show() {
if (!_isShowing) {
_dialog = new _Body();
_isShowing = true;
if (_showLogs) debugPrint('ProgressDialog shown');
showDialog<dynamic>(
context: _context,
barrierDismissible: false,
builder: (BuildContext context) {
_dismissingContext = context;
return WillPopScope(
onWillPop: () {
return Future.value(_barrierDismissible);
},
child: Dialog(
backgroundColor: _backgroundColor,
insetAnimationCurve: _insetAnimCurve,
insetAnimationDuration: Duration(milliseconds: 100),
elevation: _dialogElevation,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(_borderRadius))),
child: _dialog),
);
},
);
} else {
if (_showLogs) debugPrint("ProgressDialog already shown/showing");
}
}
}
full test code
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:progress_dialog/progress_dialog.dart';
ProgressDialog pr;
void main() {
runApp(MaterialApp(
home: FirstScreen(),
));
}
class MyApp extends StatelessWidget {
double percentage = 0.0;
#override
Widget build(BuildContext context) {
// pr = new ProgressDialog(context,
// type: ProgressDialogType.Normal, isDismissible: false);
pr = new ProgressDialog(context, type: ProgressDialogType.Download);
pr.style(
message: 'Downloading file...',
borderRadius: 10.0,
backgroundColor: Colors.white,
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 Scaffold(
body: Center(
child: RaisedButton(
child: Text(
'Show Dialog',
style: TextStyle(color: Colors.white),
),
color: Colors.blue,
onPressed: () {
pr.show();
Future.delayed(Duration(seconds: 2)).then((onvalue) {
percentage = percentage + 30.0;
print(percentage);
pr.update(
progress: percentage,
message: "Please wait...",
progressWidget: Container(
padding: EdgeInsets.all(8.0),
child: CircularProgressIndicator()),
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),
);
Future.delayed(Duration(seconds: 2)).then((value) {
percentage = percentage + 30.0;
pr.update(
progress: percentage, message: "Few more seconds...");
print(percentage);
Future.delayed(Duration(seconds: 2)).then((value) {
percentage = percentage + 30.0;
pr.update(progress: percentage, message: "Almost done...");
print(percentage);
Future.delayed(Duration(seconds: 2)).then((value) {
pr.hide().whenComplete(() {
print(pr.isShowing());
});
percentage = 0.0;
});
});
});
});
Future.delayed(Duration(seconds: 10)).then((onValue) {
print("PR status ${pr.isShowing()}");
if (pr.isShowing())
pr.hide().then((isHidden) {
print(isHidden);
});
print("PR status ${pr.isShowing()}");
});
}),
),
);
}
}
class FirstScreen extends StatefulWidget {
#override
_FirstScreenState createState() => _FirstScreenState();
}
class _FirstScreenState extends State<FirstScreen> {
ProgressDialog pr;
#override
Widget build(BuildContext context) {
pr = new ProgressDialog(context, showLogs: true);
pr.style(message: 'Please wait...');
return Scaffold(
body: Center(
child: RaisedButton(
child: Text('Show dialog and go to next screen',
style: TextStyle(color: Colors.white)),
color: Colors.blueAccent,
onPressed: () async{
print("before pr show");
pr.show();
print("after pr show");
print(pr.isShowing());
pr.hide().whenComplete((){print("hide complete");}
);
print("after pr hide");
print(pr.isShowing());
/*Future.delayed(Duration(seconds: 3)).then((value) {
pr.hide().whenComplete(() {
Navigator.of(context).push(CupertinoPageRoute(
builder: (BuildContext context) => SecondScreen()));
});
});*/
},
),
),
);
}
}
class SecondScreen extends StatefulWidget {
#override
_SecondScreenState createState() => _SecondScreenState();
}
class _SecondScreenState extends State<SecondScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child: Text('I am second screen')),
);
}
}