Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 282 Vote(s) - 3.64 Average
  • 1
  • 2
  • 3
  • 4
  • 5
type 'int' is not a subtype of type 'double'

#1
I have this issue on my flutter application. It seems failed to load an API request, but when i try on browser it return okay "http://vplay.id/api/series/popular".

**Debug**

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');
}
}
**Helpers/parse.dart**

static double checkDouble(dynamic value) {
if (value is String) {
return double.parse(value);
} else {
return value;
}
}
}
This is my first time with flutter, and this is interesting since it only me face this issue (this is an app i get from codecanyon marketplace) with fresh installation.
Reply

#2
```
static double checkDouble(dynamic value) {
if (value is String) {
return double.parse(value);
} else {
return value;
}
}
}
```

The problem seems from the last ```return value```. You may need ```return value+.0```.
Reply

#3
In my case, this error was because I had to represent my number as a double value, not an int value.

Example:

Change 0 to 0.0.

double rating = rating??0;

to:



double rating = rating??0.0;



Reply

#4
An idea would be to use `num` instead of `int` or `double` in this case.
Reply

#5
***As Gustavo Rodrigues mentioned below, do not use this as a standard solution, this is only a workaround.***

I had a similar issue getting weather data.

I solved by declaring the variable as a `dynamic` instead of `int` type.
Reply

#6
```dart
double? checkDouble(dynamic value) {
if(value is double) return value;
if(value is int) return value.toDouble();
if(value is String) return double.tryParse(value);
return null;
}
int? checkInt(dynamic value) {
if(value is int) return value;
if(value is double) return value.toInt();
if(value is String) return int.tryParse(value);
return null;
}
```
Reply

#7
You only need to add .toDouble() function to last returned value.

static double checkDouble(dynamic value) {
if (value is String) {
return double.parse(value);
} else {
return value.toDouble();
}
}
}
Reply

#8
var coordinatesFromJson = json["coordinates"] as List<dynamic>;
List<double> coordinatesList = [];
(coordinatesFromJson as List<dynamic>).forEach((element) {
if (element is int)
coordinatesList.add((element).toDouble());
else
coordinatesList.add(element);
});
Reply

#9
Will this help you?

double.parse(rating.toString());


Reply

#10
You can initialize you variables with double.
```
class MyBrick extends StatelessWidget {
double x;
double y;
MyBrick({required this.x, required this.y});

@override
Widget build(BuildContext context) {
return Container(
alignment: Alignment(x, y),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Container(
color: Colors.white,
height: 20,
width: MediaQuery.of(context).size.width / 5,
),
),
);
}
}
```
This worked for me...
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through