我正在玩扑扑,
\n我遇到错误并且没有得到任何正确的解决方案
\n在我的应用程序中,我的GetX控制器中有一些可观察的变量,当尝试应用某种格式然后在此处获取日志时
\n======== Exception caught by widgets library =======================================================\nThe following _TypeError was thrown building Obx(dirty, state: _ObxState#76641):\ntype \'int\' is not a subtype of type \'RxInt\' of \'function result\'\n\nThe relevant error-causing widget was: \n Obx file:///D:/flutter/mini_rupiya/lib/views/screens/payment.dart:84:17\nWhen the exception was thrown, this was the stack: \n#0 DepositController.total (package:mini_rupiya/controllers/deposit_controller.dart)\n#1 _PaymentState.build.<anonymous closure> (package:mini_rupiya/views/screens/payment.dart:84:145)\n#2 Obx.build (package:get/get_state_manager/src/rx_flutter/rx_obx_widget.dart:84:28)\n#3 _ObxState.notifyChilds (package:get/get_state_manager/src/rx_flutter/rx_obx_widget.dart:52:27)\n#4 _ObxState.build (package:get/get_state_manager/src/rx_flutter/rx_obx_widget.dart:68:41)\n...\n====================================================================================================\nReloaded 7 of 1033 libraries in 2,688ms.\n\n======== Exception caught by rendering library =====================================================\nThe following assertion was thrown during layout:\nA RenderFlex overflowed …Run Code Online (Sandbox Code Playgroud) 我有两个页面,设置页面和登录页面,如 getx 文档所述,它们与它们的控制器绑定,并且我使用 GetMacial() 小部件来包装应用程序树,但是当我使用 Get.to() 进入设置页面时转到登录页面,它显示此错误,尽管我进行了文件绑定并在绑定文件中正确添加了用户控制器。
AS旁注:状态管理工作正常,没有任何问题,唯一的问题是导航。
> ======== Exception caught by widgets library ======================================================= The following message was thrown building LoginPage(dirty): "UserController" not
> found. You need to call "Get.put(UserController())" or
> "Get.lazyPut(()=>UserController())"
>
> The relevant error-causing widget was: LoginPage
> file:///D:/projects/talab/lib/modules/settings/views/settings_page.dart:141:42
> When the exception was thrown, this was the stack:
> #0 GetInstance.find (package:get/get_instance/src/get_instance.dart:332:7)
> #1 GetView.controller (package:get/get_state_manager/src/simple/get_view.dart:38:37)
> #2 LoginPage.build (package:talab/modules/users/views/login_page.dart:33:26)
> #3 StatelessElement.build (package:flutter/src/widgets/framework.dart:4569:28)
> #4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4495:15)
the settings controller
import 'package:flutter/material.dart'; …Run Code Online (Sandbox Code Playgroud) 我正在启动一个 flutter 项目,很多人说 GetX 是在 flutter 中使用的最好的状态管理器框架,所以我决定使用它。
我想在 HomePage 类中做一些动画,但是当我使用 mixin SingleTickerProviderStateMixin 时,它会抛出一个编译错误
error: 'SingleTickerProviderStateMixin<StatefulWidget>' can't be mixed onto 'GetView<HomePageController>' because 'GetView<HomePageController>' doesn't implement 'State<StatefulWidget>'.
Run Code Online (Sandbox Code Playgroud)
这是我的代码
class HomePage extends GetView<HomePageController> with SingleTickerProviderStateMixin {
final Duration duration = const Duration(milliseconds: 300);
AnimationController _animationController;
HomePage() {
_animationController = AnimationController(vsync: this, duration: duration);
}
@override
Widget build(BuildContext context) {
return Container();
}
}
Run Code Online (Sandbox Code Playgroud)
因为要初始化 AnimationController,它需要一个名为“vsync”的参数,所以我必须实现 mixin SingleTickerProviderStateMixin。但是因为 GetView<> 没有实现 State 所以它会抛出编译错误。
我不知道在 GetX 中实现动画的正确方法是什么,奇怪的是我无法在 Google 或任何 flutter 社区上找到任何线索或指南,尽管 GetX 广泛流行
我有一个这样的列表:
List<Country> countries = [
Country(name: 'United States', border: ['Mexico', 'Canada']),
Country(name: 'Mexico', border: ['United States']),
Country(name: 'Canada'),
];
Run Code Online (Sandbox Code Playgroud)
在HomeView页面上将出现一个列表countries.name,单击时 => 转到显示的DetailsView页面countries.border
在此详细信息视图页面中,我希望当单击哪个时countries.border,它将推送到新的详细信息视图页面countries.name == countries.border。
我能够做到这一点Navigator().push
//Use Navigator().push
Navigator.of(context).push(MaterialPageRoute(
builder: (_) => DetailView(country: controller.countries[i]),
Run Code Online (Sandbox Code Playgroud)
但不能这样做Get.to:
//Use Get.to not succeed
Get.to(() => DetailView(country: controller.countries[i]));
Run Code Online (Sandbox Code Playgroud)
所以请帮助我,这是完整的代码:
import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() async {
runApp(GetMaterialApp(
debugShowCheckedModeBanner: false,
home: HomeView(),
));
}
class Country {
String name;
List<String> …Run Code Online (Sandbox Code Playgroud) 当我将项目添加到 obs 子列表时,小部件不会更新。如果我将一个项目添加到主列表中,它就可以正常工作。
请帮助我正确实施反应式。
home_controller.dart
import 'package:get/get.dart';
class FoodCategory {
final String name;
final List<String> foods;
FoodCategory({required this.name, required this.foods});
}
class HomeController extends GetxController {
late final List<FoodCategory> foodList;
@override
void onInit() {
super.onInit();
foodList = [
FoodCategory(name: "Fruits", foods: ["Apple", "Orange"]),
FoodCategory(name: "Vegetable", foods: ["Carrot", "Beans"])
].obs;
}
void addFood(index, food) {
foodList[index].foods.add(food); // Not Working. Item added but UI not re-rendered.
print(food + " added");
}
void addCategory(FoodCategory foodcategory) {
foodList.add(foodcategory); // Working Fine.
print("New food category …Run Code Online (Sandbox Code Playgroud) 请帮我。我做错了什么?我收到错误:
[Get] the improper use of a GetX has been detected.
这是代码:
class MealRecipesItem extends StatefulWidget {
const MealRecipesItem({
Key? key,
@required this.gender,
this.item,
}) : super(key: key);
final int? gender;
final Data? item;
@override
_MealRecipesItemState createState() => _MealRecipesItemState(item?.id);
}
class _MealRecipesItemState extends State<MealRecipesItem> {
final itemId;
_MealRecipesItemState(this.itemId) {
Get.put(RecipeDetailController(), tag: itemId);
}
@override
Widget build(BuildContext context) {
var controller = Get.find<RecipeDetailController>(tag: itemId);
_toggleFavorite() {
controller.toggleFavorite(widget.item?.databaseId);
}
return Material(
child: InkWell(
onTap: _toggleFavorite,
child: Container(
child: Obx(() { // ====**** …Run Code Online (Sandbox Code Playgroud) 我正在我的项目中使用 getx,我正在尝试使用 getx 依赖注入。我创建 AddBinding 类:
\nclass AddBinding implements Bindings {\n @override\n void dependencies() {\n Get.lazyPut<AddController>(\n () => AddController(\n AddRepository(),\n Get.find<DialogService>(),\n ),\n );\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n我添加GetPage了这样的绑定:
GetPage(\n name: Routes.ADD,\n page: () => AddPage(),\n binding: AddBinding(),\n),\nRun Code Online (Sandbox Code Playgroud)\n现在在我的主页
\nclass HomePage extends GetView<HomeController> {\n @override\n Widget build(BuildContext context) {\n return Scaffold(\n appBar: AppBar(\n // title: const Text('HomePage'),\n title: TabBar(\n controller: controller.controller,\n tabs: controller.myTabs,\n ),\n ),\n body: Padding(\n padding: const EdgeInsets.all(8.0),\n child: TabBarView(\n controller: controller.controller,\n physics: const NeverScrollableScrollPhysics(),\n …Run Code Online (Sandbox Code Playgroud) 我创建了一个带有标签的控制器,我需要访问控制器内的该标签,这可能吗?
这就是我放置控制器的方式
final ProfileController _profileController = Get.put(ProfileController(), tag: "12345etc");
Run Code Online (Sandbox Code Playgroud)
我将在ProfileController中使用该标签,但我无法访问该标签。
class ProfileController extends GetxController {
//load info from 12345etc userid
Future<void> viewProfile() {
Services.loadProfileInfo("12345etc")...
}
}
Run Code Online (Sandbox Code Playgroud)
标签12345etc将从另一个控制器加载,它不会是固定文本。
这是我的完整代码...
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class DialogHelper{
//show error dialog
static void showErrorDialog({String title='error',String description='Something went wrong'})
{
Get.dialog(
Dialog(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(title,style: Get.textTheme.headline4,),
Text(description,style: Get.textTheme.headline6,),
ElevatedButton(onPressed: () {
if (Get.isDialogOpen) Get.back();
},
child: Text('okay')),
],
),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误
19:25:错误:“bool?”类型的值 无法分配给“bool”类型的变量,因为“bool?” 可以为空,而 'bool' 则不能。if (Get.isDialogOpen) Get.back();
如果条件 Get.isDialogOpen 线上出现错误
我正在使用 flutter web 构建一个网站。我的网站中有两个主要路线,一个登录页面(也是初始路线)和一个主页。我使用Get在路线之间移动,并使用url_strategy包设置路径导航策略。
主dart
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
setPathUrlStrategy();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
debugShowCheckedModeBanner: false,
title: 'website',
unknownRoute: GetPage(
name: '/notfound',
page: () => UnknownRoutePage(),
),
initialRoute: '/LoginPage',
getPages: [
GetPage(
name: '/LoginPage',
page: () => LoginPage(),
),
GetPage(
name: '/HomePage',
page: () => HomePage(),
)
],
);
}
}
Run Code Online (Sandbox Code Playgroud)
同时,当我在我的电脑上调试时一切正常(即使使用 flutter run --release),当我在 Firebase 托管上部署网站时,我遇到了问题。
假设我尝试重新加载页面(例如www.website.com/LoginPage),但我从 Firebase 托管中找不到默认页面(即使我设置了自定义未找到页面),而我希望重定向到 LoginPage我的网站。
我该如何解决这个问题?
flutter-getx ×10
flutter ×9
dart ×6
get ×2
animation ×1
flutter-get ×1
flutter-web ×1
mixins ×1
rxdart ×1
state ×1