forked from ducafecat/getx_quick_start
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import 'package:get/get.dart'; | ||
|
||
class CountController extends GetxController { | ||
final _count = 0.obs; | ||
set count(value) => this._count.value = value; | ||
get count => this._count.value; | ||
|
||
final _count2 = 0.obs; | ||
set count2(value) => this._count2.value = value; | ||
get count2 => this._count2.value; | ||
|
||
add() => _count.value++; | ||
|
||
add2() => _count2.value++; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import 'package:flutter/material.dart'; | ||
// ignore: import_of_legacy_library_into_null_safe | ||
import 'package:get/get.dart'; | ||
import './controller.dart'; | ||
|
||
/* | ||
* GetBuilder 手动控制 | ||
* controller -> update | ||
*/ | ||
|
||
// ignore: must_be_immutable | ||
class StateGetBuilderView extends StatelessWidget { | ||
StateGetBuilderView({Key? key}) : super(key: key); | ||
|
||
var controller = CountController(); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text("GetBuilder"), | ||
), | ||
body: Center( | ||
child: Column( | ||
children: [ | ||
GetBuilder<CountController>( | ||
init: controller, | ||
initState: (_) {}, | ||
builder: (_) { | ||
print("GetBuilder - 1"); | ||
return Text('value -> ${_.count}'); | ||
}, | ||
), | ||
GetBuilder<CountController>( | ||
init: controller, | ||
initState: (_) {}, | ||
builder: (_) { | ||
print("GetBuilder - 2"); | ||
return Text('value -> ${_.count}'); | ||
}, | ||
), | ||
Divider(), | ||
|
||
// | ||
GetBuilder<CountController>( | ||
init: controller, | ||
initState: (_) {}, | ||
builder: (_) { | ||
print("GetBuilder - 3"); | ||
return Column( | ||
children: [ | ||
Text('value -> ${_.count}'), | ||
ElevatedButton( | ||
onPressed: () { | ||
_.add(); | ||
}, | ||
child: Text('GetBuilder -> add'), | ||
) | ||
], | ||
); | ||
}, | ||
), | ||
Divider(), | ||
|
||
// count2 | ||
GetBuilder<CountController>( | ||
init: controller, | ||
initState: (_) {}, | ||
builder: (_) { | ||
print("GetBuilder - 4"); | ||
return Text('value count2 -> ${_.count2}'); | ||
}, | ||
), | ||
Divider(), | ||
|
||
// id2 | ||
GetBuilder<CountController>( | ||
id: "id2", | ||
init: controller, | ||
initState: (_) {}, | ||
builder: (_) { | ||
print("GetBuilder - 4"); | ||
return Text('id2 -> value count2 -> ${_.count2}'); | ||
}, | ||
), | ||
Divider(), | ||
|
||
// 按钮 | ||
ElevatedButton( | ||
onPressed: () { | ||
controller.add(); | ||
}, | ||
child: Text('add'), | ||
), | ||
|
||
ElevatedButton( | ||
onPressed: () { | ||
controller.add2(); | ||
}, | ||
child: Text('add2'), | ||
), | ||
|
||
ElevatedButton( | ||
onPressed: () { | ||
controller.update(); | ||
}, | ||
child: Text('controller.update()'), | ||
), | ||
|
||
ElevatedButton( | ||
onPressed: () { | ||
controller.update(["id2"]); | ||
}, | ||
child: Text('controller.update(id2)'), | ||
), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
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