我想根据 PressBool 是 false 还是 true 来更改小部件的主体。
这是我写的GetxController。
import 'package:get/state_manager.dart';
class PressedState extends GetxController{
var pressedBool = true;
changeStatus() {
if(pressedBool){
pressedBool = false;
}
else {
pressedBool = true;
}
update();
}
}
Run Code Online (Sandbox Code Playgroud)
这里是 GetX 更新和监听应该改变页面正文的地方:
final PressedState pressController = Get.put(PressedState());
return MaterialButton(
onPressed: () {
pressController.changeStatus();
},
child:
pressController.pressedBool
? Container(...) : Container(...)), ...
Run Code Online (Sandbox Code Playgroud)
如何让 GetX 监听 PressBool 变量?
如何从打开对话框小部件/警报对话框的 Get.Dialog 获取返回值?
我的视图层中有这个语句
TextEditingController controllerDestino = TextEditingController();
Run Code Online (Sandbox Code Playgroud)
我想恢复这个controllerDestino,以便在我的控制器层中的方法中使用。
statusUberNaoChamado() {
showBoxAdress = true;
changeMainButton("Chamar", Color(0xFF1ebbd8), () {
callUber("I need pass the controller here");
});
update();}
Run Code Online (Sandbox Code Playgroud)
预先感谢您的关注:)
我有一个页面,可以根据该页面的启动位置以两种方式呈现:模态和推送。
我曾经toNamed展示这些页面,但问题是我无法fullscreenDialog在调用站点传递标志。我期待这样的事情:
Get.toNamed('pageName', fullscreenDialog: false);
Run Code Online (Sandbox Code Playgroud)
那么,这种工作我需要两条路线和两个页面吗?像这样的东西:
GetPage(
name: 'pageNameDialog',
page: () => QuestionPage(),
fullscreenDialog: true,
binding: QuestionBinding(),
),
GetPage(
name: 'pageNamePush',
page: () => QuestionPage(),
fullscreenDialog: false,
binding: QuestionBinding(),
),
Run Code Online (Sandbox Code Playgroud)
我认为这应该是一个更好的方法,但我对 Flutter 和 getx 真的很陌生,不知道我应该搜索什么。有人有解决方案吗?否则,我可能不得不加倍我的路线和页面,这是相当多余的。
我可以使用Get.defaultDialog()函数创建弹出对话框。我在 GetX 中找不到用于创建自定义警报对话框的方法。
我正在使用下面的函数来实现使用本机 flutter showDialog api 的函数。
showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: categoryNameController,
keyboardType: TextInputType.text,
maxLines: 1,
decoration: InputDecoration(
labelText: 'Category Name',
hintMaxLines: 1,
border: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.green, width: 4.0))),
),
SizedBox(
height: 30.0,
),
RaisedButton(
onPressed: () {
if (categoryNameController.text.isNotEmpty) {
var expenseCategory = ExpenseCategory(
categoryNameController.text,
id: _addExpenseController.expenseCategories.length);
_expenseController.addExpenseCategory(expenseCategory);
_addExpenseController.expenseCategories
.add(expenseCategory);
Get.back();
}
},
child: Text(
'ADD CATEGORY',
style: TextStyle(color: Colors.white, fontSize: 16.0),
), …Run Code Online (Sandbox Code Playgroud) 我有以下 GetX 控制器将参数传递到 Flutter 中的页面:
更新
class HomeController extends GetxController {
File image;
String ocr_text;
onInit(){
super.onInit();
image = Get.arguments['image'];
ocr_text = Get.arguments['ocr_text'];
update();
}
}
Run Code Online (Sandbox Code Playgroud)
捆绑:
class HomeBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut<HomeController>(() => HomeController());
}
}
Run Code Online (Sandbox Code Playgroud)
我想从 Ocr_details 页面传递图像:
FlatButton(
color: Colors.blue,
child: Icon(Icons.save_outlined),
onPressed: () {
Get.toNamed(
AppRoutes.HOME,
arguments: {'image': controller.image, 'ocr_text': controller.text},
);
}
),
Run Code Online (Sandbox Code Playgroud)
到主页:
更新:
Container(
padding: EdgeInsets.all(32),
child: GetBuilder<HomeController>(
builder: (_) {
return _.image != null
? Image.file(_.image)
: …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过这个演示项目学习状态管理和依赖注入。我正在尝试演示在整个地方注入一些方法,就像我的程序中可能需要的那样。我使用 GetX 是因为我喜欢能够在非小部件类中无需上下文即可执行此操作。
\n所以我的问题是下面最后一个类中的最后一个方法 summationReturns() 。尝试采用带有 return 语句的方法并将它们添加在一起。我在两个地方这样称呼它。在浮动按钮中,这工作正常,但在我的文本小部件中,我收到脏状态错误。
\n为什么当其他一切都有效时这不起作用?我认为这将是最后一个问题的必然结果,什么是脏状态?看起来像是两个问题,但我想它们是同一个问题。
\n///\n///\n/// DEMO PROJECT WORKING OUT GETX\n/// WORKOUT DEPENDANCY INJECTION AND STATE MANAGEMENT\n\nimport 'package:flutter/material.dart';\nimport 'package:get/get.dart';\nimport 'package:get/get_state_manager/get_state_manager.dart';\n\nvoid main() {\n runApp(GetMaterialApp(\n home: Home(),\n debugShowCheckedModeBanner: false,\n ));\n}\n\nclass Home extends StatelessWidget {\n // Injection of dependancy\n final Controller controller = Get.put(Controller());\n final Observable observable = Get.put(Observable());\n final SimpleMath simpleMath = Get.put(SimpleMath());\n\n @override\n Widget build(BuildContext context) {\n return Scaffold(\n appBar: AppBar(\n title: Text('GetX Demo'),\n ),\n body: Center(\n child: Column(\n mainAxisAlignment: MainAxisAlignment.center,\n children: <Widget>[\n Text('Get …Run Code Online (Sandbox Code Playgroud) 如果小部件的自定义 getx 控制器具有基于每隔特定秒运行一次的计时器的计数器增量。
问题是,即使应用程序处于后台或屏幕锁定,计数器增量功能也会继续运行。
我知道如何停止/取消计时器,但如果应用程序未激活,我想这样做。因此,使用 GetX 包如何获取应用程序状态,例如正在运行、被用户关闭、在后台运行但在屏幕上不活动等。
谢谢。
我正在尝试加载产品列表,并且正在使用 CachedNetworkImage (或者如果我也使用 Image.network)来显示该特定产品的图像。
\n我使用了 Error Builder 属性,这样如果图像出现错误,则显示默认资源图像并且工作正常。直到我将另一个页面推到它上面,然后我在调试控制台中收到以下内容。
\nI/flutter (21932): \xe2\x95\x90\xe2\x95\x90\xe2\x95\xa1 EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE \xe2\x95\x9e\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\nI/flutter (21932): The following NetworkImageLoadException was thrown resolving an image codec:\nI/flutter (21932): HTTP request failed, statusCode: 404, https://***.com/url.jpg\n\nRun Code Online (Sandbox Code Playgroud)\n但是,我在某处读到,如果我们收到此类错误,则忽略它,因为 CachedNetoworkImage 作者也在他的最后一行文档中说了同样的话。但问题是我还使用 Firebase Crashlytics 来显示崩溃和错误(如果有)。
\n问题是由于这个异常,我收到了非致命错误。因此,即使 1 个用户正在使用我的应用程序,他们也不会在屏幕上看到任何错误,但如果我使用 crashlytics,我会收到该特定用户的超过 48 个非致命错误。\n
这是我用于显示产品列表及其图像的代码\n ProductTile.dart
\nimport \'package:applicationName/views/product_page/model/ProductModel.dart\';\nimport \'package:flutter/material.dart\';\nimport \'package:cached_network_image/cached_network_image.dart\';\nimport \'package:get/get.dart\';\n\nclass ProductTile extends StatelessWidget {\n final Product product;\n const ProductTile(this.product);\n @override\n Widget build(BuildContext context) {\n return InkWell(\n onTap: () {\n Get.toNamed("/productDetailPage/${product.prodId}");\n …Run Code Online (Sandbox Code Playgroud) 使用 flutter 和 Getx 状态管理创建一个购物应用程序。我不知道如何为列表中的每个元素创建一个控制器。这样,列表中特定元素的任何更改都只会重新加载该元素,而不是整个列表重新加载。
如果我单击“新订单”容器,其他容器(“订单已确认”、“已完成”)也会重建(整个列表视图重建)。
我的型号:
import 'package:get/get.dart';
class TabModel {
late String tabName;
RxBool isSelected = false.obs;
TabModel(this.tabName);
}
Run Code Online (Sandbox Code Playgroud)
我的控制器:
import 'package:get/get.dart';
import 'package:super_mart_merchant/view/orders/view_models/tab_model.dart';
import 'package:collection/collection.dart';
class TabViewController extends GetxController{
RxList<TabModel> tabModels = <TabModel>[].obs;
@override
void onInit() {
super.onInit();
loadVal('New Order',true);
loadVal('Order Confirmed',false);
loadVal('Order Declined',false);
loadVal('Completed',false);
}
void loadVal(String name,bool isSelected){
TabModel tabModel = TabModel(name);
tabModel.isSelected.value = isSelected;
tabModels.add(tabModel);
}
void onClick(int pos){
TabModel tabModel = tabModels[pos];
if(!tabModel.isSelected.value){
TabModel? previousTabModel = tabModels.firstWhereOrNull((element) => element.isSelected.value);
if(previousTabModel != null){
previousTabModel.isSelected.value …Run Code Online (Sandbox Code Playgroud)