Committed by
GitHub
Merge pull request #1223 from 3lB4rt0/master
Little improvements of example code
Showing
3 changed files
with
21 additions
and
24 deletions
| @@ -282,6 +282,7 @@ As the view has only widgets, you can use a view for android, and another for iO | @@ -282,6 +282,7 @@ As the view has only widgets, you can use a view for android, and another for iO | ||
| 282 | However, some examples like internationalization, Snackbars without context, validators, responsiveness and other Getx resources, were not explored (and it would not even be possible to explore all resources in such a simple example), so below is an example not very complete, but trying demonstrate how to use internationalization, reactive custom classes, reactive lists, snackbars contextless, workers etc. | 282 | However, some examples like internationalization, Snackbars without context, validators, responsiveness and other Getx resources, were not explored (and it would not even be possible to explore all resources in such a simple example), so below is an example not very complete, but trying demonstrate how to use internationalization, reactive custom classes, reactive lists, snackbars contextless, workers etc. | 
| 283 | 283 | ||
| 284 | ```dart | 284 | ```dart | 
| 285 | +import 'dart:ui'; | ||
| 285 | import 'package:flutter/material.dart'; | 286 | import 'package:flutter/material.dart'; | 
| 286 | import 'package:get/get.dart'; | 287 | import 'package:get/get.dart'; | 
| 287 | 288 | ||
| @@ -397,29 +398,27 @@ class Second extends GetView<ControllerX> { | @@ -397,29 +398,27 @@ class Second extends GetView<ControllerX> { | ||
| 397 | child: Column( | 398 | child: Column( | 
| 398 | mainAxisAlignment: MainAxisAlignment.center, | 399 | mainAxisAlignment: MainAxisAlignment.center, | 
| 399 | children: [ | 400 | children: [ | 
| 400 | - GetX<ControllerX>( | ||
| 401 | - // Using bindings you don't need of init: method | ||
| 402 | - // Using Getx you can take controller instance of "builder: (_)" | ||
| 403 | - builder: (_) { | 401 | + Obx( | 
| 402 | + () { | ||
| 404 | print("count1 rebuild"); | 403 | print("count1 rebuild"); | 
| 405 | - return Text('${_.count1}'); | 404 | + return Text('${controller.count1}'); | 
| 406 | }, | 405 | }, | 
| 407 | ), | 406 | ), | 
| 408 | - GetX<ControllerX>( | ||
| 409 | - builder: (_) { | 407 | + Obx( | 
| 408 | + () { | ||
| 410 | print("count2 rebuild"); | 409 | print("count2 rebuild"); | 
| 411 | return Text('${controller.count2}'); | 410 | return Text('${controller.count2}'); | 
| 412 | }, | 411 | }, | 
| 413 | ), | 412 | ), | 
| 414 | - GetX<ControllerX>(builder: (_) { | 413 | + Obx(() { | 
| 415 | print("sum rebuild"); | 414 | print("sum rebuild"); | 
| 416 | - return Text('${_.sum}'); | 415 | + return Text('${controller.sum}'); | 
| 417 | }), | 416 | }), | 
| 418 | - GetX<ControllerX>( | ||
| 419 | - builder: (_) => Text('Name: ${controller.user.value.name}'), | 417 | + Obx( | 
| 418 | + () => Text('Name: ${controller.user.value?.name}'), | ||
| 420 | ), | 419 | ), | 
| 421 | - GetX<ControllerX>( | ||
| 422 | - builder: (_) => Text('Age: ${_.user.value.age}'), | 420 | + Obx( | 
| 421 | + () => Text('Age: ${controller.user.value?.age}'), | ||
| 423 | ), | 422 | ), | 
| 424 | ElevatedButton( | 423 | ElevatedButton( | 
| 425 | child: Text("Go to last page"), | 424 | child: Text("Go to last page"), | 
| @@ -440,25 +439,25 @@ class Second extends GetView<ControllerX> { | @@ -440,25 +439,25 @@ class Second extends GetView<ControllerX> { | ||
| 440 | ElevatedButton( | 439 | ElevatedButton( | 
| 441 | child: Text("Increment"), | 440 | child: Text("Increment"), | 
| 442 | onPressed: () { | 441 | onPressed: () { | 
| 443 | - Get.find<ControllerX>().increment(); | 442 | + controller.increment(); | 
| 444 | }, | 443 | }, | 
| 445 | ), | 444 | ), | 
| 446 | ElevatedButton( | 445 | ElevatedButton( | 
| 447 | child: Text("Increment"), | 446 | child: Text("Increment"), | 
| 448 | onPressed: () { | 447 | onPressed: () { | 
| 449 | - Get.find<ControllerX>().increment2(); | 448 | + controller.increment2(); | 
| 450 | }, | 449 | }, | 
| 451 | ), | 450 | ), | 
| 452 | ElevatedButton( | 451 | ElevatedButton( | 
| 453 | child: Text("Update name"), | 452 | child: Text("Update name"), | 
| 454 | onPressed: () { | 453 | onPressed: () { | 
| 455 | - Get.find<ControllerX>().updateUser(); | 454 | + controller.updateUser(); | 
| 456 | }, | 455 | }, | 
| 457 | ), | 456 | ), | 
| 458 | ElevatedButton( | 457 | ElevatedButton( | 
| 459 | child: Text("Dispose worker"), | 458 | child: Text("Dispose worker"), | 
| 460 | onPressed: () { | 459 | onPressed: () { | 
| 461 | - Get.find<ControllerX>().disposeWorker(); | 460 | + controller.disposeWorker(); | 
| 462 | }, | 461 | }, | 
| 463 | ), | 462 | ), | 
| 464 | ], | 463 | ], | 
| @@ -509,7 +508,7 @@ class ControllerX extends GetxController { | @@ -509,7 +508,7 @@ class ControllerX extends GetxController { | ||
| 509 | 508 | ||
| 510 | updateUser() { | 509 | updateUser() { | 
| 511 | user.update((value) { | 510 | user.update((value) { | 
| 512 | - value.name = 'Jose'; | 511 | + value!.name = 'Jose'; | 
| 513 | value.age = 30; | 512 | value.age = 30; | 
| 514 | }); | 513 | }); | 
| 515 | } | 514 | } | 
| @@ -523,7 +522,7 @@ class ControllerX extends GetxController { | @@ -523,7 +522,7 @@ class ControllerX extends GetxController { | ||
| 523 | /// Here is an outline of how you can use them: | 522 | /// Here is an outline of how you can use them: | 
| 524 | 523 | ||
| 525 | /// made this if you need cancel you worker | 524 | /// made this if you need cancel you worker | 
| 526 | - Worker _ever; | 525 | + late Worker _ever; | 
| 527 | 526 | ||
| 528 | @override | 527 | @override | 
| 529 | onInit() { | 528 | onInit() { | 
| @@ -562,8 +561,8 @@ class SizeTransitions extends CustomTransition { | @@ -562,8 +561,8 @@ class SizeTransitions extends CustomTransition { | ||
| 562 | @override | 561 | @override | 
| 563 | Widget buildTransition( | 562 | Widget buildTransition( | 
| 564 | BuildContext context, | 563 | BuildContext context, | 
| 565 | - Curve curve, | ||
| 566 | - Alignment alignment, | 564 | + Curve? curve, | 
| 565 | + Alignment? alignment, | ||
| 567 | Animation<double> animation, | 566 | Animation<double> animation, | 
| 568 | Animation<double> secondaryAnimation, | 567 | Animation<double> secondaryAnimation, | 
| 569 | Widget child) { | 568 | Widget child) { | 
| @@ -572,7 +571,7 @@ class SizeTransitions extends CustomTransition { | @@ -572,7 +571,7 @@ class SizeTransitions extends CustomTransition { | ||
| 572 | child: SizeTransition( | 571 | child: SizeTransition( | 
| 573 | sizeFactor: CurvedAnimation( | 572 | sizeFactor: CurvedAnimation( | 
| 574 | parent: animation, | 573 | parent: animation, | 
| 575 | - curve: curve, | 574 | + curve: curve!, | 
| 576 | ), | 575 | ), | 
| 577 | child: child, | 576 | child: child, | 
| 578 | ), | 577 | ), | 
| @@ -18,7 +18,6 @@ class CountryView extends GetView<HomeController> { | @@ -18,7 +18,6 @@ class CountryView extends GetView<HomeController> { | ||
| 18 | child: BackdropFilter( | 18 | child: BackdropFilter( | 
| 19 | filter: ImageFilter.blur(sigmaX: 15.0, sigmaY: 15.0), | 19 | filter: ImageFilter.blur(sigmaX: 15.0, sigmaY: 15.0), | 
| 20 | child: Container( | 20 | child: Container( | 
| 21 | - decoration: BoxDecoration(color: Colors.white.withOpacity(0.0)), | ||
| 22 | child: Scaffold( | 21 | child: Scaffold( | 
| 23 | backgroundColor: Colors.transparent, | 22 | backgroundColor: Colors.transparent, | 
| 24 | appBar: AppBar( | 23 | appBar: AppBar( | 
| @@ -21,7 +21,6 @@ class DetailsView extends StatelessWidget { | @@ -21,7 +21,6 @@ class DetailsView extends StatelessWidget { | ||
| 21 | child: BackdropFilter( | 21 | child: BackdropFilter( | 
| 22 | filter: ImageFilter.blur(sigmaX: 15.0, sigmaY: 15.0), | 22 | filter: ImageFilter.blur(sigmaX: 15.0, sigmaY: 15.0), | 
| 23 | child: Container( | 23 | child: Container( | 
| 24 | - decoration: BoxDecoration(color: Colors.white.withOpacity(0.0)), | ||
| 25 | child: Scaffold( | 24 | child: Scaffold( | 
| 26 | backgroundColor: Colors.transparent, | 25 | backgroundColor: Colors.transparent, | 
| 27 | appBar: AppBar( | 26 | appBar: AppBar( | 
- 
Please register or login to post a comment