(FLUTTER) I'm getting this problem: throw UnimplementedError(); - flutter

I have a total of 10 hours of coding experience so spare my ignorance. Under the TODO it's supposed to be (this is what the tutorial shows) return null; instead of throw UnimplementedError();
This is a copy of what I have.
void main() => runApp(MyQuizApp());
class MyQuizApp extends StatefulWidget {
#override
State<StatefulWidget> createState() {
// TODO: implement createState
throw UnimplementedError();
}
}
class MyQuizAppState extends State<MyQuizApp> {
var questionIndex = 0;
void answerQuestion() {
questionIndex = questionIndex + 1;
print(questionIndex);
}
#override
Widget build(BuildContext context) {
var questions = [
"What\'s your favorite color?",
"What\'s your favorite fruit?",
];
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Personality Quiz"),
),
body: Column(
children: [
Text(questions[questionIndex]),
RaisedButton(
child: Text("Answer 1"),
onPressed: answerQuestion,
),
RaisedButton(
child: Text("Answer 2"),
onPressed: () => print("Answer chosen!"),
),
RaisedButton(
child: Text("Answer 3"),
onPressed: () {
print("Answer chosen!");
},
),
],
),
),
);
}
}

This should fix it!
class MyQuizApp extends StatefulWidget {
#override
State<StatefulWidget> createState() {
_MyQuizAppState createState() => _MyQuizAppState();
}
}

Related

why setState not working for List of widgets in flutter

I am new in flutter I try to experiment with List of Widget . I try to change state inside the list of widget i.e. initialized in initState . I create sample example to what I want to achieve.
class Testing extends StatefulWidget {
const Testing({super.key});
#override
State<Testing> createState() => _TestingState();
}
class _TestingState extends State<Testing> {
bool isChanged = false;
List<Widget> simpleWidget = [];
#override
void initState() {
simpleWidget = [_someComplexWidget(), _someComplexWidget()];
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title:const Text("Test"),
),
body: Center(
child: Column(
children: [
Container(
child: Column(
children: simpleWidget,
),
),
ElevatedButton(
onPressed: () {
setState(() {
isChanged = !isChanged;
});
},
child: const Text("Click"))
],
),
),
);
}
Widget _someComplexWidget() {
return Text(
"Hello",
style: TextStyle(color: isChanged ? Colors.red : Colors.blue),
);
}
}
I also try with keys but it did not work in this sample code. When to Use Keys
What is the reason behind not working this code.
Because your simpleWidget is created at initState & it will not change on rebuild.
You should add [_someComplexWidget(), _someComplexWidget()] under build for it to change dynamically based on the current state.
class Testing extends StatefulWidget {
const Testing({super.key});
#override
State<Testing> createState() => _TestingState();
}
class _TestingState extends State<Testing> {
bool isChanged = false;
#override
void initState() {
super.initState();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Test"),
),
body: Center(
child: Column(
children: [
Container(
child: Column(
children: [_someComplexWidget(), _someComplexWidget()], // HERE
),
),
ElevatedButton(
onPressed: () {
setState(() {
isChanged = !isChanged;
});
print(isChanged);
},
child: const Text("Click"))
],
),
),
);
}
Widget _someComplexWidget() {
return Text(
"Hello",
style: TextStyle(color: isChanged ? Colors.red : Colors.blue),
);
}
}

How to Refresh State from Navigator Pop in Flutter

I want to refresh the state when calling Navigator Pop / Navigator Pop Until.
While I was doing some research, I finally found this article Flutter: Refresh on Navigator pop or go back. From the code in the article, it can work fine.
But there is a problem when I use the widget tree, for example like the code below:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Refresh on Go Back',
home: HomePage(),
);
}
}
Home Page - Parent Class
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int id = 0;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'Data: $id',
style: Theme.of(context).textTheme.headline5,
),
ButtonWidget(),
],
),
),
);
}
void refreshData() {
id++;
}
onGoBack(dynamic value) {
refreshData();
setState(() {});
}
}
Button Widget - Widget Class
class ButtonWidget extends StatelessWidget{
#override
Widget build(BuildContext context) {
return RaisedButton(
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) =>
SecondPage())).then(onGoBack);
// The Problem is Here
// How to call a Method onGoBack from HomePage Class
}
);
}
}
SecondPage
class SecondPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Second Page'),
),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Go Back'),
),
),
);
}
}
Or is there another solution to refresh the state class when calling Navigator Pop / Navigator Pop Until?
re-write your Button's class like this:
class ButtonWidget extends StatelessWidget{
final Function onGoBack;
ButtonWidget({this.onGoBack})
#override
Widget build(BuildContext context) {
return RaisedButton(
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context) =>
SecondPage())).then(onGoBack);
//to avoid any np exception you can do this: .then(onGoBack ?? () => {})
// The Problem is Here
// How to call a Method onGoBack from HomePage Class
}
);
}
}
And add the onGoBack function as a parameter from the home page like this:
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int id = 0;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'Data: $id',
style: Theme.of(context).textTheme.headline5,
),
ButtonWidget(onGoBack: onGoBack),
],
),
),
);
}
void refreshData() {
id++;
}
onGoBack(dynamic value) {
refreshData();
setState(() {});
}
}
you must sent function on widget
class ButtonWidget extends StatelessWidget{
final Function(dynamic)? refresh;
const ButtonWidget({this.refresh})
#override
Widget build(BuildContext context) {
return RaisedButton(
onPressed: ()async {
await Navigator.push(context, MaterialPageRoute(builder: (context) =>
SecondPage()));
if(refresh!=null){
refresh!("your params");
}
// The Problem is Here
// How to call a Method onGoBack from HomePage Class
}
);
}
}
and you can use widget
ButtonWidget(
refresh:onGoBack
)
Try this, it just you are calling method out of scope
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Refresh on Go Back',
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int id = 0;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'Data: $id',
style: Theme.of(context).textTheme.headline5,
),
ButtonWidget(
refresh: onGoBack,
)
],
),
),
);
}
void refreshData() {
id++;
}
onGoBack(dynamic value) {
refreshData();
setState(() {});
}
}
class ButtonWidget extends StatelessWidget {
final Function(dynamic)? refresh;
ButtonWidget({Key? key, this.refresh}) : super(key: key);
#override
Widget build(BuildContext context) {
print(refresh);
return RaisedButton(onPressed: () async {
await Navigator.push(
context, MaterialPageRoute(builder: (context) => SecondPage()))
.then((value) => refresh!("okay"));
});
}
}
class SecondPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Second Page'),
),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Go Back'),
),
),
);
}
}

Stateless widget to stateful widget ( using Create state)

[error][1]
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
#override
State<StatefulWidget> createState() {
// TODO: implement createState
return MyAppState();
}
}
class MyAppState extends State<MyApp> {
var questionIndex = 0;
void answerQuestion() {
setState(() {
questionIndex = questionIndex + 1;
});
print(questionIndex);
}
#override
Widget build(BuildContext context) {
var question = [
'what\'s your favorite colour?',
'what\'s your favorite sports?',
];
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('My app'),
),
body: Column(
children: [
Text(question[questionIndex]),
RaisedButton(
child: Text('answer1'),
onPressed: () => print('answer2'),
),
RaisedButton(
child: Text('answer2'),
onPressed: () => print('answer2'),
),
RaisedButton(
child: Text('answer3'),
onPressed: () {
print('answer3');
}),
],
),
),
);
}
}
error
I'm on going course in Udemy in that they got the output for the same code but for me it showing error like this **
** Exception caught by widgets library
** MyAppState#f6d27(lifecycle state: created, no widget, not mounted)**
[1]: https://i.stack.imgur.com/NFGhN.jpg
You need to create a private class.
class FilmList extends StatefulWidget {
const FilmList({Key? key}) : super(key: key);
#override
_FilmListState createState() => _FilmListState();//need to add
}
class _FilmListState extends State<FilmList> {
MovieQuery query = MovieQuery.year;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
child:Container(),
);}
}

Need Help in getting respective value from a custom widget

I am a noob in flutter and i need help with this. So I made this counter widget where you can increase and decrease the counter value with button, and called that widget two times in my root widget. now I want to get respective counter value of those counter widget separately for each time I call my counter widget. How do I achieve that.
this is my main.dart file
class _MyHomePageState extends State<MyHomePage> {
int count;
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
CounterContainer(count, ValueKey(1)),
Text('first counter : ${CounterContainer(count, ValueKey(1)).count}'),
CounterContainer(count, ValueKey(2)),
Text('second counter : ${CounterContainer(count, ValueKey(2)).count}'),
],
),
),
);
}
}
this is my Counter_widget
class CounterContainer extends StatefulWidget {
int count;
CounterContainer(this.count, ValueKey<int> valueKey);
#override
_CounterContainerState createState() => _CounterContainerState();
}
class _CounterContainerState extends State<CounterContainer> {
int _counter = 0;
void _incrementCounter() {
setState(() {
widget.count = ++_counter;
print('------------>${widget.count}');
});
}
void _decrementCounter() {
setState(() {
if (_counter > 0) {
widget.count = --_counter;
print('------------>${widget.count}');
}
});
}
#override
Widget build(BuildContext context) {
return Row(
children: <Widget>[
FlatButton(
onPressed: _incrementCounter,
child: Icon(Icons.add),
),
Text('$_counter'),
FlatButton(
onPressed: _decrementCounter,
child: Icon(Icons.remove),
),
],
);
}
}
You can copy paste run full code below
You can define two counters counter1 and counter2 and pass callback to do refresh
working demo
code snippet
void _incrementCounter() {
setState(() {
...
});
widget.callback();
}
void _decrementCounter() {
setState(() {
...
});
widget.callback();
}
...
CounterContainer counter1;
CounterContainer counter2;
void refresh() {
print("refresh");
setState(() {});
}
#override
void initState() {
counter1 = CounterContainer(count, ValueKey(1), refresh);
counter2 = CounterContainer(count, ValueKey(2), refresh);
super.initState();
}
...
children: <Widget>[
counter1,
Text('first counter : ${counter1.count}'),
counter2,
Text('second counter : ${counter2.count}'),
],
full code
import 'package:flutter/material.dart';
class CounterContainer extends StatefulWidget {
int count;
VoidCallback callback;
CounterContainer(this.count, ValueKey<int> valueKey, this.callback);
#override
_CounterContainerState createState() => _CounterContainerState();
}
class _CounterContainerState extends State<CounterContainer> {
int _counter = 0;
void _incrementCounter() {
setState(() {
widget.count = ++_counter;
print('------------>${widget.count}');
});
widget.callback();
}
void _decrementCounter() {
setState(() {
if (_counter > 0) {
widget.count = --_counter;
print('------------>${widget.count}');
}
});
widget.callback();
}
#override
Widget build(BuildContext context) {
return Row(
children: <Widget>[
FlatButton(
onPressed: _incrementCounter,
child: Icon(Icons.add),
),
Text('$_counter'),
FlatButton(
onPressed: _decrementCounter,
child: Icon(Icons.remove),
),
],
);
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
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> {
int count;
CounterContainer counter1;
CounterContainer counter2;
void refresh() {
print("refresh");
setState(() {});
}
#override
void initState() {
counter1 = CounterContainer(count, ValueKey(1), refresh);
counter2 = CounterContainer(count, ValueKey(2), refresh);
super.initState();
}
#override
Widget build(BuildContext context) {
print('${counter1.count}');
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
counter1,
Text('first counter : ${counter1.count}'),
counter2,
Text('second counter : ${counter2.count}'),
],
),
),
);
}
}

How to recall method initState each time that I navigate to a specific tab in flutter?

I'm doing a flutter app with Cupertino, I'm trying to figure out how to recall method initState each time that I navigate to this tab (MapPage).
This method initState() calls other mehtod "initPlatformState()" who asks for the permission location and makes a request to an API, with this result I build a marker per each object's result and show them on the map.
Here is the code of the map page.
https://gist.github.com/GreyHat147/3ea92f4e962218893b84af667452b087
This is the ui.
For CupertinoTabBar you can do as below where create instance of state class and the without creating it again called it only on tap:
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
MyHome myHome = new MyHome();
MyNearMe myNearMe = new MyNearMe();
MyMap myMap = new MyMap();
MyNotifications myNotifications = new MyNotifications();
MyWallet myWallet = new MyWallet();
MyHomeState myHomeState = MyHomeState();
MyNearMeState myNearMeState = MyNearMeState();
MyMapState myMapState = MyMapState();
MyNotificationsState myNotificationsState = MyNotificationsState();
MyWalletState myWalletState = MyWalletState();
int indexPrevValue = 0;
class TabBarPage extends StatefulWidget {
TabBarPage({Key key, this.userId})
: super(key: key);
final String userId;
#override
_TabBarPage createState() => new _TabBarPage();
}
class _TabBarPage extends State<TabBarPage> {
_TabBarPage({Key key, this.userId});
final String userId;
void _onTap(int value) {
print('Value => $value');
if(value == 0){
myHomeState.initState();
}
else if(value == 1){
myNearMeState.initState();
}
else if(value == 2){
myMapState.initState();
}
else if(value == 3){
myNotificationsState.initState();
}
else if(value == 4){
myWalletState.initState();
}
indexPrevValue = value;
}
#override
void initState() {
// TODO: implement initState
super.initState();
}
#override
void dispose() {
super.dispose();
}
#override
Widget build(BuildContext context) {
return CupertinoTabScaffold(
tabBar: CupertinoTabBar(
onTap: _onTap,
activeColor: new Color.fromRGBO(148, 3, 123, 1.0),
items: <BottomNavigationBarItem>[
new BottomNavigationBarItem(
title: new Text('Home'),
icon: new Icon(
Icons.home,
size: 22,
),
),
new BottomNavigationBarItem(
title: new Text('Near me'),
icon: new Icon(
Icons.location_on,
size: 22,
),
),
new BottomNavigationBarItem(
icon: new Icon(
Icons.map,
size: 22,
),
title: new Text('Map')
),
new BottomNavigationBarItem(
title: new Text('Notifications'),
icon: new Icon(
Icons.notifications,
size: 22,
)
),
new BottomNavigationBarItem(
title: new Text('Wallet'),
icon: new Icon(
Icons.account_balance_wallet,
size: 22,
)
),
],
),
tabBuilder: (BuildContext context, int index) {
switch (index) {
case 0:
return CupertinoTabView(
builder: (BuildContext context) {
if(myHomeState == null){
myHomeState = myHome.createState();
}
return myHome.createState().build(context);
},
);
break;
case 1:
return CupertinoTabView(
builder: (BuildContext context) {
if(myNearMeState == null){
myNearMeState = myNearMe.createState();
}
return myNearMe.createState().build(context);
},
);
break;
case 2:
return CupertinoTabView(
builder: (BuildContext context) {
if(myMapState == null){
myMapState = myMap.createState();
}
return myMap.createState().build(context);
},
);
break;
case 3:
return CupertinoTabView(
builder: (BuildContext context) {
if(myNotificationsState == null){
myNotificationsState = myNotifications.createState();
}
return myNotifications.createState().build(context);
},
);
break;
case 4:
return CupertinoTabView(
builder: (BuildContext context) {
if(myWalletState == null){
myWalletState = myWallet.createState();
}
return myWallet.createState().build(context);
},
);
break;
}
},
);
}
}
class MyHome extends StatefulWidget {
#override
MyHomeState createState() => new MyHomeState();
}
class MyHomeState extends State<MyHome> {
#override
void initState() {
super.initState();
print('MyHomeState initState() called');
}
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("test stream"),
),
body: Container(
padding: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Text('HOME 1')
],
),
));
}
}
class MyNearMe extends StatefulWidget {
#override
MyNearMeState createState() => new MyNearMeState();
}
class MyNearMeState extends State<MyNearMe> {
#override
void initState() {
super.initState();
print('MyNearMeState initState() called');
}
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("MyNearMe"),
),
body: Container(
padding: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Text('My Near Me')
],
),
));
}
}
class MyMap extends StatefulWidget {
#override
MyMapState createState() => new MyMapState();
}
class MyMapState extends State<MyMap> {
#override
void initState() {
super.initState();
print('MyMapState initState() called');
}
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("MyMap"),
),
body: Container(
padding: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Text('My Map')
],
),
));
}
}
class MyNotifications extends StatefulWidget {
#override
MyNotificationsState createState() => new MyNotificationsState();
}
class MyNotificationsState extends State<MyNotifications> {
#override
void initState() {
super.initState();
print('MyNotificationsState initState() called');
}
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("MyNotifications"),
),
body: Container(
padding: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Text('My Notifications')
],
),
));
}
}
class MyWallet extends StatefulWidget {
#override
MyWalletState createState() => new MyWalletState();
}
class MyWalletState extends State<MyWallet> {
#override
void initState() {
super.initState();
print('MyWalletState initState() called');
}
#override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text("MyWallet"),
),
body: Container(
padding: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Text('My Wallet')
],
),
));
}
}
If you want to use another bottom navigation bar instead of cupertino then you can use as below:
I have created a sample example for you where initState() will call every time on tab change whether its same tab or different tab:
First of all import "bmnav: ^0.3.4" library in pubspec.yaml and then copy and paste below code:
import 'package:flutter/material.dart';
import 'package:bmnav/bmnav.dart' as bmnav;
Widget currentScreen = null;
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
currentScreen = MyHomeMapSample();
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
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> {
#override
void initState(){
super.initState();
}
int currentTab = 0;
int prevTab = 0;
final PageStorageBucket bucket = PageStorageBucket();
#override
Widget build(BuildContext ctx) {
debugPrint('currentTab: $currentTab');
return Scaffold(
body: PageStorage(child: currentScreen, bucket: bucket),
bottomNavigationBar: SizedBox(height: 58,
child: bmnav.BottomNav(
index: currentTab,
onTap: (i) {
setState(() {
currentTab = i;
currentScreen = getWidget(context, i);
if(prevTab==currentTab){
if(i==0){
MyHomeMapSample map = currentScreen as MyHomeMapSample;
map.createState().initState();
}else if(i==1){
MyHomeWorkouts map = currentScreen as MyHomeWorkouts;
map.createState().initState();
}
else if(i==2){
MyHomeAccount map = currentScreen as MyHomeAccount;
map.createState().initState();
}
}
prevTab = currentTab;
});
},
labelStyle: bmnav.LabelStyle(visible: true),
items: [
bmnav.BottomNavItem(Icons.map, label: 'Map'),
bmnav.BottomNavItem(Icons.cast, label: 'Workouts'),
bmnav.BottomNavItem(Icons.textsms, label: 'Account'),
],
),
),
resizeToAvoidBottomPadding: true,
);
}
Widget getWidget(BuildContext context, int i){
if(i==0){
return MyHomeMapSample();
}
else if(i==1){
return MyHomeWorkouts();
}else if(i==2){
return MyHomeAccount();
}
}
}
class MyHomeMapSample extends StatefulWidget {
MyHomeMapSample({Key key}) : super(key: key);
#override
MapSample createState() => MapSample();
}
class MapSample extends State<MyHomeMapSample> {
var myVariable = 0;
#override
void initState(){
super.initState();
debugPrint('current: MapSample: initState() called!');
}
#override
Widget build(BuildContext context) {
myVariable = myVariable + 1;
return Scaffold(
appBar: AppBar(
title: Text('MapSample'),
),
body: Center(
child: Text('MapSample details + $myVariable'),
),
resizeToAvoidBottomPadding: true,
);
}
}
class MyHomeWorkouts extends StatefulWidget {
MyHomeWorkouts({Key key}) : super(key: key);
#override
Workouts createState() => Workouts();
}
class Workouts extends State<MyHomeWorkouts> {
var myVariable = 0;
#override
void initState(){
super.initState();
debugPrint('current: Workouts: initState() called!');
}
#override
Widget build(BuildContext context) {
myVariable = myVariable + 1;
return Scaffold(
appBar: AppBar(
title: Text('Workouts'),
),
body: Center(
child: Text('Workouts details + $myVariable'),
),
resizeToAvoidBottomPadding: true,
);
}
}
class MyHomeAccount extends StatefulWidget {
MyHomeAccount({Key key}) : super(key: key);
#override
Account createState() => Account();
}
class Account extends State<MyHomeAccount> {
var myVariable = 0;
#override
void initState(){
super.initState();
debugPrint('current: Account: initState() called!');
}
#override
Widget build(BuildContext context) {
myVariable = myVariable + 1;
return Scaffold(
appBar: AppBar(
title: Text('Account'),
),
body: Center(
child: Text('Account details + $myVariable'),
),
resizeToAvoidBottomPadding: true,
);
}
}