How to fix the '!_debugLocked': is not true in flutter? - flutter

I'm new to flutter and I have a problem with the navigation. My app has multiple pages and I can't understand the error and how to fix it.
I searched online and I tried everything that I found on Git / Stack or Google but nothing works.
This is the error : '!_debugLocked': is not true.
This is the code :
This is the first .dart file and the error is when I try to do the Navigator.of .....
import 'package:flutter/material.dart';
class FirstScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[100],
body: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
SizedBox(
height: 320,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'C.R',
style: TextStyle(
fontSize: 120,
fontFamily: 'Membra',
),
)
],
),
SizedBox(
height: 200,
),
FloatingActionButton(
backgroundColor: Colors.white,
child: Image.asset('images/arrow_next.png'),
onPressed: () {
Navigator.of(context).pushNamedAndRemoveUntil(
'/SecondScreen', (Route<dynamic> route) => false);
},
),
],
),
);
}
}
This is the second .dart file where I want to go to from the first file/ page.
import 'package:flutter/material.dart';
import 'NewWidget_Creator.dart';
class SecondScreen extends StatefulWidget {
#override
_SecondScreenState createState() => _SecondScreenState();
}
class _SecondScreenState extends State<SecondScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Center(
child: NewWidget(
'Schede',
Navigator.of(context).pushNamedAndRemoveUntil(
'/SecondScreen', (Route<dynamic> route) => false)),
),
NewWidget(
'Orario',
Navigator.of(context).pushNamedAndRemoveUntil(
'/SecondScreen', (Route<dynamic> route) => false)),
NewWidget(
'Pausa',
Navigator.of(context).pushNamedAndRemoveUntil(
'/SecondScreen', (Route<dynamic> route) => false)),
],
),
);
}
}
NewWidgetCreator .dart file :
import 'package:flutter/material.dart';
class NewWidget extends StatelessWidget {
String Name_of_button;
Future<dynamic> send_toNextPage;
NewWidget(this.Name_of_button, this.send_toNextPage);
#override
Widget build(BuildContext context) {
return FlatButton(
onPressed: () {
send_toNextPage;
},
child: Container(
child: Text(
Name_of_button,
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Membra',
fontSize: 50,
),
),
),
);
}
}
Thank you in advance.

Why in NewWidget field send_toNextPage is a Future? Here you have fixed class of NewWidget
class NewWidget extends StatelessWidget {
String buttonName;
String nextPageRoute;
NewWidget(this.buttonName, this.nextPageRoute);
#override
Widget build(BuildContext context) {
return FlatButton(
onPressed: () {
Navigator.of(context).pushNamed(nextPageRoute);
},
child: Container(
child: Text(
buttonName,
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Membra',
fontSize: 50,
),
),
),
);
}
}
This is how to use it in SeconScreen:
class SecondScreen extends StatefulWidget {
#override
_SecondScreenState createState() => _SecondScreenState();
}
class _SecondScreenState extends State<SecondScreen> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
NewWidget('Schede', '/SecondScreen'),
NewWidget('Orario', '/SecondScreen'),
NewWidget('Pausa', '/SecondScreen'),
],
),
);
}
}
BTW: SecondSreen can be StatelessWidget:
class SecondScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
NewWidget('Schede', '/SecondScreen'),
NewWidget('Orario', '/SecondScreen'),
NewWidget('Pausa', '/SecondScreen'),
],
),
);
}
}

Related

Unable to navigate from GetX Dialog to another screen

I have follow dialog box. When I click 'Next' I want it to navigate to GamePage() screen. But unfortunately it doesn't work.
Following is the GamePage Widget
class GamePage extends StatelessWidget {
final homeCtrl = Get.find<HomeController>();
GamePage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF8fb1ca),
body: SafeArea(
child: ListView(
children: [
Padding(
padding: EdgeInsets.all(3.0.wp),
child: Row(
children: [
IconButton(
onPressed: () {
Get.back();
},
icon: const Icon(Icons.arrow_back),
),
],
),
),
Padding(
padding: EdgeInsets.symmetric(vertical: 4.0.wp),
child: Column(
children: [
SizedBox(
height: 2.0.wp,
),
Center(
child: Text(
'What ${homeCtrl.currentWord.first.wordtype} is this?',
style: TextStyle(
fontSize: 18.0.sp,
color: Colors.grey[800],
),
),
),
SizedBox(height: 10.0.wp),
WordsWidget(currentWord: homeCtrl.currentWord.first),
],
),
),
],
),
),
);
}
}
Following is the Word Widget being called from GamePage Widget
class WordsWidget extends StatelessWidget {
final currentWord;
WordsWidget({Key? key, this.currentWord}) : super(key: key);
final homeCtrl = Get.find<HomeController>();
#override
Widget build(BuildContext context) {
// var currentWord = homeCtrl.nextWord();
var shuffleword = [].obs;
shuffleword.addAll(homeCtrl.shuffleWord(currentWord.word));
TextToSpeech tts = TextToSpeech();
String language = 'en-US';
tts.setLanguage(language);
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
print('pressed here');
Get.defaultDialog(
title: 'Go to next page',
content: Container(
child: Column(
children: [
Text('You are about to move to another screen'),
ElevatedButton.icon(
onPressed: () {
Get.to(() => GamePage());
},
icon: Icon(
Icons.arrow_right,
),
label: Text('Go'))
],
),
));
},
child: Text('Open Dialog')),
],
);
}
}
Get.back() is working but not Get.to
Try
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (BuildContext context) {
return const GamePage();
},
),
);
},
child: Text("Next Word"),
)
Try this code -
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:image_memory/next_page.dart';
import 'package:image_picker/image_picker.dart';
void main() {
//check getMaterialApp is used
runApp(const GetMaterialApp(
title: 'Temp',
home: const MyApp(),
));
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
#override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Image Picker'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
print('pressed here');
Get.defaultDialog(
title: 'Go to next page',
content: Container(
child: Column(
children: [
Text('You are about to move to another screen'),
ElevatedButton.icon(
onPressed: () {
Get.to(() => NextPage());
},
icon: Icon(
Icons.arrow_right,
),
label: Text('Go'))
],
),
));
},
child: Text('Open Dialog')),
),
);
}
}
and next page is -
import 'package:flutter/material.dart';
class NextPage extends StatefulWidget {
const NextPage({ Key? key }) : super(key: key);
#override
State<NextPage> createState() => _NextPageState();
}
class _NextPageState extends State<NextPage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Next Page'),
),
body: Container(
child: Center(
child: Text("this is next page"),
),
),
);
}
}
And yes, you need to insure that you are using 'GetMaterialApp'.
If you want to use GetX navigation system, you should wrap your application in a GetMaterialApp instead of MaterialApp.
So in your main use this:
class GetxApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return GetMaterialApp(
home: HomePage(),
);
}
}
Instead of this:
class NormalApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: HomePage(),
);
}
}

Flutter: Increment a counter from 2 different classes with counter display on a common AppBar

I have a unique .dart page
At the beginning I would like to have a counter on a common AppBar, a "button 1" which allows to increment my counter, and another button which directs me to another class.
On this class, I would like to review the counter without it being reset to zero, it must keep the starting increment.
With the "button 2" which is in this new class, I would like to be able to continue to increment this same counter.
I have 2 problems (beginner):
the AppBar shows me an error for the counter
I can't increment from "button 1" and "button 2" which are
in a different class from the counter. So I also have an error concerning these 2 buttons.
Can you help me by giving me a maximum of explanations please because I am new to Flutter.
Thanks in advance.
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class TestClass1 extends StatefulWidget {
#override
TestClass1State createState() => TestClass1State();
}
class TestClass2 extends StatefulWidget {
#override
TestClass2State createState() => TestClass2State();
}
class Counter extends StatefulWidget {
const Counter({Key? key}) : super(key: key);
#override
CounterState createState() => CounterState();
}
class AppBarShared extends StatelessWidget implements PreferredSizeWidget {
final Color backgroundColor = Colors.red;
final Text title;
final AppBar appBar;
final List<Widget> widgets;
const AppBarShared({required this.title, required this.appBar, required this.widgets});
#override
Widget build(BuildContext context) {
return AppBar(
title: title,
backgroundColor: backgroundColor,
actions: <Widget>[Counter()],
);
}
#override
Size get preferredSize => new Size.fromHeight(appBar.preferredSize.height);
}
class CounterState extends State<Counter> {
int _counter = 1;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child:Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
'$_counter',
style: Theme.of(context).textTheme.headline4,
),
],
),
)
);
}
}
class TestClass1State extends State<TestClass1> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBarShared(
title: Text('title'),
appBar: AppBar(),
widgets: [this.widget],
),
//backgroundColor: Color(0xffe80fd3),
body: Container (
child: Stack(
children: [
IconButton (
iconSize: 40,
onPressed: _incrementCounter,
icon:Icon(Icons.arrow_upward, color:Colors.amber)
),
button1(),
],
),
),
);
}
Container button1() {
return Container(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
IconButton (
iconSize: 40,
onPressed: () => Navigator.pushReplacement(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) => TestClass2(),
transitionDuration: Duration.zero,
),
),
icon:Icon(Icons.arrow_upward, color:Colors.amber)
)
],
),
);
}
}
class TestClass2State extends State<TestClass2> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBarShared(
title: Text('title 2'),
appBar: AppBar(),
widgets: [this.widget],
),
//backgroundColor: Color(0xffe80fd3),
body: Container(
child: Stack(
children: [
IconButton (
iconSize: 40,
onPressed: _incrementCounter,
icon:Icon(Icons.arrow_upward, color:Colors.amber)
),
button2(),
],
),
),
);
}
Container button2() {
return Container(
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
IconButton(
iconSize: 40,
onPressed: () => Navigator.pushReplacement(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) => TestClass1(),
transitionDuration: Duration.zero,
),
),
icon: Icon(Icons.arrow_upward, color: Colors.amber)
)
],
),
);
}
}

How to prevent elements from moving in Column after one's visibility is changed?

So, as it is in the title, I'm facing problem with preventing a group of elements from moving, when one of the elements, wrapped in Visibility, becomes visible/invisible. I am new to Flutter, so I couldn't neither solve the problem nor find the solution anywhere.
I created sample code and made 2 screenshots to show the problem more clearly.
screenshots:
State 1, before the button is clicked
State 2, after the button is clicked (button clicked changes visibility of the text below)
code:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'MyApp',
home: MyAppHome()
);
}
}
class MyAppHome extends StatefulWidget {
#override
_MyAppHomeState createState() => _MyAppHomeState();
}
class _MyAppHomeState extends State<MyAppHome> {
bool isVisible = false;
#override
Widget build(BuildContext context) {
return Scaffold(
body: _buildStateWidget()
);
}
Widget _buildStateWidget() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text('Some text 1', style: TextStyle(fontSize: 30.0)),
SizedBox(
width: 200.0,
height: 200.0,
child: FloatingActionButton(
onPressed: () {
setState(() {
isVisible = !isVisible;
});
},
)),
Visibility(
visible: isVisible,
child: Column(
children: <Widget>[
Text(
'Some text 2',
textAlign: TextAlign.center,
),
Icon(
Icons.favorite_border
)
]
)
)
],
)
);
}
}
I understand, why it behaves like this, but I don't know how to fix that problem.
I think you could wrap your FAB and the widget below it with Expanded
Here's my solution:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(title: 'MyApp', home: MyAppHome());
}
}
class MyAppHome extends StatefulWidget {
#override
_MyAppHomeState createState() => _MyAppHomeState();
}
class _MyAppHomeState extends State<MyAppHome> {
bool isVisible = false;
#override
Widget build(BuildContext context) {
return Scaffold(body: _buildStateWidget());
}
Widget _buildStateWidget() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text('Some text 1', style: TextStyle(fontSize: 30.0)),
Expanded(
child: Container(
height: 200.0,
width: 200.0,
child: FittedBox(
child: FloatingActionButton(
onPressed: () {
setState(() {
isVisible = !isVisible;
});
},
),
),
),
),
Expanded(
child: Visibility(
visible: isVisible,
child: Column(children: <Widget>[
Text(
'Some text 2',
textAlign: TextAlign.center,
),
Icon(Icons.favorite_border)
])))
],
));
}
}
NOTE: I've changed the way you resize your FAB

Understand how listen: false works when used with Provider<SomeType>.of(context, listen: false)

I'm working through understanding how the Provider package works with Flutter but confused on how listen:false works.
I wrote some basic code using the usual Counter example from a new Flutter project. I created three types of stateless widgets each using a Provider:
Provider.of(context)
Consumer
Provider.of(context, listen: false)
The third example was to show how access the provider object and call methods on it without it rebuilding.
When I run the application all of the widget counts are changing - and I only expect it to change in the first two.
This is a simple example - what am I doing wrong?
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() => runApp(MyApp());
class Counter with ChangeNotifier {
int _count = 0;
int get count => _count;
void increment() {
_count++;
notifyListeners();
}
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(builder: (_) => Counter()),
],
child: MaterialApp(
title: 'Provider Demo',
theme: ThemeData(
primarySwatch: Colors.amber,
),
home: MyHomePage(title: 'Provider Demo Home Page'),
),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
Widget build(BuildContext context) {
Counter counter = Provider.of<Counter>(context);
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ExampleProviderWidget(),
ExampleConsumerWidget(),
ExampleNoListenWidget()
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => counter.increment(),
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
class ExampleProviderWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
Counter counter = Provider.of<Counter>(context);
return Container(
color: Colors.green,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Provider.of<Counter>(context):',
),
Text(
'${counter.count}',
style: Theme.of(context).textTheme.display1,
),
],
),
),
);
}
}
class ExampleConsumerWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Consumer<Counter>(
builder: (context, counter, _) {
return Container(
color: Colors.blue,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Consumer<Counter>(context):',
),
Text(
'${counter.count}',
style: Theme.of(context).textTheme.display1,
),
],
),
),
);
},
);
}
}
class ExampleNoListenWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
Counter counter = Provider.of<Counter>(context, listen: false);
return Container(
color: Colors.red,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Provider.of<Counter>(context, listen: false):',
),
Text(
'${counter.count}',
style: Theme.of(context).textTheme.display1,
),
RaisedButton(
child: Text("Increment"),
onPressed: () => counter.increment(),
)
],
),
),
);
}
}
That's because, while the widget that called Provider.of with listen:false did not want to rebuild, its parent forced it to.
In your example, when Counter changes, MyHomePage rebuilds and recreate the widget that specified listen:false, which in turn force it to rebuild too.
MyHomePage should specify listen: false too here.
What Remi suggested is a working approach (hack).
But I believe the better way in this case will be to remove the call
Counter counter = Provider.of(context); from the MyHomePageClass. That call is polluting the scope of your Counter object.
As suggested by flutter.io , It is best practice to put your Consumer widgets as deep in the tree as possible. As you did in the ExampleProviderWidget(), ExampleConsumerWidget(),ExampleNoListenWidget(). So make the floatingActionButton a separate widget class and have its own Provider.of(context).
And your MyHomePageClass will not have to call Provider.of.
listen: false necessary to be able to call Provider.of inside [State.initState] or the create method of providers.
listen: true, latter value changes will trigger a new [State.build] to widgets, and [State.didChangeDependencies] for [StatefulWidget].
According to the link below
https://docs.flutter.dev/development/data-and-backend/state-mgmt/simple#providerof
when listen is set false, it won’t cause this widget to rebuild when notifyListeners is called.
It works for me
I/flutter (12384): MyApp build
I/flutter (12384): MyHomePage build
I/flutter (12384): ExampleProviderWidget build
I/flutter (12384): ExampleConsumerWidget build
I/flutter (12384): ExampleNoListenWidget build
Reloaded 1 of 524 libraries in 792ms.
I/flutter (12384): ExampleProviderWidget build
I/flutter (12384): ExampleProviderWidget build
I/flutter (12384): ExampleProviderWidget build
I/flutter (12384): ExampleProviderWidget build
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
void main() => runApp(MyApp());
class Counter with ChangeNotifier {
int _count = 0;
int get count => _count;
void increment() {
_count++;
notifyListeners();
}
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
print('MyApp build');
return MaterialApp(
title: 'Provider Demo',
theme: ThemeData(
primarySwatch: Colors.amber,
),
home: MyHomePage(title: 'Provider Demo Home Page'),
);
}
}
class MyHomePage extends StatelessWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
Counter _counter = Counter();
#override
Widget build(BuildContext context) {
print('MyHomePage build');
return ChangeNotifierProvider.value(
value: _counter,
child: Scaffold(
appBar: AppBar(
title: Text(title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ExampleProviderWidget(),
ExampleConsumerWidget(),
ExampleNoListenWidget()
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () => _counter.increment(),
tooltip: 'Increment',
child: Icon(Icons.add),
),
),
);
}
}
class ExampleProviderWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
print('ExampleProviderWidget build');
Counter counter = Provider.of<Counter>(context);
return Container(
color: Colors.green,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Provider.of<Counter>(context):',
),
Text(
'${counter.count}',
style: Theme.of(context).textTheme.display1,
),
],
),
),
);
}
}
class ExampleConsumerWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
print('ExampleConsumerWidget build');
return Consumer<Counter>(
builder: (context, counter, _) {
return Container(
color: Colors.blue,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Consumer<Counter>(context):',
),
Text(
'${counter.count}',
style: Theme.of(context).textTheme.display1,
),
],
),
),
);
},
);
}
}
class ExampleNoListenWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
print('ExampleNoListenWidget build');
Counter counter = Provider.of<Counter>(context, listen: false);
return Container(
color: Colors.red,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Provider.of<Counter>(context, listen: false):',
),
Text(
'${counter.count}',
style: Theme.of(context).textTheme.display1,
),
RaisedButton(
child: Text("Increment"),
onPressed: () => counter.increment(),
)
],
),
),
);
}
}
Whenever you say Provider.of<Counter>(context,, you should write , listen: false).
Provider.of<Counter>(context, listen: false);
from the code you have written, the increment method you are using in the onPressed method will not work, if you implement listen: false.

Not able to navigate to a new screen in flutter

I am trying to navigate to a new screen after the splash screen, when i try to navigate to new screen in the init method it shows an error,
E/flutter ( 5636): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Navigator operation requested with a context that does not include a Navigator.
E/flutter ( 5636): The context used to push or pop routes from the Navigator must be that of a widget that is a descendant of a Navigator widget.
My code
import 'package:flutter/material.dart';
import 'package:igloled_app/home.dart';
import 'dart:async';
class SplashScreen extends StatefulWidget {
#override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
#override
void initState() {
super.initState();
Future.delayed(Duration(seconds: 3),(){
print('3 sec done');
Navigator.push(context, MaterialPageRoute(builder: (context){
return AppHeader();
}));
});
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
Container(
decoration: BoxDecoration(
color: Colors.white70,
),
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(flex: 2,
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(20.0),
child: Container(
margin: EdgeInsets.all(10.0),
child: Image.asset('images/splash_logo.png')
),
)
],
),
),
),
Expanded(flex: 1,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircularProgressIndicator(valueColor: AlwaysStoppedAnimation<Color>(Colors.green),),
Padding(padding: EdgeInsets.only(top: 20.0),
),
Text('Make Your Life Brighter',
style: TextStyle(
color: Colors.lightGreen,
fontStyle: FontStyle.italic,
fontSize: 20.0,
),
),
],
),
)
],
),
],
),
),
);
}
}
}
Can anyone please help me with this.
Thank you in advance.
Here is a sample code of doing it right way.
void main() => runApp(MaterialApp(home: FirstScreen()));
class FirstScreen extends StatefulWidget {
#override
_FirstScreenState createState() => _FirstScreenState();
}
class _FirstScreenState extends State<FirstScreen> {
#override
void initState() {
super.initState();
Future.delayed(Duration(seconds: 3), () {
print('3 sec done');
Navigator.push(context, MaterialPageRoute(builder: (context) {
return SecondScreen();
}));
});
}
#override
Widget build(BuildContext context) {
return Scaffold(appBar: AppBar(title: Text("First screen")));
}
}
class SecondScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(appBar: AppBar(title: Text("Second screen")));
}
}
your MaterialApp is not in your context !!
a slight fix to move the MaterialApp to the runApp method.
but for a notice please but all underground widgets that won't use the setState to another class or to the runApp method to have the best functionality of your code .