我想在中心显示图像或文本,就像No Record Found所有详细信息都是从 API 获取的一样。在本机 Android 中,setEmptyView()对于这种情况,但不知道如何在 flutter 中做到这一点。不间断进度 对话框正在运行,但不显示文本。我在 JSON 响应中添加了代码
List<NewAddressModel> newAddress = List();
bool isLoading = false;
Scaffold(
body :isLoading
? Center(
child: CircularProgressIndicator(),
)
: Container(
color: Color.fromRGBO(234, 236, 238, 1),
child: getListView()
),
)
Run Code Online (Sandbox Code Playgroud)
Widget getListView(){
return newAddress.isNotEmpty ?
ListView.builder(itemCount: newAddress.length,
itemBuilder: (BuildContext context, int index) {
return addressViewCard(index);
}
)
: Center(child: Text("No Found"));
}
Run Code Online (Sandbox Code Playgroud)
Future<List>hitGetAddressApi() async {
setState(() {
isLoading = true;
});
final response = await http.post(api);
var …Run Code Online (Sandbox Code Playgroud) 我试图使依赖的多级下拉列表首先包含州列表,第二个包含城市列表,所有数据都是从 API 获取的。最初,我加载状态下拉列表,当我选择状态时,然后加载该状态的城市,如果我选择城市,则城市选择成功,但是当我更改状态值时会发生错误。如果在第一个下拉列表中进行更改,重新加载第二个下拉列表的正确方法是什么?
错误:应该只有一项具有 [DropdownButton] 的值:“城市”的实例。检测到零个或 2 个或更多 [DropdownMenuItem] 具有相同的值
Future _state;
Future _city;
@override
void initState() {
super.initState();
_state = _fetchStates();
}
Run Code Online (Sandbox Code Playgroud)
Future<List<StateModel>> _fetchStates() async {
final String stateApi = "https://dummyurl/state.php";
var response = await http.get(stateApi);
if (response.statusCode == 200) {
final items = json.decode(response.body).cast<Map<String, dynamic>>();
List<StateModel> listOfUsers = items.map<StateModel>((json) {
return StateModel.fromJson(json);
}).toList();
return listOfUsers;
} else {
throw Exception('Failed to load internet');
}
}
Run Code Online (Sandbox Code Playgroud)
Future<List<City>> _fetchCities(String id) async {
final String cityApi = "https://dummyurl/city.php?stateid=$id";
var response = …Run Code Online (Sandbox Code Playgroud) 我想在 flutter 的帮助下使用 url 下载文件Dio。
final imgUrl = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf";
var dio = Dio();
Run Code Online (Sandbox Code Playgroud)
RaisedButton.icon(
onPressed: (){
download2(dio, imgUrl, "./example/boo2.pdf");
},
icon: Icon(Icons.file_download,color: Colors.white,),
color: Colors.green,
textColor: Colors.white,
label: Text('Dowload Invoice')
)
Run Code Online (Sandbox Code Playgroud)
Future download2(Dio dio, String url, String savePath) async {
try {
Response response = await dio.get(
url,
onReceiveProgress: showDownloadProgress,
//Received data with List<int>
options: Options(
responseType: ResponseType.bytes,
followRedirects: false,
validateStatus: (status) { return status < 500; }
),
);
print(response.headers);
File file = File(savePath);
var raf = …Run Code Online (Sandbox Code Playgroud) 如何访问我的 JSON 对象?
获取Employee Title = null如何直接使用对象?
像Text('Employee Title = ${list[0].title}')这样直接使用模型对象获得正确的输出或任何其他方式?
什么是正确的方法?
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:flutter/cupertino.dart';
class EmployeeModel {
int userId;
int id;
String title;
String body;
EmployeeModel({this.userId, this.id, this.title, this.body});
EmployeeModel.fromJson(Map<String, dynamic> json) {
userId = json['userId'];
id = json['id'];
title = json['title'];
body = json['body'];
}
}
class EmployeePage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return EmployeePageState();
}
}
class EmployeePageState extends State<EmployeePage> …Run Code Online (Sandbox Code Playgroud)