Video RxList to List flutter Mới nhất

Kinh Nghiệm về RxList to List flutter 2022

Bạn đang tìm kiếm từ khóa RxList to List flutter được Update vào lúc : 2022-01-04 05:07:06 . Với phương châm chia sẻ Thủ Thuật về trong nội dung bài viết một cách Chi Tiết Mới Nhất. Nếu sau khi Read Post vẫn ko hiểu thì hoàn toàn có thể lại Comments ở cuối bài để Admin lý giải và hướng dẫn lại nha.

GETX: how to create a RxList from GetStorage.read (error: List is not a subtype of type RxList? in type cast)(GETX:如何从GetStorage.read创建RxList(错误:List不是类型转换中RxList?类型的子类型))-flutter

GETX: how to create a RxList from GetStorage.read (error: List is not a subtype of type RxList? in type cast)(GETX:如何从GetStorage.read创建RxList(错误:List不是类型转换中RxList?类型的子类型))

I have a 2 List like this:

Nội dung chính

var listStringRaw = [‘a’, ‘b’, ‘c’];
var listIntRaw = [1, 2, 3];

then write them to GetStorage:

await GetStorage().write(‘listString’, listStringRaw);
await GetStorage().write(‘listInt’, listIntRaw);

So how can I assign them to RxList in GetxController?

RxList<String> get listString => GetStorage().read(‘listString’) ?? [];
RxList<int> get listInt => GetStorage().read(‘listInt’) ?? [];

the error appears when I try:
Unhandled Exception: type List is not a subtype of type RxList? in type cast

pls help me, this is the full code:

import ‘package:get/get.dart’;
import ‘package:get_storage/get_storage.dart’;

void main() async
await GetStorage.init();
var listStringRaw = [‘a’, ‘b’, ‘c’];
var listIntRaw = [1, 2, 3];

await GetStorage().write(‘listString’, listStringRaw);
await GetStorage().write(‘listInt’, listIntRaw);

Get.put(Controller());

class Controller extends GetxController

RxList<String> get listString => GetStorage().read(‘listString’) ?? [];
RxList<int> get listInt => GetStorage().read(‘listInt’) ?? [];

@override
void onInit()
print(listString);
print(listInt);
super.onInit();

Solution:

If you read get packages doc, it says that you need to use the .obs method to convert anything to an Rx object.

RxList<String> get listString => (GetStorage().read<List<String>?>(‘listString’) ?? []).obs;
RxList<int> get listInt => (GetStorage().read<List<int>?>(‘listInt’) ?? []).obs;

Also, the call to read() of GetStorage() has to be declared with the return type so that the compiler knows the object you will be working with.

我有这样一个2列表:

var listStringRaw = [‘a’, ‘b’, ‘c’];
var listIntRaw = [1, 2, 3];

然后将它们写入GetStorage:

await GetStorage().write(‘listString’, listStringRaw);
await GetStorage().write(‘listInt’, listIntRaw);

那么如何将它们分配给GetxController中的RxList呢?

RxList<String> get listString => GetStorage().read(‘listString’) ?? [];
RxList<int> get listInt => GetStorage().read(‘listInt’) ?? [];

尝试时出现错误:
未处理的异常:类型List不是类型转换中类型RxList?的子类型

请帮助我,这是完整的代码:

import ‘package:get/get.dart’;
import ‘package:get_storage/get_storage.dart’;

void main() async
await GetStorage.init();
var listStringRaw = [‘a’, ‘b’, ‘c’];
var listIntRaw = [1, 2, 3];

await GetStorage().write(‘listString’, listStringRaw);
await GetStorage().write(‘listInt’, listIntRaw);

Get.put(Controller());

class Controller extends GetxController

RxList<String> get listString => GetStorage().read(‘listString’) ?? [];
RxList<int> get listInt => GetStorage().read(‘listInt’) ?? [];

@override
void onInit()
print(listString);
print(listInt);
super.onInit();

解决方法:

如果您阅读了get包的doc,它会说您需要使用.obs方法将任何内容转换为Rx对象。

RxList<String> get listString => (GetStorage().read<List<String>?>(‘listString’) ?? []).obs;
RxList<int> get listInt => (GetStorage().read<List<int>?>(‘listInt’) ?? []).obs;

另外,对GetStorage()的read()的调用必须用返回类型声明,以便编译器知道您将使用的对象。

文章导航

前一页 上一篇: Filtering twice with multiple variables and counting rows(使用多个变量过滤两次并计算行数)-r后一页 下一篇: 算法基础之快速排序(Algorithm based quick sort)-其他

Reply
6
0
Chia sẻ

Video RxList to List flutter ?

Bạn vừa đọc tài liệu Với Một số hướng dẫn một cách rõ ràng hơn về Video RxList to List flutter tiên tiến và phát triển nhất

Share Link Tải RxList to List flutter miễn phí

Hero đang tìm một số trong những Chia SẻLink Tải RxList to List flutter Free.

Thảo Luận vướng mắc về RxList to List flutter

Nếu You sau khi đọc nội dung bài viết RxList to List flutter , bạn vẫn chưa hiểu thì hoàn toàn có thể lại Comment ở cuối bài để Ad lý giải và hướng dẫn lại nha
#RxList #List #flutter

Exit mobile version