Created
April 17, 2021 10:13
-
-
Save thenbe/b920c76e7c8be112acf4bdf07cdd30cb to your computer and use it in GitHub Desktop.
How to Access a Variable that is Associated with other Widget in Flutter?
This file contains 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
import 'package:flutter/material.dart'; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatefulWidget { | |
@override | |
_MyWidgetState createState() => _MyWidgetState(); | |
} | |
class _MyWidgetState extends State<MyWidget> { | |
String _currentEmoji = 'my initial emoji'; | |
void _setEmoji() { | |
// My Random Code Goes Here. (Never Mind) | |
setState(() { | |
_currentEmoji = 'new emoji'; | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Column(children: [ | |
ElevatedButton( | |
onPressed: _setEmoji, | |
child: Text('press me'), | |
), | |
Text(_currentEmoji), | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment