android - “int”类型不是“double”类型的子类型
问题描述
我的颤振应用程序有这个问题。似乎无法加载 API 请求,但是当我在浏览器上尝试时,它返回正常“ http://vplay.id/api/series/popular ”。
调试
exception = {_Exception} Exception: Failed to load
message = "Failed to load"
this = {SeriesProvider}
_url = "http://vplay.id/api/"
_loading = false
_currentPage = 1
_pages = 1
_series = {_GrowableList} size = 0
_seriesStream = {_AsyncStreamController}
endpoint = "series/popular"
e = {_TypeError} type 'int' is not a subtype of type 'double'
_stackTrace = {_StackTrace}
_failedAssertion = "is assignable"
_url = "package:streamapp/src//helpers/parse.dart"
_line = 31
_column = 7
message = "type 'int' is not a subtype of type 'double'"
Series_provider.dart
import 'dart:async';
import 'dart:convert';
import 'package:http/http.dart' as http;
import '../helpers/api.dart';
import '../models/serie_model.dart';
export '../models/serie_model.dart';
class SeriesProvider {
String _url = Api.url;
bool _loading = false;
int _currentPage = 1;
int _pages = 1;
List<Serie> _series = List();
final _seriesStream = StreamController<List<Serie>>();
Function(List<Serie>) get seriesSink => _seriesStream.sink.add;
Stream<List<Serie>> get seriesStream => _seriesStream.stream;
void dispose() {
_seriesStream?.close();
}
Future<List<Serie>> _process(String endpoint) async {
try {
final resp = await http.get(_url + endpoint);
if (resp.statusCode != 200) {
throw Exception('Failed to load');
}
final data = json.decode(resp.body);
final series = Series.fromJsonList(data);
return series.items;
} catch (e) {
throw Exception('Failed to load');
}
}
助手/parse.dart
static double checkDouble(dynamic value) {
if (value is String) {
return double.parse(value);
} else {
return value;
}
}
}
这是我第一次使用颤振,这很有趣,因为只有我在全新安装时遇到这个问题(这是我从 codecanyon 市场获得的应用程序)。
解决方案
一个想法是在这种情况下使用num
代替int
或。double
推荐阅读
- java - 为什么 Java 8 接口静态方法不能覆盖 Object 类方法
- sql - 如果下面出现 raiseerror,如何不返回 SQL Server 存储过程中的 select 语句?
- ios - .utf8 编码如何与 json 数据编码完全配合?
- php - 我怎样才能将这个表重新排列到另一个远离 laravel 雄辩的关系
- android - 运行appium服务器时adb未检测到设备
- java - Saxon-He 9.8 s9Api Transform 函数抛出:net.sf.saxon.trans.XPathException: Failed to read input file exception
- javascript - Angular 5 本地存储单元测试
- html - 如何添加自定义属性和属性
路由器链接? - .net - 如何使用 dotnet CLI(命令行)将项目(.csproj)添加到解决方案文件夹下的解决方案(.sln)?
- java - 性能:内部接口与单独的接口类