Showing
1 changed file
with
43 additions
and
36 deletions
@@ -422,65 +422,72 @@ class Controller extends GetController { | @@ -422,65 +422,72 @@ class Controller extends GetController { | ||
422 | } | 422 | } |
423 | } | 423 | } |
424 | ``` | 424 | ``` |
425 | -Controller life cycle: | ||
426 | -- onInit() where it is created. | ||
427 | -- onClose() where it is closed to make any changes in preparation for the delete method | ||
428 | -- deleted: you do not have access to this API because it is literally removing the controller from memory. It is literally deleted, without leaving any trace. | 425 | +Ciclo de vida do controller: |
426 | +* `onInit()`: Onde ele é criado. | ||
427 | +* `onClose()`: Onde ele é fechado para fazer mudanças em preparação para o método delete() | ||
428 | +* deleted: Você não tem mais acesso a essa API porque ela está literalmente removendo o controller da memória. Está literalmente deletado, sem deixar rastros. | ||
429 | 429 | ||
430 | -##### Forms of use: | 430 | +##### Formas de uso: |
431 | 431 | ||
432 | -- Recommended usage: | 432 | +* Uso recomendado; |
433 | 433 | ||
434 | -You can use Controller instance directly on GetBuilder value: | 434 | +Você pode usar uma instância do Controller diretamente no `value` do GetBuilder |
435 | 435 | ||
436 | ```dart | 436 | ```dart |
437 | GetBuilder<Controller>( | 437 | GetBuilder<Controller>( |
438 | - init: Controller(), | ||
439 | - builder: (value) => Text( | ||
440 | - '${value.counter}', //here | ||
441 | - )), | 438 | + init: Controller(), |
439 | + builder: (value) => Text( | ||
440 | + '${value.counter}', //aqui | ||
441 | + ) | ||
442 | +), | ||
442 | ``` | 443 | ``` |
443 | -You may also need an instance of your controller outside of your GetBuilder, and you can use these approaches to achieve this: | 444 | +Você talvez também precise de uma instância do seu controller fora do GetBuilder, e você pode usar essas abordagens para conseguir isso: |
444 | 445 | ||
446 | +essa: | ||
445 | ```dart | 447 | ```dart |
446 | class Controller extends GetController { | 448 | class Controller extends GetController { |
447 | - static Controller get to => Get.find(); | ||
448 | -[...] | 449 | + static Controller get to => Get.find(); // criando um getter estático |
450 | + [...] | ||
449 | } | 451 | } |
450 | -// on stateful/stateless class | ||
451 | -GetBuilder<Controller>( | ||
452 | - init: Controller(), // use it only first time on each controller | ||
453 | - builder: (_) => Text( | ||
454 | - '${Controller.to.counter}', //here | ||
455 | - )), | ||
456 | -or | 452 | +// Numa classe stateful/stateless |
453 | +GetBuilder<Controller>( | ||
454 | + init: Controller(), // use somente uma vez por controller, não se esqueça | ||
455 | + builder: (_) => Text( | ||
456 | + '${Controller.to.counter}', //aqui | ||
457 | + ) | ||
458 | +), | ||
459 | +``` | ||
457 | 460 | ||
461 | +ou essa: | ||
462 | +```dart | ||
458 | class Controller extends GetController { | 463 | class Controller extends GetController { |
459 | - // static Controller get to => Get.find(); // with no static get | 464 | + // sem nenhum método estático |
460 | [...] | 465 | [...] |
461 | } | 466 | } |
462 | -// on stateful/stateless class | ||
463 | -GetBuilder<Controller>( | ||
464 | - init: Controller(), // use it only first time on each controller | ||
465 | - builder: (_) => Text( | ||
466 | - '${Get.find<Controller>().counter}', //here | ||
467 | - )), | 467 | +// Numa classe stateful/stateless |
468 | +GetBuilder<Controller>( | ||
469 | + init: Controller(), // use somente uma vez por controller, não se esqueça | ||
470 | + builder: (_) => Text( | ||
471 | + '${Get.find<Controller>().counter}', //aqui | ||
472 | + ) | ||
473 | +), | ||
468 | ``` | 474 | ``` |
469 | 475 | ||
470 | -- You can use "non-canonical" approaches to do this. If you are using some other dependency manager, like get_it, modular, etc., and just want to deliver the controller instance, you can do this: | 476 | +* Você pode usar outras abordagens "menos regulares". Se você está utilizando outro gerenciador de dependências, como o get_it, modular, etc., e só quer entregar a instância do controller, pode fazer isso: |
471 | 477 | ||
472 | ```dart | 478 | ```dart |
473 | - | ||
474 | Controller controller = Controller(); | 479 | Controller controller = Controller(); |
475 | [...] | 480 | [...] |
476 | -GetBuilder( // you dont need to type on this way | ||
477 | - init: controller, //here | ||
478 | - builder: (_) => Text( | ||
479 | - '${controller.counter}', // here | ||
480 | - )), | 481 | +GetBuilder( // não precisa digitar desse jeito |
482 | + init: controller, //aqui | ||
483 | + builder: (_) => Text( | ||
484 | + '${controller.counter}', // aqui | ||
485 | + ) | ||
486 | +), | ||
481 | 487 | ||
482 | ``` | 488 | ``` |
483 | -This approach is not recommended, as you will have to manually dispose of your controllers, close your streams manually, and literally give up one of the great benefits of this library, which is intelligent memory control. But if you trust your potential, go ahead! | 489 | + |
490 | +Essa abordagem não é recomendade, uma vez que você vai precisar descartar os controllers manualmente, fechar seus stream manualmente, e literalmente abandonar um dos grandes benefícios desse package, que é controle de memória inteligente. Mas se você confia no seu potencial, vai em frente! | ||
484 | 491 | ||
485 | If you want to refine a widget's update control with GetBuilder, you can assign them unique IDs: | 492 | If you want to refine a widget's update control with GetBuilder, you can assign them unique IDs: |
486 | ```dart | 493 | ```dart |
-
Please register or login to post a comment