I'm getting data from my api as a following JSON object to create chart with the data. I want to covert this DIO response to a Map<String, int> object in my flutter app.
My API response:
{
"November 20": 1,
"October 20": 3,
"September 20": 1
}
My try of creating a map object:
Future<bool> fetchChartData() async {
var response = await CasesApiService().getChartData();
Map<String, dynamic> data = jsonDecode(response.data);
}
But it shows the following error:
E/flutter ( 4733): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String'
E/flutter ( 4733): #0 CasesProvider.fetchChartData
package:bdopsApp/providers/casesProvider.dart:86
E/flutter ( 4733): <asynchronous suspension>
E/flutter ( 4733): #1 _CasesChartViewState.build.<anonymous closure>
package:bdopsApp/…/casesApp/casesChart.dart:31
E/flutter ( 4733): #2 _InkResponseState._handleTap
package:flutter/…/material/ink_well.dart:985
E/flutter ( 4733): #3 _InkResponseState.build.<anonymous closure>
package:flutter/…/material/ink_well.dart:1101
E/flutter ( 4733): #4 GestureRecognizer.invokeCallback
package:flutter/…/gestures/recognizer.dart:183
E/flutter ( 4733): #5 TapGestureRecognizer.handleTapUp
package:flutter/…/gestures/tap.dart:598
E/flutter ( 4733): #6 BaseTapGestureRecognizer._checkUp
package:flutter/…/gestures/tap.dart:287
E/flutter ( 4733): #7 BaseTapGestureRecognizer.handlePrimaryPointer
package:flutter/…/gestures/tap.dart:222
E/flutter ( 4733): #8 PrimaryPointerGestureRecognizer.handleEvent
package:flutter/…/gestures/recognizer.dart:476
E/flutter ( 4733): #9 PointerRouter._dispatch
package:flutter/…/gestures/pointer_router.dart:77
E/flutter ( 4733): #10 PointerRouter._dispatchEventToRoutes.<anonymous closure>
package:flutter/…/gestures/pointer_router.dart:122
E/flutter ( 4733): #11 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:377:8)
E/flutter ( 4733): #12 PointerRouter._dispatchEventToRoutes
package:flutter/…/gestures/pointer_router.dart:120
E/flutter ( 4733): #13 PointerRouter.route
package:flutter/…/gestures/pointer_router.dart:106
E/flutter ( 4733): #14 GestureBinding.handleEvent
package:flutter/…/gestures/binding.dart:368
E/flutter ( 4733): #15 GestureBinding.dispatchEvent
package:flutter/…/gestures/binding.dart:348
E/flutter ( 4733): #16 RendererBinding.dispatchEvent
package:flutter/…/rendering/binding.dart:268
E/flutter ( 4733): #17 GestureBinding._handlePointerEventImmediately
package:flutter/…/gestures/binding.dart:303
E/flutter ( 4733): #18 GestureBinding.handlePointerEvent
package:flutter/…/gestures/binding.dart:267
E/flutter ( 4733): #19 GestureBinding._flushPointerEventQueue
package:flutter/…/gestures/binding.dart:225
E/flutter ( 4733): #20 GestureBinding._handlePointerDataPacket
package:flutter/…/gestures/binding.dart:208
E/flutter ( 4733): #21 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter ( 4733): #22 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 4733): #23 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 4733): #24 _invoke1 (dart:ui/hooks.dart:265:10)
E/flutter ( 4733): #25 _dispatchPointerDataPacket (dart:ui/hooks.dart:174:5)
N.B: I'm doing my final year project. Therefore, the process I'm following might not be what is used in real world project.
If you run the following example in the dartPad you will get the result that you are looking for:
import 'dart:convert';
void main() {
var jsonString= "{\"November 20\": \"1\",\"October 20\": \"2\",\"September 20\": \"3\"}";
Map<String, dynamic> data = jsonDecode(jsonString);
print(data);
}
I think you need to check the data that you are getting it from the response.data
Related
I have a query function for data from the database that comes with the id number from the database, then the id is saved in shared_preferences in case the new id that comes from the database is larger than the old id that was in the shared_preferences previously.But after running the code, the following problem comes:
E/flutter (30884): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: Class 'String' has no instance method '<'.
E/flutter (30884): Receiver: ""
E/flutter (30884): Tried calling: <(7)
E/flutter (30884): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
E/flutter (30884): #1 AddCommentsState.getLogin.<anonymous closure> (package:flutter_apptestqeuriy/AddComment.dart:84:46)
E/flutter (30884): #2 State.setState (package:flutter/src/widgets/framework.dart:1240:30)
E/flutter (30884): #3 AddCommentsState.getLogin (package:flutter_apptestqeuriy/AddComment.dart:78:5)
E/flutter (30884): <asynchronous suspension>
E/flutter (30884): #4 AddCommentsState.initState.<anonymous closure> (package:flutter_apptestqeuriy/AddComment.dart:57:9)
E/flutter (30884): #5 interval.function (package:flutter_apptestqeuriy/AddComment.dart:21:9)
E/flutter (30884): #6 _rootRun (dart:async/zone.dart:1182:47)
E/flutter (30884): #7 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (30884): #8 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter (30884): #9 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter (30884): #10 _rootRun (dart:async/zone.dart:1190:13)
E/flutter (30884): #11 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (30884): #12 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1021:23)
E/flutter (30884): #13 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter (30884): #14 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19)
E/flutter (30884): #15 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5)
E/flutter (30884): #16 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter (30884):
This is the code used to query from the database:
var user_id;
var my_pre_id;
Future<String> getLogin() async {
var response = await http.get(Uri.encodeFull("http://xxxxxxxxxxx/Application.php"),);
setState(() {
var convertDataToJson = json.decode(response.body);
data = convertDataToJson['result'];
if (data != null) {
user_id = int.parse(data[0]['id']);
my_pre_id = _myPreferences.id;
if (my_pre_id == null || my_pre_id < user_id ){
_myPreferences.id = user_id;
_myPreferences.commit();
// print("tappeeeeedddd $my_pre_id");
}
}
});
}
Does anyone know the cause of the problem?
I think the issue comes from my_pre_id < user_id where my_pre_id is actually a String. You might want to do an int.parse() on it as well or change its type in the class.
I am new to flutter. when I run my code , I got the error
E/flutter (16181): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Unhandled error type '() => Future<List<Food>>' is not a subtype of type 'List<Food>' occurred in Instance of 'MenuBloc'.
E/flutter (16181): #0 MenuBloc.mapEventToState (package:restuarant_app/Bloc/menue_bloc/menu_bloc.dart:30:7)
E/flutter (16181): <asynchronous suspension>
E/flutter (16181): #1 Bloc._bindEventsToStates.<anonymous closure> (package:bloc/src/bloc.dart:232:20)
E/flutter (16181): #2 Stream.asyncExpand.onListen.<anonymous closure> (dart:async/stream.dart:579:30)
E/flutter (16181): #3 _rootRunUnary (dart:async/zone.dart:1192:38)
E/flutter (16181): #4 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter (16181): #5 _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
E/flutter (16181): #6 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
E/flutter (16181): #7 _DelayedData.perform (dart:async/stream_impl.dart:594:14)
E/flutter (16181): #8 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:710:11)
E/flutter (16181): #9 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:670:7)
E/flutter (16181): #10 _rootRun (dart:async/zone.dart:1180:38)
E/flutter (16181): #11 _CustomZone.run (dart:async/zone.dart:1077:19)
E/flutter (16181): #12 _CustomZone.runGuarded (dart:async/zone.dart:979:7)
E/flutter (16181): #13 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
E/flutter (16181): #14 _rootRun (dart:async/zone.dart:1184:13)
E/flutter (16181): #15 _CustomZone.run (dart:async/zone.dart:1077:19)
E/flutter (16181): #16 _CustomZone.runGuarded (dart:async/zone.dart:979:7)
E/flutter (16181): #17 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1019:23)
E/flutter (16181): #18 _microtaskLoop (dart:async/schedule_microtask.dart:43:21)
E/flutter (16181): #19 _startMicrotaskLoop (dart:async/schedule_microtask.dart:52:5)
E/flutter (16181):
E/flutter (16181): #0 Cubit.onError.<anonymous closure> (package:bloc/src/cubit.dart:140:7)
E/flutter (16181): #1 Cubit.onError (package:bloc/src/cubit.dart:141:6)
E/flutter (16181): #2 Bloc.onError (package:bloc/src/bloc.dart:113:11)
E/flutter (16181): #3 _rootRunBinary (dart:async/zone.dart:1204:38)
E/flutter (16181): #4 _CustomZone.runBinary (dart:async/zone.dart:1093:19)
E/flutter (16181): #5 _CustomZone.runBinaryGuarded (dart:async/zone.dart:995:7)
E/flutter (16181): #6 _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:358:15)
E/flutter (16181): #7 _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:376:16)
E/flutter (16181): #8 _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:275:7)
E/flutter (16181): #9 _SyncBroadcastStreamController._sendError.<anonymous closure> (dart:async/broadcast_stream_controller.dart:393:20)
E/flutter (16181): #10 _BroadcastStreamController._forEachListener (dart:async/broadcast_stream_controller.dart:327:15)
E/flutter (16181): #11 _SyncBroadcastStreamController._sendError (dart:async/broadcast_stream_controller.dart:392:5)
E/flutter (16181): #12 _BroadcastStreamController._addError (dart:async/broadcast_stream_controller.dart:294:5)
E/flutter (16181): #13 _rootRunBinary (dart:async/zone.dart:1204:38)
E/flutter (16181): #14 _CustomZone.runBinary (dart:async/zone.dart:1093:19)
E/flutter (16181): #15 _CustomZone.runBinaryGuarded (dart:async/zone.dart:995:7)
E/flutter (16181): #16 _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:358:15)
E/flutter (16181): #17 _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:376:16)
E/flutter (16181): #18 _BufferingStreamSubscription._addError (dart:async/stream_impl.dart:275:7)
E/flutter (16181): #19 _ForwardingStreamSubscription._addError (dart:async/stream_pipe.dart:139:11)
E/flutter (16181): #20 _ForwardingStream._handleError (dart:async/stream_pipe.dart:104:10)
E/flutter (16181): #21 _ForwardingStreamSubscription._handleError (dart:async/stream_pipe.dart:170:13)
E/flutter (16181): #22 _rootRunBinary (dart:async/zone.dart:1204:38)
E/flutter (16181): #23 _CustomZone.runBinary (dart:async/zone.dart:1093:19)
E/flutter (16181): #24 _CustomZone.runBinaryGuarded (dart:async/zone.dart:995:7)
E/flutter (16181): #25 _BufferingStreamSubscription._sendError.sendError (dart:async/stream_impl.dart:358:15)
E/flutter (16181): #26 _BufferingStreamSubscription._sendError (dart:async/stream_impl.dart:376:16)
E/flutter (16181): #27 _DelayedError.perform (dart:async/stream_impl.dart:605:14)
E/flutter (16181): #28 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:710:11)
E/flutter (16181): #29 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:670:7)
E/flutter (16181): #30 _rootRun (dart:async/zone.dart:1180:38)
E/flutter (16181): #31 _C
I would like to get data from remote server.I use bloc library in my code.
This is part of menue_bloc.dart .I got error on line allFood= await _foodRepositiry.getAllFood() ;.
class MenuBloc extends Bloc<FoodEvent, MenuState> {
final _foodRepositiry = FoodRepository();
Map<String, List<Food>> mapFoodList;
MenuBloc({this.mapFoodList=const{}}) : super(InitialMenuState());
#override
// TODO: implement initialState
MenuState get initialState => InitialMenuState();
#override
Stream<MenuState> mapEventToState(FoodEvent event) async* {
print("loading....");
yield Loading();
if (event is GetAllFoodEvent) {
print("Get all food....");
this.mapFoodList = {};
List<Food> allFood;
allFood= await _foodRepositiry.getAllFood() ;
try {
print("in menu bloc...... ");
allFood.forEach((food) {
print(food.toString());
if (!this.mapFoodList.containsKey(food.category)) {
this.mapFoodList[food.category.toString()] = [];
}
this.mapFoodList[food.category].add(food);
});
yield Loaded(mapFoodList: this.mapFoodList);
} catch (e, stacktrace) {
print(e.toString());
print(stacktrace.toString());
When I change List<Food> allFood;to Future<List<Food>> allFood; it gives me following error
I/flutter (16181): type '() => Future<List<Food>>' is not a subtype of type 'Future<List<Food>>'
This FoodRepository code.
class FoodRepository{
final foodDao=new FoodDao();
final foodApiClient =new FoodApiClient();
Future getAllFood() async{
if(await checkInternetConnection()) {
print("fetch data from remote server");
return foodApiClient.fetchAllFood;
}else{
print("from db");
return foodDao.getAllFood();
}
}
}
This is FoodApiClient code:
class FoodApiClient{
static const baseUrl = '10.0.2.2';
final http.Client httpClient;
FoodApiClient({this.httpClient});
Future<List<Food>> fetchAllFood()async{
String url=":8080/resturant/food/allFood";
// print(url);
List<Food> foodList;
print(url);
final allFoodResponse=await httpClient.get(baseUrl+url);
print(allFoodResponse);
if (allFoodResponse.statusCode != 200) {
throw Exception('An error occured while loading food list!!! status code: '+allFoodResponse.statusCode.toString());
}
print("foodJson");
List foodJson = json.decode(allFoodResponse.body);
print(foodJson);
//foodJson.forEach((food) {foodList.add(Food.fromJson(food)); });
foodList=foodJson.map((f)=>Food.fromJson(f)).toList();
return foodList;
}
}
Future getAllFood() async{
needs to be
Future<List<Food>> getAllFood() async {
and then you need to follow the compiler errors from there, because there are a lot more instances that I cannot all name and describe here.
I strongly advise you to use proper dart formatting, and the package pedantic to tell you all about your code and how to improve it if you cannot find those places yourself.
I'm a beginner at Flutter and I'm currently following along with a tutorial to built a task planner (https://www.youtube.com/watch?v=xJSestoFlJ8&list=PLF9bFmu3NqWqchwS3DO9MDSl15IiHQWcr&index=9)
After rewriting the code by hand (the database, etc), when I restarted to app to show the items I saved into the database in the debug console, I got an error saying while working with initstate and setstate
Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index'
Here is the code related to the error
final TextEditingController _textEditingController = TextEditingController();
var db = DatabaseHelper();
#override
void initState() {
super.initState();
_readTaskList();
}
void _handleSubmitted(String text) async {
_textEditingController.clear();
Tasks tasksItem = Tasks(text, DateTime.now().toIso8601String());
int savedItemId = await db.saveItem(tasksItem);
print("Item saved ID: $savedItemId");
}
_readTaskList() async {
List items = await db.getItems();
items.forEach((item) {
Tasks tasksItem = Tasks.map(items);
print("DB Items: ${tasksItem.itemName}");
});
}
and here is the full debug console log
E/flutter ( 8249): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index'
E/flutter ( 8249): #0 new Tasks.map
package:gatorblocks_rbt/models/tasks.dart:12
E/flutter ( 8249): #1 _TaskPlannerState._readTaskList.<anonymous closure>
package:gatorblocks_rbt/pages/taskPlanner.dart:105
E/flutter ( 8249): #2 List.forEach (dart:core-patch/growable_array.dart:285:8)
E/flutter ( 8249): #3 _TaskPlannerState._readTaskList
package:gatorblocks_rbt/pages/taskPlanner.dart:104
E/flutter ( 8249): <asynchronous suspension>
E/flutter ( 8249): #4 _TaskPlannerState.initState
package:gatorblocks_rbt/pages/taskPlanner.dart:24
E/flutter ( 8249): #5 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4355
E/flutter ( 8249): #6 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4201
E/flutter ( 8249): #7 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #8 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #9 SingleChildRenderObjectElement.mount
package:flutter/…/widgets/framework.dart:5445
E/flutter ( 8249): #10 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #11 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #12 ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4243
E/flutter ( 8249): #13 Element.rebuild
package:flutter/…/widgets/framework.dart:3947
E/flutter ( 8249): #14 ComponentElement._firstBuild
package:flutter/…/widgets/framework.dart:4206
E/flutter ( 8249): #15 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4201
E/flutter ( 8249): #16 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #17 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #18 SingleChildRenderObjectElement.mount
package:flutter/…/widgets/framework.dart:5445
E/flutter ( 8249): #19 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #20 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #21 SingleChildRenderObjectElement.mount
package:flutter/…/widgets/framework.dart:5445
E/flutter ( 8249): #22 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #23 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #24 ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4243
E/flutter ( 8249): #25 Element.rebuild
package:flutter/…/widgets/framework.dart:3947
E/flutter ( 8249): #26 ComponentElement._firstBuild
package:flutter/…/widgets/framework.dart:4206
E/flutter ( 8249): #27 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4381
E/flutter ( 8249): #28 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4201
E/flutter ( 8249): #29 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #30 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #31 SingleChildRenderObjectElement.mount
package:flutter/…/widgets/framework.dart:5445
E/flutter ( 8249): #32 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #33 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #34 SingleChildRenderObjectElement.mount
package:flutter/…/widgets/framework.dart:5445
E/flutter ( 8249): #35 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #36 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #37 ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4243
E/flutter ( 8249): #38 Element.rebuild
package:flutter/…/widgets/framework.dart:3947
E/flutter ( 8249): #39 ComponentElement._firstBuild
package:flutter/…/widgets/framework.dart:4206
E/flutter ( 8249): #40 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4381
E/flutter ( 8249): #41 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4201
E/flutter ( 8249): #42 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #43 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #44 ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4243
E/flutter ( 8249): #45 Element.rebuild (package:flutte
Here is a screenshot
The app works perfectly fine, it doesn't crash or anything, just fails to properly show the items that I've saved into the database.
You are getting the error because you are putting a int into a Text widget that accepts a String.
You can solve that by converting the int using the toString() method.
Check the code below: Replace it with your handleSubmitted function:
void _handleSubmitted(String text) async {
_textEditingController.clear();
Tasks tasksItem = Tasks(text, DateTime.now().toIso8601String());
int savedItemId = await db.saveItem(tasksItem);
// convert savedItemId to a string using toString() method
print("Item saved ID: $savedItemId.toString()");
}
I hope this helps.
UPDATED
After going through your code, I can see you are trying to access the field id which you didn't define in your Tasks constructor.
Why you are getting the error:
Type String is not a subtype of int index
Hope this solves your error.
I am not getting output on my app and it should have give a output like many question is how to sisplay json data in my flutter app
class AppState extends State<AppName>{
var name ;
var email ;
int cgpa ;
TextEditingController user = new TextEditingController();
String url = 'http://10.42.0.243:8000/students/';
getData(String username) async{
String profile = url+'?search='+username;
var res = await http.get(profile,headers: {"Accept":"application/json"});
print(res.body);
debugPrint(res.body);
var resBody = json.decode(res.body);
name = resBody['sname'].toString();
email = resBody['email'].toString();
cgpa = resBody['cgpa'] ;
debugPrint(name);
setState(() {
print("Success");
});
}
my app screenshot is
JSON Data Screenshot
Error output:
Performing hot reload...
Syncing files to device Moto G 5 Plus...
Reloaded 0 of 576 libraries in 389ms.
E/BpSurfaceComposerClient(28411): Failed to transact (-1)
E/BpSurfaceComposerClient(28411): Failed to transact (-1)
I/flutter (28411): [{"id":1,"sname":"Ashutosh Lokhande","email":"2016bit053#sggs.ac.in","year":"2016","cgpa":7.2}]
I/flutter (28411): [{"id":1,"sname":"Ashutosh Lokhande","email":"2016bit053#sggs.ac.in","year":"2016","cgpa":7.2}]
E/flutter (28411): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index'
E/flutter (28411): #0 AppState.getData (package:json_flutter/main.dart:28:19)
E/flutter (28411):
E/flutter (28411): #1 AppState.build. (package:json_flutter/main.dart:56:34)
E/flutter (28411): #2 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:654:14)
E/flutter (28411): #3 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:729:32)
E/flutter (28411): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (28411): #5 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11)
E/flutter (28411): #6 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:275:7)
E/flutter (28411): #7 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:455:9)
E/flutter (28411): #8 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:75:13)
E/flutter (28411): #9 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:102:11)
E/flutter (28411): #10 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:19)
E/flutter (28411): #11 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (28411): #12 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (28411): #13 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (28411): #14 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (28411): #15 _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter (28411): #16 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter (28411): #17 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter (28411): #18 _invoke1 (dart:ui/hooks.dart:263:10)
E/flutter (28411): #19 _dispatchPointerDataPacket (dart:ui/hooks.dart:172:5)
E/flutter (28411):
I'm trying to use a simple GET requests in REST to flutter, but have an error
Code:
Future<Map> timeStamp() async {
const request =
"https://armariosinteligentes.com/api/v3/timestamp";
http.Response response = await http.get(request);
print(json.decode(response.body));
}
json: {"timestamp":1566397501}
Error:
E/flutter ( 7041): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: HandshakeException: Handshake error in client (OS Error:
E/flutter ( 7041): BLOCK_TYPE_IS_NOT_01(padding.c:108)
E/flutter ( 7041): PADDING_CHECK_FAILED(rsa_impl.c:641)
E/flutter ( 7041): public key routines(a_verify.c:105)
E/flutter ( 7041): CERTIFICATE_VERIFY_FAILED: certificate signature failure(handshake.cc:352)) E/flutter ( 7041):
#0 IOClient.send (package:http/src/io_client.dart:33:23) E/flutter ( 7041): <asynchronous suspension> E/flutter ( 7041):
#1 BaseClient._sendUnstreamed (package:http/src/base_client.dart:169:38) E/flutter ( 7041): <asynchronous suspension> E/flutter ( 7041):
#2 BaseClient.get (package:http/src/base_client.dart:32:7) E/flutter ( 7041):
#3 get.<anonymous closure> (package:http/http.dart:46:36) E/flutter ( 7041):
#4 _withClient (package:http/http.dart:166:20) E/flutter ( 7041): <asynchronous suspension> E/flutter ( 7041):
#5 get (package:http/http.dart:46:5) E/flutter ( 7041):
#6 timeStamp (package:armarios_inteligentes/screens/locker_screen.dart:196:34) E/flutter ( 7041): <asynchronous suspension> E/flutter ( 7041):
#7 LockerScreenState.build.<anonymous closure> (package:armarios_inteligentes/screens/locker_screen.dart:114:15) E/flutter ( 7041):
#8 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:635:14) E/flutter ( 7041):
#9 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:711:32) E/flutter ( 7041):
#10 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24) E/flutter ( 7041): #11 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:365:11) E/flutter ( 7041):
#12 TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:312:7) E/flutter ( 7041):
#13 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27) E/flutter ( 7041):
#14 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20) E/flutter ( 7041):
#15 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22) E/flutter ( 7041):
#16 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7) E/flutter ( 7041):
#17 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7) E/flutter ( 7041):
#18 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7) E/flutter ( 7041):
#19 _rootRunUnary (dart:async/zone.dart:1136:13) E/flutter ( 7041):
#20 _CustomZone.runUnary (dart:async/zone.dart:1029:19) E/flutter ( 7041):
#21 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7) E/flutter ( 7041):
#22 _invoke1 (dart:ui/hooks.dart:250:10) E/flutter ( 7041):
#23 _dispatchPointerDataPacket (dart:ui/hooks.dart:159:5) E/flutter ( 7041):
timeStamp() async {
final response =
await http.get('http://armariosinteligentes.com/api/v3/timestamp');
if (response.statusCode == 200) {
// If server returns an OK response, parse the JSON.
var jsonResponse = json.decode(response.body);
tempoStamp tempo = new tempoStamp.fromJson(jsonResponse);
var time = ('${tempo.timestamp}');
return time;
} else {
// If that response was not OK, throw an error.
throw Exception('Failed to load post');
}
}
Result: 1566411603
Try to remove the https and put http instead. And verify your connection, you need to know if you can call websites like this in your local...