我正在尝试加载产品列表,并且正在使用 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) 我有一个使用 GetX 进行导航的基本网站。我有带有 ontap 功能的墨水池,可以导航到新视图。现在,如果您右键单击这些按钮,则不会出现“在新选项卡/窗口中打开链接”、“链接另存为”或“复制链接地址”。
有什么方法可以让 Flutter Web 获得这个功能吗?
使用 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) 每当我的 GetX 状态发生变化时,如何调用无状态小部件中的特定函数?例如,每当我的底部导航栏的索引发生变化时,如何触发事件?
Obx(
() =>
BottomNavigationBar(
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.explore),
label: 'Erkunden',
),
],
currentIndex: bottomNavigationController.index.value,
onTap: (index) {
bottomNavigationController.changeIndex(index);
},
)
),
Run Code Online (Sandbox Code Playgroud)
编辑:
class BottomNavigationController extends GetxController {
RxInt index = 0.obs;
void changeIndex(int val) {
index.value = val;
}
}
Run Code Online (Sandbox Code Playgroud) 问题: 我在使用 GetX 和 AutoRoute 设置导航时遇到问题。
代码设置: 根据 GetX 文档,如果您想使用 GetX 导航,则必须将 MaterialApp() 替换为 GetMaterialApp()。您还设置了路线。
void main() {
runApp(
GetMaterialApp(
initialRoute: '/',
getPages: [
GetPage(name: '/', page: () => MyHomePage()),
GetPage(name: '/second', page: () => Second()),
GetPage(
name: '/third',
page: () => Third(),
transition: Transition.zoom
),
],
)
);
}
Run Code Online (Sandbox Code Playgroud)
AutoRoute示例使用MaterialApp.router()来设置routerDelegate和routeInformationParser。
final _appRouter = AppRouter()
...
Widget build(BuildContext context){
return MaterialApp.router(
routerDelegate: _appRouter.delegate(...initialConfig),
routeInformationParser: _appRouter.defaultRouteParser(),
),
}
Run Code Online (Sandbox Code Playgroud)
以下是我根据 Getx 和 AutoRoute 设置导航的方法:
void main() {
configureDependencies();
runApp(Portfolio());
}
class Portfolio …Run Code Online (Sandbox Code Playgroud) 我是 Flutter GetX 包的新手,在使用 flutter GetX 包时遇到问题。我有几个应用程序屏幕,其中一个屏幕用于列出数据库中的所有产品。
在我的产品控制器中,我从数据库中获取所有数据并使用列表视图显示,如下面给出的代码所示,并且工作正常。
问题:当我从另一个控制器插入新记录并返回产品列表控制器时,它不会显示新添加的数据。实际上这次onInit方法不会触发。
控制器代码
class ProductIndexCtrl extends GetxController {
var products = [].obs;
@override
void onInit() {
super.onInit();
getAll();
}
void getAll() {
Product.getAll().then((jsonList) {
products.value = Product.fromJsonList(jsonList);
});
}
}
class ProductCreateCtrl extends GetxController {
void saveData(Product product) {
...
...
//after successful insert
Get.toNamed('productIndex');
}
}
Run Code Online (Sandbox Code Playgroud)
产品索引屏幕
final ctrl = Get.put(ProductIndexCtrl());
GetX<ProductIndexCtrl>(builder: (controller) {
return _listview(controller.products);
}
Widget _listview(data) {
...
...
}
Run Code Online (Sandbox Code Playgroud) 我尝试检查 GetX 包。我一直在更新 String.obs
这是示例代码:
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class MyController extends GetxController {
var name = "JOHN".obs;
var age = 33.obs;
incrementAge() {
age++;
}
changeName(String s) {
name = RxString(s);
}
}
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
TextEditingController textEditingController …Run Code Online (Sandbox Code Playgroud) 使用 GetX (或任何其他方式)在 flutter 中发送带有参数的数据是一个好习惯吗?我的意思是它对性能和内存容量有好处吗?...就像这个例子:
Get.toNamed(AppPages.servicesDetails, arguments: [service]);
Run Code Online (Sandbox Code Playgroud)
当(服务)仅包含来自 API 的一种产品的数据时:例如(id、名称、信息、图像...等)。
并在服务详细信息页面中:
final s = Get.arguments[0];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child: Text(s.name),),
Run Code Online (Sandbox Code Playgroud) 我使用 GetX 来实现底部工作表的目的。我使用下面的代码来实现该功能。当我按 (i)-info 图标时,我希望弹出底部工作表,但我收到此错误。
处理手势时抛出以下 _CastError:空值检查运算符
这是代码:
GestureDetector(
onTap:(){
Get.bottomSheet(
Container(
child: Wrap(
children:<Widget>[
ListTile(
leading: Icon(Icons.wb_incandescent),
title: Text("Testing"),
onTap: () => {Get.changeTheme(ThemeData.light())},
),
ListTile(
leading: Icon(Icons.wb_incandescent),
title: Text("Testing"),
onTap: () => {Get.changeTheme(ThemeData.dark())},
),
]
),
),
);
},
child: Container(
width: 30.0,
height: 30.0,
decoration: BoxDecoration(
color: Color(0xFF1D265F),
borderRadius: BorderRadius.circular(80.0),
),
child: new LayoutBuilder(
builder: (context, constraint) {
return new Icon(
Icons.info_outline_rounded,
color: widget.cardContent.cardColor,
size: constraint.biggest.height,
);
},
),
),
),
Run Code Online (Sandbox Code Playgroud) dart android-studio flutter flutter-dependencies flutter-getx
一段时间以来,我注意到我的一些 Firebase 文档的字段被删除,即使我没有删除它们或在我的应用程序上编写任何逻辑来删除文档或文档本身的字段。这张图片显示了我的 firebase 项目中的一个文档,该文档的字段已自行删除。
firebase项目已连接到我的flutter应用程序,但我还没有编写任何删除功能。我只是偶尔用最新数据更新字段。请问谁知道发生了什么事?
编辑
这就是我更新用户集合文档的方式
Future<String?> submitUpdate(User user) async{
CollectionReference userCollection = firestore.collection('users');
String? uid = await secureStorage.read(key: 'uid');
try{
//updates user doc in users collection
await userCollection.doc(uid).update(user.toMap());
return "Success";
}catch(e){
return null;
}
Run Code Online (Sandbox Code Playgroud)
这就是我在用户集合中创建用户文档的方法。
Future<String?> saveUserCredentials(User user) async{
CollectionReference users = firestore.collection('users');
String? uid = await FlutterSecureStorage().read(key: "uid");
try{
//creates a user doc in the users collection
await users.doc(uid).set(
user.toMap()
);
return "Success";
}catch (e){
print(e);
return null;
}
Run Code Online (Sandbox Code Playgroud)
我有一个定义用户对象的用户模型。
firebase firebase-realtime-database flutter google-cloud-firestore flutter-getx
flutter ×10
flutter-getx ×10
dart ×3
android ×1
arguments ×1
dart-pub ×1
firebase ×1
get ×1
performance ×1
web ×1