Created
April 8, 2021 15:14
-
-
Save RipplesCode/09ba55dcb076ba8084365e68e10bea07 to your computer and use it in GitHub Desktop.
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'; | |
import 'package:flutter_getx/next_screen.dart'; | |
import 'package:flutter_getx/student.dart'; | |
import 'package:flutter_getx/unknown_route.dart'; | |
import 'package:get/get.dart'; | |
import 'home.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
var student = Student(); | |
// For making the entire class observable | |
//final student=Student( name:"tom",age:25).obs; | |
@override | |
Widget build(BuildContext context) { | |
// TODO: implement build | |
return GetMaterialApp( | |
title: "State Management", | |
home: Scaffold( | |
appBar: AppBar(title: Text("State Management")), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
crossAxisAlignment: CrossAxisAlignment.center, | |
children: [ | |
Obx(() => Text( | |
"Name is ${student.name.value}", | |
style: TextStyle(fontSize: 25), | |
)), | |
SizedBox( | |
height: 16, | |
), | |
RaisedButton( | |
child: Text("Upper"), | |
onPressed: () { | |
//If individual variables are observable | |
student.name.value = student.name.value.toUpperCase(); | |
// If entire class is observable | |
// student.update((student) { | |
// student.name=student.name.toString().toUpperCase(); | |
// }); | |
}, | |
), | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
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:get/get.dart'; | |
class Student { | |
/* Classes can be made observable by making individuals variables Rx | |
or by making the entire class observable. | |
*/ | |
// Individuals variables Rx | |
var name = "Tom".obs; | |
var age = 25.obs; | |
// To make the entire class observable | |
// var name; | |
// var age; | |
// Student({this.name, this.age}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment