Created
March 6, 2018 02:31
-
-
Save patientplatypus/bf3950a5cf93d62b9e91157a7850459d to your computer and use it in GitHub Desktop.
Having trouble updating passed variable in flutter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NavigationState extends State<MyNavigationHolder> { | |
var goToPass = "/page1"; | |
assignPass(page){ | |
print("inside assignPass"); | |
print("value of page: " + page); | |
setState(() {goToPass = page;}); | |
} | |
//button gets pressed and assignPass updates goToPass with new page val | |
//then I call HeaderPage | |
new Flexible( | |
child: new HeaderPage(goTo: goToPass) | |
), | |
//Inside header page: | |
import 'package:flutter/material.dart'; | |
import 'main.dart'; | |
class HeaderPage extends StatefulWidget { | |
const HeaderPage({ | |
Key key, | |
this.goTo | |
}) : super(key: key); | |
final String goTo; | |
@override | |
HeaderPageState createState() => new HeaderPageState(goTo); | |
} | |
class HeaderPageState extends State<HeaderPage> { | |
HeaderPageState(this.goTo); | |
final String goTo; | |
String goToPass; | |
sunPressed(){ | |
} | |
moonPressed(){ | |
} | |
@override | |
void initState() { | |
// TODO: implement initState | |
super.initState(); | |
setState(() {goToPass = goTo;}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
print("value of goTo in Widget build: " + goToPass); | |
Widget ButtonGrad(){ | |
print("value of goTo: " + goToPass); | |
if (goToPass=="/page3"){ | |
//magic happens | |
//i only want to fire buttongrad if goToPass="/page3") | |
//PROBLEM: goToPass is always == "/page1" and I don't know why; | |
//Output from console: | |
Performing full restart... | |
Restarted app in 2,570ms. | |
I/flutter ( 5550): value of goTo in Widget build: /page1 | |
I/flutter ( 5550): value of goTo: /page1 | |
I/flutter ( 5550): inside assignPass | |
I/flutter ( 5550): value of page: /page2 | |
I/flutter ( 5550): value of goTo in Widget build: /page1 | |
I/flutter ( 5550): value of goTo: /page1 | |
I/flutter ( 5550): inside assignPass | |
I/flutter ( 5550): value of page: /page4 | |
I/flutter ( 5550): value of goTo in Widget build: /page1 | |
I/flutter ( 5550): value of goTo: /page1 | |
I/flutter ( 5550): inside assignPass | |
I/flutter ( 5550): value of page: /page1 | |
I/flutter ( 5550): value of goTo in Widget build: /page1 | |
I/flutter ( 5550): value of goTo: /page1 | |
I/flutter ( 5550): inside assignPass | |
I/flutter ( 5550): value of page: /page3 | |
I/flutter ( 5550): value of goTo in Widget build: /page1 | |
I/flutter ( 5550): value of goTo: /page1 | |
I/flutter ( 5550): inside getActivityList | |
//What am I doing wrong? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment