Unable to retrieve fetch ID data from API. How to fix? - flutter

I want to fetch details of a product by retrieving its ID and by accessing its Id to load the details needed but I keep getting an error that I dont quite understand?
here is my provider data:
class AddCar {
int id;
String name;
String city;
String country;
String currencyT;
double price;
String date;
int sponsNum;
String category;
String company;
String model;
String year;
String engine;
double distanceCovered;
String transmission;
String oilT;
String outColor;
String inColor;
String description;
File image;
PlaceLocation location;
bool isFavorite;
AddCar({
this.id,
this.name,
this.city,
this.country,
this.currencyT,
this.price,
this.date,
this.sponsNum,
this.category,
this.company,
this.model,
this.year,
this.engine,
this.distanceCovered,
this.transmission,
this.oilT,
this.outColor,
this.inColor,
this.description,
this.image,
this.location,
this.isFavorite = false,
});
}
class PlaceLocation {
final double latitude;
final double longitude;
final String address;
const PlaceLocation({
this.address,
this.latitude,
this.longitude,
});
}
Here is how im fetching the data (i have a link to a custome ID that im clicking on to lead to that product):
Future<void> fetchAndSetCarDetails() async {
const url = 'customLink/Detail?Id=204';
final response = await http.get(url);
final extractedData = json.decode(response.body) as Map<String, dynamic>;
List<AddCar> loadedCars = [];
extractedData.forEach((carId, carData) {
loadedCars.add(AddCar(
id: int.parse(carId),
name: carData['adTitle'],
sponsNum: carData['adNumber'],
price: carData['adPrice'],
date: carData['adDate'],
model: carData['brandModel'],
year: carData['modelYear'],
distanceCovered: carData['kilometer'],
transmission: carData['gearType'],
oilT: carData['fuelType'],
location: carData['adLocation'][PlaceLocation(
address: carData['adAddress'],
latitude: carData['lath'],
longitude: carData['lang'],
)],
description: carData['adDetails'],
country: carData['country'],
city: carData['cityName'],
category: carData['category'],
company: carData['brand'],
engine: carData['cylinder'],
outColor: carData['exteriorColor'],
inColor: carData['interiorColor'],
));
});
_cars = loadedCars;
print(response.body);
notifyListeners();
}
Here is the print data I get:
I/flutter (13626): {"id":204,"adTitle":null,"adDate":"2019-11-07T11:52:40.0156875","adPrice":25.0,"adNumber":195,"adAddress":"AdAddressssssss","adLocation":{"lath":"40.959028921030104","lang":" 30.992774628906318"},"adDetails":null,"country":227,"cityName":"Stockholm","category":"car child 1","categoryId":7,"brand":"mercedes","brandId":1,"brandModelId":6,"brandModel":"M300","cylinder":"6C","kilometer":300.0,"modelYear":"2010","fuelType":"benz","gearType":"automatic","exteriorColor":"red","interiorColor":"yellow","carType":1,"image":[],"isFavorite":false,
Here is the error I get when I click on the product to access its details:
E/flutter (13626): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: FormatException: Invalid radix-10 number (at character 1)
E/flutter (13626): id
E/flutter (13626): ^
E/flutter (13626):
E/flutter (13626): #0 int._throwFormatException (dart:core-patch/integers_patch.dart:131:5)
E/flutter (13626): #1 int._parseRadix (dart:core-patch/integers_patch.dart:142:16)
E/flutter (13626): #2 int._parse (dart:core-patch/integers_patch.dart:100:12)
E/flutter (13626): #3 int.parse (dart:core-patch/integers_patch.dart:63:12)
E/flutter (13626): #4 Cars.fetchAndSetCarDetails.<anonymous closure>
package:flutter_app/providers/car_provider.dart:88
E/flutter (13626): #5 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
E/flutter (13626): #6 Cars.fetchAndSetCarDetails
package:flutter_app/providers/car_provider.dart:86
E/flutter (13626): <asynchronous suspension>
E/flutter (13626): #7 _MyCarDetailsState.initState.<anonymous closure>
package:flutter_app/details/car_details.dart:23
E/flutter (13626): #8 _rootRunUnary (dart:async/zone.dart:1132:38)
E/flutter (13626): #9 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (13626): #10 _FutureListener.handleValue (dart:async/future_impl.dart:137:18)
E/flutter (13626): #11 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:678:45)
E/flutter (13626): #12 Future._propagateToListeners (dart:async/future_impl.dart:707:32)
E/flutter (13626): #13 Future._complete (dart:async/future_impl.dart:512:7)
E/flutter (13626): #14 new Future.delayed.<anonymous closure> (dart:async/future.dart:313:16)
E/flutter (13626): #15 _rootRun (dart:async/zone.dart:1120:38)
E/flutter (13626): #16 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (13626): #17 _CustomZone.runGuarded (dart:async/zone.dart:923:7)
E/flutter (13626): #18 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:963:23)
E/flutter (13626): #19 _rootRun (dart:async/zone.dart:1124:13)
E/flutter (13626): #20 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (13626): #21 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:947:23)
E/flutter (13626): #22 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:21:15)
E/flutter (13626): #23 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:382:19)
E/flutter (13626): #24 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:416:5)
E/flutter (13626): #25 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:172:12)
E/flutter (13626):

You have several problems.
1 - your forEach closure looks like you are expecting the JSON to include a list of cars that you are going to add to loadedCars but it does not - there's just one car. That's why extractedData is a Map<String, dynamic> not a List<Map<String, dynamic>>.
2 - that means that the forEach closures is iterating over the members of the map so gets called once with carId='id' and carData=204 and then again with carId='adPrice' and carData=25.0 etc. This is clearly not what you're expecting! The exception happens when you try to parse 'id' into an int.
Given that there's only one car in your current json you can dispense with the loop. You should extract that one car like:
final response = await http.get(url);
final extractedData = json.decode(response.body) as Map<String, dynamic>;
var theOneCar = AddCar(
id: extractedData['id'], // no need for parse either - id is already an int
name: extractedData['adTitle'],
// etc
// etc
print (theOneCar);

Related

Flutter mapping a List<int> to a List<String> throws the error 'String' is not a subtype of type 'int'

Unhandled Exception: type 'String' is not a subtype of type 'int' in
type cast
else if (value is List<int>) {
prefs.setStringList(
"itemsToLoanCats", [...value.map((e) => e.toString())]);
}
type of 'value' = List<int>
I don't see why this doesn't work, I'm using .toString()
STACK TRACE
I/flutter (16996): Person This is claiming to be itemsToLoanCats: [0]
I/flutter (16996): saveToPrefs converting GeoPoint...
E/flutter (16996): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: type 'String' is not a subtype of type 'int' in type cast
E/flutter (16996): #0 _CastListBase.[] (dart:_internal/cast.dart:99:46)
E/flutter (16996): #1 ListMixin.elementAt (dart:collection/list.dart:78:33)
E/flutter (16996): #2 ListIterator.moveNext (dart:_internal/iterable.dart:342:26)
E/flutter (16996): #3 StringBuffer.writeAll (dart:core-patch/string_buffer_patch.dart:96:19)
E/flutter (16996): #4 IterableBase.iterableToFullString (dart:collection/iterable.dart:268:14)
E/flutter (16996): #5 ListMixin.toString (dart:collection/list.dart:588:37)
E/flutter (16996): #6 Person.saveToPrefs.<anonymous closure> (package:meloan/model/person.dart:635:72)
E/flutter (16996): #7 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:617:13)
E/flutter (16996): #8 Person.saveToPrefs (package:meloan/model/person.dart:593:20)
E/flutter (16996): #9 _PersonalDetailsScreenState._buildBody.<anonymous closure> (package:meloan/personal/edit_personal_details.dart:1231:30)
E/flutter (16996): #10 _InkResponseState.handleTap (package:flutter/src/material/ink_well.dart:1072:21)
E/flutter (16996): #11 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:253:24)
E/flutter (16996): #12 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:627:11)
E/flutter (16996): #13 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:306:5)
E/flutter (16996): #14 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:276:7)
E/flutter (16996): #15 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:163:27)
E/flutter (16996): #16 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:464:20)
E/flutter (16996): #17 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:440:22)
E/flutter (16996): #18 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:337:11)
E/flutter (16996): #19 GestureBinding._handlePointerEventImmediately (package:flutter/src/gestures/binding.dart:395:7)
E/flutter (16996): #20 GestureBinding.handlePointerEvent (package:flutter/src/gestures/binding.dart:357:5)
E/flutter (16996): #21 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:314:7)
E/flutter (16996): #22 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:295:7)
E/flutter (16996): #23 _invoke1 (dart:ui/hooks.dart:167:13)
E/flutter (16996): #24 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:341:7)
E/flutter (16996): #25 _dispatchPointerDataPacket (dart:ui/hooks.dart:94:31)
ADDITION:
List<String> encodedList = [];
for(int intValue in (value as List<int>)) {
print(LOG + "intValue: $intValue");
encodedList.add(int.parse(intValue).toString());
}
Doesn't work either, same Exception thrown.
Longer code snippet as requested:
saveToPrefs(SharedPreferences prefs) {
(this.toMap()).forEach((key, value) {
//print("saveToPrefs entered with key: $key\nvalue: $value");
if (value != null) {
if (key == "dbProfilePicPath") {
print("PERSON " + "should be saving dbProfilePicPath");
}
if (value is String) {
prefs.setString(key, value);
} else if (key == "position") {
print("saveToPrefs converting GeoPoint...");
double latitude = value['geopoint'].latitude;
double longitude = value['geopoint'].longitude;
prefs.setDouble("latitude", latitude);
prefs.setDouble("longitude", longitude);
} else if (value is List<String>)
prefs.setStringList(key, value);
else if (value is double)
prefs.setDouble(key, value);
else if (value is int)
prefs.setInt(key, value);
else if (value is bool)
prefs.setBool(key, value);
else if (value is Map<String, String>) {
// needs to be stored as a list
List<String>? list = [];
value.forEach((key, value) {
list.add("$key:$value");
});
prefs.setStringList(key, list);
} else if (value is Map<String, bool>) {
// e.g. .Charateristics needs to be stored as a list
List<String>? list = [];
value.forEach((key, value) {
list.add("$key:${value.toString()}");
});
prefs.setStringList(key, list);
} else if (value is Map<String, dynamic>) {
// loanItemFinancials / loanItemDetails?
//prefs.setString('loanItemDetails', json.encode(value));
} else if (value is List<int>) {
// itemsToLoanCats, each loaning category encoded to int
value = value.cast<int>();
print(LOG + 'This is claiming to be itemsToLoanCats: ${value.toString()}');
prefs.setStringList("itemsToLoanCats", value.map((el) => el.toString()).toList());
//prefs.setStringList("itemsToLoanCats", [...value.map((e) => e.toString())]);
}
Try encoding the list into json first.
encodedList = json.encode(value);
debugPrint(encodedList.toString());
prefs.setString('itemsToLoanCats', encodedList);
OK solved. So I discovered the type of value wasn't compatible with my map to String code.
Turns out value was assigned using .cast<int>(), this doesn't produce a proper List, it's a Map? CastList<String, int>.
Anyway, I had to delve earlier in my code and reconfigure how this variable is assigned when extracted from prefs.
(prefs.getStringList('itemsToLoanCats') ?? []).map(int.parse).toList();
Solved it.
Crikey! Thanks for the attention and encouragement all. If you want to post an answer explaining why .cast<int> produces a map and can't be treated like a List<int> then I'll give the answer credit.
Extremely strange it reports as List<int> but refuses to behave as such 🤔

Null Check operator used on a null value on flutter with Sqflite

I'm studying flutter with Sqflite and trying to make a small app, but I'm getting this error when I run the code, I've looked literaly everywhere to findout what it could be.
Here the code code who use the Sqflite package:
Future<Database> getDatabase() async {
final String path = join(await getDatabasesPath(), 'bytebank.db');
return openDatabase(path, onCreate: (db, version) {
db.execute('CREATE TABLE contacts'
'(id INTEGER PRIMARY KEY, '
'name TEXT, '
'account_number INTEGER)');
}, version: 1);
}
Future<int> save(Contact contact) async {
final Database db = await getDatabase();
final Map<String, dynamic> contactMap = Map();
contactMap['name'] = contact.name;
contactMap['account_number'] = contact.account;
contactMap['id'] = contact.id;
return db.insert('contacts', contactMap);
}
Future<List<Contact>> findAll() async {
final Database db = await getDatabase();
final List<Map<String, dynamic>> result = await db.query('contacts');
final List<Contact> contacts = [];
for (Map<String, dynamic> row in result) {
final Contact contact = Contact(
row['id'],
row['name'],
row['account_number'],
);
contacts.add(contact);
}
return contacts;
}
And here is the only one place where I use This functions:
void main() {
save(Contact('William', 2, 13456)).then((id) {
findAll().then((contacts) => print(contacts));
});
runApp(ByteBankApp());
}
Model Class:
class Contact {
final String name;
final int account;
final int id;
Contact( this.id,
this.name,
this.account,
);
#override
String toString() {
return 'Contact{name: $name, account: $account}';
}
}
Error Trace back:
Launching lib\main.dart on sdk gphone x86 arm in debug mode...
Running Gradle task 'assembleDebug'...
√ Built build\app\outputs\flutter-apk\app-debug.apk.
Installing build\app\outputs\flutter-apk\app.apk...
Debug service listening on ws://127.0.0.1:52296/07rtnvW9tlQ=/ws
Syncing files to device sdk gphone x86 arm...
E/flutter (28649): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Null check operator used on a null value
E/flutter (28649): #0 MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:142:86)
E/flutter (28649): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:148:36)
E/flutter (28649): #2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:331:12)
E/flutter (28649): #3 invokeMethod (package:sqflite/src/sqflite_impl.dart:17:13)
E/flutter (28649): #4 SqfliteDatabaseFactoryImpl.invokeMethod (package:sqflite/src/factory_impl.dart:82:7)
E/flutter (28649): #5 SqfliteDatabaseFactoryMixin.safeInvokeMethod.<anonymous closure> (package:sqflite_common/src/factory_mixin.dart:41:38)
E/flutter (28649): #6 wrapDatabaseException (package:sqflite/src/exception_impl.dart:7:32)
E/flutter (28649): #7 SqfliteDatabaseFactoryImpl.wrapDatabaseException (package:sqflite/src/factory_impl.dart:78:7)
E/flutter (28649): #8 SqfliteDatabaseFactoryMixin.safeInvokeMethod (package:sqflite_common/src/factory_mixin.dart:41:7)
E/flutter (28649): #9 SqfliteDatabaseFactoryMixin.getDatabasesPath (package:sqflite_common/src/factory_mixin.dart:153:26)
E/flutter (28649): #10 getDatabasesPath (package:sqflite/sqflite.dart:161:54)
E/flutter (28649): #11 getDatabase (package:bytebank/database/app_database.dart:6:34)
E/flutter (28649): #12 save (package:bytebank/database/app_database.dart:16:29)
E/flutter (28649): #13 main (package:bytebank/main.dart:7:3)
E/flutter (28649): #14 _runMainZoned.<anonymous closure>.<anonymous closure> (dart:ui/hooks.dart:142:25)
E/flutter (28649): #15 _rootRun (dart:async/zone.dart:1354:13)
E/flutter (28649): #16 _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (28649): #17 _runZoned (dart:async/zone.dart:1789:10)
E/flutter (28649): #18 runZonedGuarded (dart:async/zone.dart:1777:12)
E/flutter (28649): #19 _runMainZoned.<anonymous closure> (dart:ui/hooks.dart:138:5)
E/flutter (28649): #20 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:283:19)
E/flutter (28649): #21 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
E/flutter (28649):
I am not sure if will help, but I was running into a similar issue when initializing a database in an async "main" method. Adding the following:
WidgetsFlutterBinding.ensureInitialized();
inside the method before the code initializing the database solved the problem.

Unhandled Exception: NoSuchMethodError: The getter 'length' was called on null. Shared Preference

While fetching the data for the first time from shared preference, I am getting this error: Unhandled Exception: NoSuchMethodError: The getter 'length' was called on null. But after the hot restart, I am getting the data as usual.
Retrieving data from Dashboard Screen
loadSharedPrefs() async {
var decodedData = await sharedPref.read("details");
signInItem = SignInItem.fromJson(decodedData);
setState(() {});
}
Saving data in SignIn screen
await FirebaseAuth.instance
.signInWithCredential(_phoneAuthCredential)
.then((AuthResult authRes) {
Navigator.pop(context);
Flushbar(
message: "Verified!!",
duration: Duration(seconds: 2),
)..show(context);
sharedPref.save("details", signInItem);
Navigator.popAndPushNamed(context, DashboardScreen.id);
});
Model Class
class SignInItem {
String phoneNumber;
String schoolCode;
String schoolReference;
Map<String, dynamic> teacherData;
String error;
SignInItem.fromJson(Map<String, dynamic> json)
: phoneNumber = json['phoneNumber'],
schoolCode = json['schoolCode'],
schoolReference = json['schoolReference'],
teacherData = json['teacherData'],
error = json['error'];
Map<String, dynamic> toJson() => {
'phoneNumber': phoneNumber,
'schoolCode': schoolCode,
'schoolReference': schoolReference,
'teacherData': teacherData,
'error': error,
};
SignInItem(
{this.phoneNumber,
this.schoolCode,
this.schoolReference,
this.teacherData,
this.error});
}
Shared preference helper class
class SharedPref {
read(String key) async {
final prefs = await SharedPreferences.getInstance();
return json.decode(prefs.getString(key));
}
save(String key, SignInItem signInItem) async {
final prefs = await SharedPreferences.getInstance();
prefs.setString(key, json.encode(signInItem.toJson()));
}
}
Detail Stacktrace
[ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: The getter 'length' was called on null.
E/flutter (19241): Receiver: null
E/flutter (19241): Tried calling: length
E/flutter (19241): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (19241): #1 _parseJson (dart:convert-patch/convert_patch.dart:39:28)
E/flutter (19241): #2 JsonDecoder.convert (dart:convert/json.dart:505:36)
E/flutter (19241): #3 JsonCodec.decode (dart:convert/json.dart:156:41)
E/flutter (19241): #4 SharedPref.read (package:teacher_app/constants.dart:156:17)
E/flutter (19241): <asynchronous suspension>
E/flutter (19241): #5 _DashboardScreenState.loadSharedPrefs (package:teacher_app/screens/dashboard_screen.dart:33:40)
E/flutter (19241): #6 _DashboardScreenState.initState (package:teacher_app/screens/dashboard_screen.dart:49:5)
E/flutter (19241): #7 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4684:58)
E/flutter (19241): #8 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
E/flutter (19241): #9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter (19241): #10 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter (19241): #11 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5874:14)
E/flutter (19241): #12 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter (19241): #13 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter (19241): #14 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
E/flutter (19241): #15 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
E/flutter (19241): #16 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
E/flutter (19241): #17 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
E/flutter (19241): #18 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter (19241): #19 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter (19241): #20 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5874:14)
E/flutter (19241): #21 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter (19241): #22 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter (19241): #23 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5874:14)
E/flutter (19241): #24 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter (19241): #25 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter (19241): #26 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
E/flutter (19241): #27 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4719:11)
E/flutter (19241): #28 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
E/flutter (19241): #29 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
E/flutter (19241): #30 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4710:11)
E/flutter (19241): #31 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
E/flutter (19241): #32 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter (19241): #33 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter (19241): #34 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5874:14)
E/flutter (19241): #35 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter (19241): #36 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter (19241): #37 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5874:14)
E/flutter (19241): #38 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter (19241): #39 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter (19241): #40 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
E/flutter (19241): #41 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4719:11)
E/flutter (19241): #42 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
E/flutter (19241): #43 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
E/flutter (19241): #44 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4710:11)
E/flutter (19241): #45 ComponentElement.mount (package:flutter/src/widgets/framework.dart
Shared Preference takes time to save the details and I was fetching the data before saving it. So that's why I was getting null.
I solved it by delaying to navigate to Dashboard screen by this:
await FirebaseAuth.instance
.signInWithCredential(_phoneAuthCredential)
.then((AuthResult authRes) {
sharedPref.save("details", signInItem);
Timer(Duration(seconds: 2), () {
Navigator.pop(context);
Navigator.popAndPushNamed(context, DashboardScreen.id);
});
});
But thanks #TheSohan for letting me know where I was getting null.
In SharedPref class read method; use a null check before decoding the data.
Ex:
class SharedPref {
read(String key) async {
final prefs = await SharedPreferences.getInstance();
string data = prefs.getString(key)
if(data){
return json.decode(prefs.getString(key));
}
return data
}
similarly, add null check in loadSharedPrefs method.
loadSharedPrefs() async {
var decodedData = await sharedPref.read("details");
if(decodedData){
signInItem = SignInItem.fromJson(decodedData);
}
setState(() {});
}

SQFLite (Flutter) Insert fails for Map containing Maps

Can someone confirm if SQFLite supports maps containing maps? I did run across the following post on this site and possibly this is the answer?
Flutter sqflite insert List<String>
In my situation, I have a two model classes I am working with.
House
Dog
House includes a field called pets which is a List
I have a constructor and factory method in each of these classes which takes care of converting to/from map/object as needed for sending to and retrieving information from SQFLite.
Model classes
Dog
class Dog {
final int id;
final String breed;
final String name;
final int age;
Dog({this.id, this.breed, this.name, this.age});
// Used when inserting a row into the db, including the id field
Map<String, dynamic> toMap() {
final map = Map<String, dynamic>();
map['id'] = id;
map['breed'] = breed;
map['name'] = name;
map['age'] = age;
return map;
}
// Used when returning a row from the DB and converting into an object
factory Dog.fromMap(Map<String, dynamic> data) => Dog(
id: data['id'],
breed: data['breed'],
name: data['name'],
age: data['age']
);
}
House
import 'dog.dart';
class House{
final int id;
final String name;
final String color;
final List<Dog> pets;
House({this.id, this.name, this.color, this.pets});
// Will be used when inserting a row into the database
Map<String, dynamic> toMap() {
final map = Map<String, dynamic>();
map['id'] = id;
map['name'] = name;
map['color'] = color;
if (this.pets != null) {
map['pets'] = this.pets.map((pet) => pet.toMap()).toList();
}
return map;
}
// Used when returning a row from the DB and converting into an object
factory House.fromMap(Map<String, dynamic> data) {
return House(
id: data['id'],
name: data['name'],
color: data['color'],
pets: data['pets'] != null
? (data['pets'] as List).map((pet) => Dog.fromMap(pet)).toList()
: null,
);
}
}
Method for inserting a new house
Future<int> addNewHome(House house) async {
// Attempt to add the house to the DB
var client = await database.db;
int result = await client.insert(HomesSchema.tblHomes, house.toMap(), conflictAlgorithm: ConflictAlgorithm.replace);
_homes.add(house);
return result;
}
When I attempt to perform the insert, I get the following error.
E/flutter ( 586): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: DatabaseException(java.util.HashMap cannot be cast to java.lang.Integer) sql 'INSERT OR REPLACE INTO homes (id, name, color, pets) VALUES (?, ?, ?, ?)' args [1, Smith, Green, [{name: Mackie, id: 1, breed: Rottweiler, age: 8}, {name: Tanner, id: 2, breed: Mastiff, age: 8}]]}
E/flutter ( 586): #0 wrapDatabaseException (package:sqflite/src/exception_impl.dart:12:7)
E/flutter ( 586): <asynchronous suspension>
E/flutter ( 586): #1 SqfliteDatabaseFactoryImpl.wrapDatabaseException (package:sqflite/src/factory_impl.dart:25:7)
E/flutter ( 586): #2 SqfliteDatabaseMixin.safeInvokeMethod (package:sqflite/src/database_mixin.dart:188:15)
E/flutter ( 586): #3 SqfliteDatabaseMixin.txnRawInsert.<anonymous closure> (package:sqflite/src/database_mixin.dart:363:14)
E/flutter ( 586): #4 SqfliteDatabaseMixin.txnSynchronized.<anonymous closure> (package:sqflite/src/database_mixin.dart:307:22)
E/flutter ( 586): #5 BasicLock.synchronized (package:synchronized/src/basic_lock.dart:32:26)
E/flutter ( 586): #6 SqfliteDatabaseMixin.txnSynchronized (package:sqflite/src/database_mixin.dart:303:43)
E/flutter ( 586): #7 SqfliteDatabaseMixin.txnWriteSynchronized (package:sqflite/src/database_mixin.dart:325:7)
E/flutter ( 586): #8 SqfliteDatabaseMixin.txnRawInsert (package:sqflite/src/database_mixin.dart:362:12)
E/flutter ( 586): #9 SqfliteDatabaseExecutorMixin.rawInsert (package:sqflite/src/database_mixin.dart:49:15)
E/flutter ( 586): #10 SqfliteDatabaseExecutorMixin.insert (package:sqflite/src/database_mixin.dart:59:12)
E/flutter ( 586): #11 Homes.addNewHome (package:search_list_view/providers/homes.dart:19:31)
E/flutter ( 586): <asynchronous suspension>
E/flutter ( 586): #12 _MyAppState.build.<anonymous closure> (package:search_list_view/main.dart:95:26)
E/flutter ( 586): #13 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14)
E/flutter ( 586): #14 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789:36)
E/flutter ( 586): #15 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter ( 586): #16 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
E/flutter ( 586): #17 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
E/flutter ( 586): #18 BaseTapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:199:7)
E/flutter ( 586): #19 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:467:9)
E/flutter ( 586): #20 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:76:12)
E/flutter ( 586): #21 PointerRouter._dispatchEventToRoutes.<anonymous closure> (package:flutter/src/gestures/pointer_router.dart:117:9)
E/flutter ( 586): #22 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:379:8)
E/flutter ( 586): #23 PointerRouter._dispatchEventToRoutes (package:flutter/src/gestures/pointer_router.dart:115:18)
E/flutter ( 586): #24 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:7)
E/flutter ( 586): #25 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter ( 586): #26 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter ( 586): #27 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter ( 586): #28 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter ( 586): #29 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter ( 586): #30 _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter ( 586): #31 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter ( 586): #32 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter ( 586): #33 _invoke1 (dart:ui/hooks.dart:273:10)
E/flutter ( 586): #34 _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
E/flutter ( 586):
If the answer is to change my DB schema so I have a table which joins dogs and houses and then do a custom query to pull back the information I'm after, then fine, I will do that. It doesn't seem too far fetch that a nosql db should be able to handle this... yes/no?
Any assistance would be much appreciated.
Thank you,
Bob
For storing any kind of value in the SQLite Database you can simply serialize the object into a JSON string and later deserialize the object.
lets say you have a class called Menu. (I am using JSON serializable here)
class Menu {
#JsonKey(name: "status")
String status;
#JsonKey(name: "data")
MenuListData menuListData;
Menu(this.status, this.menuListData);
factory Menu.fromJson(Map<String,dynamic>
json)=>_$MenuFromJson(json);
Map<String, dynamic> toJson() => _$MenuToJson(this);
}
Here is how to encode it in JSON and store it(in your bloc).
Menue menuList =
await getIt<LiveMenuRepository>().getMenuResponse(menuPost);
//decode the response to String format
String menuResponseString = jsonEncode(menuList);
//convert the string to Map of <String,dynamic> format
Map<String, dynamic> menuResponseMap = {"menu": menuResponseString};
//store this Map response in to local database
int menuStored = await getIt<LocalMenuRepository>().insertMenuResponseData(menuResponseMap);
Your DB insertion method
Future<int> insertMenuResponseData(Map<String,dynamic> menuResponse) async {
final db = await dbProvider.database;
var result = db.insert(menuTable, menuResponse);
return result;
}
Later retrieve your object using this
final Map<String, dynamic> menuList = await getIt<LocalMenuRepository>().getMenuResponseString();
// if(menuList!=null) {
menuList.forEach((key, value) {
if (key == "menu") {
storedMenu = value ;
}
});
//decode the string back to Map Object
final dynamic menuMap = jsonDecode(storedMenu);
//getting the Menu object using fromJson method
final Menu menuListNameResponse = Menu
.fromJson(menuMap as Map<String,dynamic>);
//getMenuResponseString method in db
Future<Map<String,dynamic>> getMenuResponse() async {
final db = await dbProvider.database;
List<Map<String, dynamic>> result;
result = await db.rawQuery('SELECT * FROM $menuTable');
// print(result[0]);
if (result.length > 0) {
return result[0];
}
return null;
}
Supported types are listed here (num, String or Uint8List): https://github.com/tekartik/sqflite/blob/master/sqflite/doc/supported_types.md
Nested content is not supported, Map and List should be encoded in a supported type for example as json string.

Flutter: version 0.2.8 breaks code that used to work

Before I update to the new version of flutter (see below) everything worked OK.
Now it does no longer work.
The following piece of code performs a "paged" load of a gridView
Could somebody tell me what has changed with the last version of Flutter and how to solve this issue ?
Many thanks
Flutter version:
flutter --version
Flutter 0.2.8 • channel beta • https://github.com/flutter/flutter.git
Framework • revision b397406561 (11 days ago) • 2018-04-02 13:53:20 -0700
Engine • revision c903c217a1
Tools • Dart 2.0.0-dev.43.0.flutter-52afcba357
Here is the code that used to work:
typedef Future<PageAnswer> ApiPageRequest(int page, int pageSize);
class MIDApi {
///
/// Returns the list of items belonging to the active profile
///
Future<PageAnswer> getItems({
int pageIndex: 0,
int pageSize: 50,
#required String sortOrder
}) async {
String url = "ItemsList/$sortOrder";
return ajaxGet(url).then((String responseBody) async {
// print(responseBody);
final Map response = json.decode(responseBody);
final _status = response["status"];
if (_status == "OK"){
// Everything is OK
Map map = json.decode(response["data"]);
List<Map> objects = map["List"];
int total = map["Total"];
return new PageAnswer(objects, total);
}
return Null;
}).catchError((){
return Null;
});
}
}
///
/// This widget is used to display a "paged" GridView
///
/// Invocation example:
/// new PagedGridView<Map>(request, widgetAdapter: adapt);
///
/// where: request could be
/// Future<List<Map>> request(int page, int pageSize) async {
/// routine to fetch the data from the server
/// }
///
/// and adapt could be:
/// Widget adapt(Map map){
/// return new MyWidget(map);
/// }
///
class PagedGridView extends StatefulWidget {
/// Abstraction for loading the data.
/// This can be anything: An API-Call,
/// loading data from a certain file or database,
/// etc. If will deliver a list of objects (of type T)
final ApiPageRequest pageRequest;
/// The number of columns per row of the grid
final int numberColumns;
/// The number of elements requested for each page
final int pageSize;
/// The number of left-over elements in list which
/// will trigger loading the next page
final int pageThreshold;
/// Used for building Widgets out of the fetched data
final WidgetAdapter<Map> widgetAdapter;
final bool reverse;
final Indexer<Map> indexer;
final Stream<Map> topStream;
/// Constructor
const PagedGridView({
Key key,
this.numberColumns: 2,
this.pageSize: 50,
this.pageThreshold: 10,
#required this.pageRequest,
#required this.widgetAdapter,
this.reverse: false,
this.indexer,
this.topStream
}): super(key: key);
#override
State<StatefulWidget> createState() {
return new PagedGridViewState();
}
}
class PagedGridViewState extends State<PagedGridView> {
/// Contains all fetched elements ready to display
List<Map> objects = [];
/// Total number of objects that could be returned
int total = -1;
/// A Future returned by loadNext() if there
/// is currently a request running
/// or null, if no request is performed
Future request;
Map<int, int> index = {};
void doSomething(){
print("I need to do something");
}
void Clear() async {
await onRefresh();
}
#override
void initState(){
super.initState();
/// At start, let's systematically try to fetch some data
this.lockedLoadNext();
if (widget.topStream != null){
widget.topStream.listen((Map t){
setState((){
this.objects.insert(0, t);
this.reIndex();
});
});
}
}
#override
Widget build(BuildContext context){
GridView listView = new GridView.builder(
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: widget.numberColumns),
itemBuilder: itemBuilder,
itemCount: objects.length,
reverse: widget.reverse
);
RefreshIndicator refreshIndicator = new RefreshIndicator(
onRefresh: onRefresh,
child: listView
);
return new NotificationListener<ListElementUpdate<Map>>(
child: refreshIndicator,
onNotification: onUpdate
);
}
Widget itemBuilder(BuildContext context, int index){
/// If we are entering the threshold zone,
/// try to fetch additional objects
if (index + widget.pageThreshold > objects.length){
notifyThreshold();
}
return widget.widgetAdapter != null ? widget.widgetAdapter(objects[index])
: new Container();
}
void notifyThreshold(){
lockedLoadNext();
}
bool onUpdate(ListElementUpdate<Map> update){
if (widget.indexer == null){
debugPrint('ListElementUpdate on un-indexed list');
return false;
}
int index = this.index[update.key];
if (index == null){
debugPrint('ListElementUpdate index not found');
return false;
}
setState((){
this.objects[index] = update.instance;
});
return true;
}
Future onRefresh() async {
this.request?.timeout(const Duration());
PageAnswer answer = await widget.pageRequest(0, widget.pageSize);
List<Map> fetched = answer.list;
total = answer.total;
setState(() {
this.objects.clear();
this.index.clear();
this.addObjects(fetched);
});
return true;
}
///
/// This routine only fetches new data, if no other request is pending
///
void lockedLoadNext() {
if (this.request == null) {
this.request = loadNext().then((x) {
this.request = null;
});
}
}
Future loadNext() async {
// If there is no need to fetch any further data, simply return
if (objects.length >= total && total != -1){
return Null;
}
int page = (objects.length / widget.pageSize).floor();
PageAnswer answer = await widget.pageRequest(page, widget.pageSize);
List<Map> fetched = answer.list;
total = answer.total;
if (mounted) {
this.setState(() {
addObjects(fetched);
});
}
}
void addObjects(Iterable<Map> objects) {
objects.forEach((Map object) {
int index = this.objects.length;
this.objects.add(object);
if (widget.indexer != null) {
this.index[widget.indexer(object)] = index;
}
});
}
void reIndex(){
this.index .clear();
if (widget.indexer!=null){
int i = 0;
this.objects.forEach((object){
index[widget.indexer(object)] == i;
i++;
});
}
}
}
Invocation code:
class ItemsPage extends StatefulWidget {
#override
_ItemsPageState createState() => new _ItemsPageState();
}
class _ItemsPageState extends State<ItemsPage> {
static final GlobalKey<PagedGridViewState> _gridKey = new GlobalKey<PagedGridViewState>();
String _path = mid.serverHttps ? "https://${mid.serverUrl}/"
: "http://${mid.serverUrl}/";
String _sortOrder;
final List<SortMethod> sortMethods = const <SortMethod>[
const SortMethod(value: 'alpha', title: "Alpha", icon: Icons.sort_by_alpha),
const SortMethod(value: 'older_first', title: "Older first", icon: Icons.autorenew),
const SortMethod(value: 'last_first', title: "Last first", icon: Icons.change_history),
];
Future<PageAnswer> request(int page, int pageSize) async {
PageAnswer answer = await mid.api.getItems(sortOrder: _sortOrder);
return answer;
}
void _handleTap(int lookId) {
print('tap:' + lookId.toString());
}
Widget adapt(Map map){
var photos = map["Photos"].split(";");
String photoName = photos[0].split("|")[0];
return new GestureDetector(
onTap: () {_handleTap(map["Id"]);},
child: new GridTile(
child: new Card(
child: new Stack(
fit: StackFit.expand,
children: <Widget>[
new Image.network(_path + photoName,
fit: BoxFit.fitHeight),
new Center(
child: new Text(
map["Title"],
textAlign: TextAlign.center,
)),
],
),
),
),
);
}
_onSortOrderChanged(String value) {
setState((){
_sortOrder = value;
_gridKey.currentState.Clear();
});
}
#override
void initState(){
super.initState();
_sortOrder = 'alpha';
}
#override
Widget build(BuildContext context) {
PagedGridView grid = new PagedGridView(
key: _gridKey,
pageRequest: request,
widgetAdapter: adapt,
numberColumns: 2,
);
DropdownButton ddl = new DropdownButton<String>(
value: _sortOrder,
items: sortMethods.map((SortMethod sort){
return new DropdownMenuItem(
value: sort.value,
child: new Row(children: <Widget>[new Icon(sort.icon), new Text(sort.title)],)
);
}).toList(),
onChanged: _onSortOrderChanged,
);
PopupMenuButton<ItemSorting> popSort = new PopupMenuButton<ItemSorting>(
icon: new Icon(Icons.sort),
itemBuilder: (BuildContext context) => <PopupMenuItem<ItemSorting>> [
const PopupMenuItem<ItemSorting>(
value: ItemSorting.alpha,
child: const Text('Sort Alpha')
),
const PopupMenuItem<ItemSorting>(
value: ItemSorting.last_first,
child: const Text('Sort Last First')
),
const PopupMenuItem<ItemSorting>(
value: ItemSorting.older_first,
child: const Text('Sort Older First')
)
],
onSelected: (ItemSorting action){
_onSortOrderChanged(action.toString().split('.')[1]);
},
);
return new Scaffold(
appBar: new AppBar(
title: new Text('My Items'),
actions: <Widget>[
popSort, //ddl,
],
),
body: new Center(
child: grid,
),
);
}
}
class SortMethod {
const SortMethod({this.title, this.icon, this.value});
final String title;
final IconData icon;
final String value;
}
Error stack:
E/flutter (15195): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (15195): type 'Future<Object>' is not a subtype of type 'FutureOr<PageAnswer>' where
E/flutter (15195): Future is from dart:async
E/flutter (15195): Object is from dart:core
E/flutter (15195): FutureOr is from dart:async
E/flutter (15195): PageAnswer is from file:///D:/Development/appli/lib/libraries/function_types.dart
E/flutter (15195):
E/flutter (15195): #0 MIDApi.getItems (file:///D:/Development/appli/lib/libraries/api.dart:35:8)
E/flutter (15195): <asynchronous suspension>
E/flutter (15195): #1 _ItemsPageState.request (file:///D:/Development/appli/lib/pages/items.dart:30:39)
E/flutter (15195): <asynchronous suspension>
E/flutter (15195): #2 PagedGridViewState.loadNext (file:///D:/Development/appli/lib/widgets/paged_grid_view.dart:191:38)
E/flutter (15195): <asynchronous suspension>
E/flutter (15195): #3 PagedGridViewState.lockedLoadNext (file:///D:/Development/appli/lib/widgets/paged_grid_view.dart:178:22)
E/flutter (15195): #4 PagedGridViewState.initState (file:///D:/Development/appli/lib/widgets/paged_grid_view.dart:93:10)
E/flutter (15195): #5 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3734:58)
E/flutter (15195): #6 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600:5)
E/flutter (15195): #7 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890:14)
E/flutter (15195): #8 Element.updateChild (package:flutter/src/widgets/framework.dart:2693:12)
E/flutter (15195): #9 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4637:14)
E/flutter (15195): #10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890:14)
E/flutter (15195): #11 Element.updateChild (package:flutter/src/widgets/framework.dart:2693:12)
E/flutter (15195): #12 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636:16)
E/flutter (15195): #13 Element.rebuild (package:flutter/src/widgets/framework.dart:3478:5)
E/flutter (15195): #14 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605:5)
E/flutter (15195): #15 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600:5)
E/flutter (15195): #16 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890:14)
E/flutter (15195): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:2693:12)
E/flutter (15195): #18 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636:16)
E/flutter (15195): #19 Element.rebuild (package:flutter/src/widgets/framework.dart:3478:5)
E/flutter (15195): #20 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605:5)
E/flutter (15195): #21 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600:5)
E/flutter (15195): #22 ParentDataElement.mount (package:flutter/src/widgets/framework.dart:3938:11)
E/flutter (15195): #23 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890:14)
E/flutter (15195): #24 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4742:32)
E/flutter (15195): #25 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890:14)
E/flutter (15195): #26 Element.updateChild (package:flutter/src/widgets/framework.dart:2693:12)
E/flutter (15195): #27 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636:16)
E/flutter (15195): #28 Element.rebuild (package:flutter/src/widgets/framework.dart:3478:5)
E/flutter (15195): #29 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605:5)
E/flutter (15195): #30 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3752:11)
E/flutter (15195): #31 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600:5)
E/flutter (15195): #32 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890:14)
E/flutter (15195): #33 Element.updateChild (package:flutter/src/widgets/framework.dart:2693:12)
E/flutter (15195): #34 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3636:16)
E/flutter (15195): #35 Element.rebuild (package:flutter/src/widgets/framework.dart:3478:5)
E/flutter (15195): #36 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3605:5)
E/flutter (15195): #37 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600:5)
E/flutter (15195): #38 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890:14)
E/flutter (15195): #39 Element.updateChild (package:flutter/src/widgets/framework.dart:2693:12)
E/flutter (15195): #40 ComponentElement.performRebuild (packag
E/flutter (15195): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (15195): type 'Future<Object>' is not a subtype of type 'FutureOr<PageAnswer>' where
E/flutter (15195): Future is from dart:async
E/flutter (15195): Object is from dart:core
E/flutter (15195): FutureOr is from dart:async
E/flutter (15195): PageAnswer is from file:///D:/Development/appli/lib/libraries/function_types.dart
E/flutter (15195):
E/flutter (15195): #0 MIDApi.getItems (file:///D:/Development/appli/lib/libraries/api.dart:34:8)
E/flutter (15195): <asynchronous suspension>
E/flutter (15195): #1 _ItemsPageState.request (file:///D:/Development/appli/lib/pages/items.dart:30:39)
E/flutter (15195): <asynchronous suspension>
E/flutter (15195): #2 PagedGridViewState.onRefresh (file:///D:/Development/appli/lib/widgets/paged_grid_view.dart:160:38)
E/flutter (15195): <asynchronous suspension>
E/flutter (15195): #3 PagedGridViewState.Clear (file:///D:/Development/appli/lib/widgets/paged_grid_view.dart:85:11)
E/flutter (15195): <asynchronous suspension>
E/flutter (15195): #4 _ItemsPageState._onSortOrderChanged.<anonymous closure> (file:///D:/Development/appli/lib/pages/items.dart:67:29)
E/flutter (15195): #5 State.setState (package:flutter/src/widgets/framework.dart:1108:30)
E/flutter (15195): #6 _ItemsPageState._onSortOrderChanged (file:///D:/Development/appli/lib/pages/items.dart:65:5)
E/flutter (15195): #7 _ItemsPageState.build.<anonymous closure> (file:///D:/Development/appli/lib/pages/items.dart:114:9)
E/flutter (15195): #8 _PopupMenuButtonState.showButtonMenu.<anonymous closure> (package:flutter/src/material/popup_menu.dart)
E/flutter (15195): #9 _RootZone.runUnary (dart:async/zone.dart:1381:54)
E/flutter (15195): #10 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
E/flutter (15195): #11 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633:45)
E/flutter (15195): #12 Future._propagateToListeners (dart:async/future_impl.dart:662:32)
E/flutter (15195): #13 Future._completeWithValue (dart:async/future_impl.dart:477:5)
E/flutter (15195): #14 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:507:7)
E/flutter (15195): #15 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (15195): #16 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
I/flutter (15195): Another exception was thrown: type '() => Future<dynamic>' is not a subtype of type '() => Future<Null>'
E/flutter (15195): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (15195): type '() => Type' is not a subtype of type '(Object) => FutureOr<Object>'
E/flutter (15195): #0 _FutureListener.handleError (dart:async/future_impl.dart:145:11)
E/flutter (15195): #1 Future._propagateToListeners.handleError (dart:async/future_impl.dart:645:47)
E/flutter (15195): #2 Future._propagateToListeners (dart:async/future_impl.dart:666:24)
E/flutter (15195): #3 Future._completeError (dart:async/future_impl.dart:485:5)
E/flutter (15195): #4 _SyncCompleter._completeError (dart:async/future_impl.dart:55:12)
E/flutter (15195): #5 _Completer.completeError (dart:async/future_impl.dart:27:5)
E/flutter (15195): #6 MIDApi.getItems.<anonymous closure> (file:///D:/Development/appli/lib/libraries/api.dart)
E/flutter (15195): <asynchronous suspension>
E/flutter (15195): #7 _RootZone.runUnary (dart:async/zone.dart:1381:54)
E/flutter (15195): #8 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
E/flutter (15195): #9 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633:45)
E/flutter (15195): #10 Future._propagateToListeners (dart:async/future_impl.dart:662:32)
E/flutter (15195): #11 Future._complete (dart:async/future_impl.dart:467:7)
E/flutter (15195): #12 _SyncCompleter.complete (dart:async/future_impl.dart:51:12)
E/flutter (15195): #13 ajaxGet (file:///D:/Development/appli/lib/libraries/ajax.dart)
E/flutter (15195): <asynchronous suspension>
E/flutter (15195): #14 MIDApi.getItems (file:///D:/Development/appli/lib/libraries/api.dart:21:12)
E/flutter (15195): <asynchronous suspension>
E/flutter (15195): #15 _ItemsPageState.request (file:///D:/Development/appli/lib/pages/items.dart:30:39)
E/flutter (15195): <asynchronous suspension>
E/flutter (15195): #16 PagedGridViewState.onRefresh (file:///D:/Development/appli/lib/widgets/paged_grid_view.dart:160:38)
E/flutter (15195): <asynchronous suspension>
E/flutter (15195): #17 PagedGridViewState.Clear (file:///D:/Development/appli/lib/widgets/paged_grid_view.dart:85:11)
E/flutter (15195): <asynchronous suspension>
E/flutter (15195): #18 _ItemsPageState._onSortOrderChanged.<anonymous closure> (file:///D:/Development/appli/lib/pages/items.dart:67:29)
E/flutter (15195): #19 State.setState (package:flutter/src/widgets/framework.dart:1108:30)
E/flutter (15195): #20 _ItemsPageState._onSortOrderChanged (file:///D:/Development/appli/lib/pages/items.dart:65:5)
E/flutter (15195): #21 _ItemsPageState.build.<anonymous closure> (file:///D:/Development/appli/lib/pages/items.dart:114:9)
E/flutter (15195): #22 _PopupMenuButtonState.showButtonMenu.<anonymous closure> (package:flutter/src/material/popup_menu.dart)
E/flutter (15195): #23 _RootZone.runUnary (dart:async/zone.dart:1381:54)
E/flutter (15195): #24 _FutureListener.handleValue (dart:async/future_impl.dart:129:18)
E/flutter (15195): #25 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:633:45)
E/flutter (15195): #26 Future._propagateToListeners (dart:async/future_impl.dart:662:32)
E/flutter (15195): #27 Future._completeWithValue (dart:async/future_impl.dart:477:5)
E/flutter (15195): #28 Future._asyncComplete.<anonymous closure> (dart:async/future_impl.dart:507:7)
E/flutter (15195): #29 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (15195): #30 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)