所以假设我从不同的 URL 中获取不同的列表,所以 Future 函数看起来像这样
Future<List<City>> getCityDetails(Region selectedRegion) async {}
Future<List<Region>> getregionDetails() async {}
Run Code Online (Sandbox Code Playgroud)
因此小部件生成器将如下所示
FutureBuilder<List<Region>>(
future: getregionDetails(),
builder: (context, snapshot) {}
Run Code Online (Sandbox Code Playgroud)
有没有办法或解决这个问题?我试图找到一个如何实现这个的答案还是有另一种方法?
我的主页上有一个列表视图,如果单击它将移动到新页面,第一个页面的主题应为蓝色,下一个页面的主题数据应为红色。就像 Facebook Messenger 中聊天自定义的工作原理一样。
假设我已经构建了一个如下所示的条子列表。
return new Container(
child: new CustomScrollView(
scrollDirection: Axis.vertical,
shrinkWrap: false,
slivers: <Widget>[
new SliverPadding(
padding: const EdgeInsets.symmetric(vertical: 2.0),
sliver: new SliverList(
delegate: new SliverChildBuilderDelegate(
(BuildContext context, int index) {
ModelClass class= _List[index];
return new Dismissible(
key: new ObjectKey(_List[index]),
child: ModelCard(class),
onDismissed: (DismissDirection direction) {
setState(() {
_List.removeAt(index);
direction == DismissDirection.endToStart;
});
},
background: new Container(
color: const Color.fromRGBO(183, 28, 28, 0.8),
child: new Center(
child: new Text(
"Item Removed",
style: new TextStyle(color: Colors.white),
),
)),
);
// return new …Run Code Online (Sandbox Code Playgroud) 显示从具有搜索功能的第三方 API 获取的 A-List 错误仅在我运行应用程序时显示,它说 _InternalLinkedHashMap<String, dynamic>' 不是'Iterable 类型的子类型
请Welp *** Edit A new Error Showed after play the code this error shows type 'String' is not a subtype of type Map-dynamic, dynamic-
Future<Null> getStoreDetails() async {
var basicAuth = 'Basic ' +
base64Encode(utf8.encode('api_token_key'));
var result;
var response = await http.get(url, headers: {'authorization': basicAuth});
if (response.statusCode == 200) {
var responseJson = json.decode(response.body);
setState(() {
/Where the error is
for (Map storedetails in responseJson) {
_searchResult.add(StoreDetails.fromJson(storedetails));
}
});
} else …Run Code Online (Sandbox Code Playgroud) 数据将是这样的
[{ID: 1, Code: 01, Description: REGION I (ILOCOS REGION), PSGCCode: 010000000}, {ID: 2, Code: 02, Description: REGION II (CAGAYAN VALLEY), PSGCCode: 020000000},
Run Code Online (Sandbox Code Playgroud)
我只想使用描述作为 DropDownButton 中的文本
编辑****
类看起来像这样吗?
class Region {
final int regionid;
final String regionDescription;
Region ({
this.regionid,
this.regionDescription
});
factory Region.fromJson(Map<String, dynamic> json) {
return new Region(
regionid: json['id'],
regionDescription: json['description']
);
}
}
Run Code Online (Sandbox Code Playgroud)
编辑**尝试使用或执行上面的类并将其分配给列表
List<Region> _region = [];
Run Code Online (Sandbox Code Playgroud)
并将其用于我的 DropDownItems
child: new DropdownButtonHideUnderline(
child: new DropdownButton<String>(
hint: new Text("Select Region"),
value: selectedRegion,
isDense: true,
onChanged: (String …Run Code Online (Sandbox Code Playgroud)