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...
Related
My app was working fine on both iOS and Android but after updating to Flutter 2.10.0 I'm getting this issue:
Unhandled Exception: Null check operator used on a null value
E/flutter ( 8991): #0 Element.widget (package:flutter/src/widgets/framework.dart:3203:31)
E/flutter ( 8991): #1 Provider._inheritedElementOf (package:provider/src/provider.dart:341:17)
E/flutter ( 8991): #2 Provider.of (package:provider/src/provider.dart:293:30)
E/flutter ( 8991): #3 Shop.getPastPurchases.<anonymous closure> (package:my_rents/services/shop.dart:123:20)
E/flutter ( 8991): #4 _rootRunUnary (dart:async/zone.dart:1434:47)
E/flutter ( 8991): #5 _CustomZone.runUnary (dart:async/zone.dart:1335:19)
E/flutter ( 8991): #6 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1244:7)
E/flutter ( 8991): #7 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:341:11)
E/flutter ( 8991): #8 _DelayedData.perform (dart:async/stream_impl.dart:591:14)
E/flutter ( 8991): #9 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:706:11)
E/flutter ( 8991): #10 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:663:7)
E/flutter ( 8991): #11 _rootRun (dart:async/zone.dart:1418:47)
E/flutter ( 8991): #12 _CustomZone.run (dart:async/zone.dart:1328:19)
E/flutter ( 8991): #13 _CustomZone.runGuarded (dart:async/zone.dart:1236:7)
E/flutter ( 8991): #14 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1276:23)
E/flutter ( 8991): #15 _rootRun (dart:async/zone.dart:1426:13)
E/flutter ( 8991): #16 _CustomZone.run (dart:async/zone.dart:1328:19)
E/flutter ( 8991): #17 _CustomZone.runGuarded (dart:async/zone.dart:1236:7)
E/flutter ( 8991): #18 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1276:23)
E/flutter ( 8991): #19 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter ( 8991): #20 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
My implementation:
Future<List<PurchaseDetails>> getPastPurchases(BuildContext context) async {
if (this.purchases.isEmpty) {
final Stream<List<PurchaseDetails>> purchaseUpdated =
inAppPurchase.purchaseStream;
_subscription = purchaseUpdated.listen((purchaseDetailsList) {
if (purchaseDetailsList.isEmpty) {
Provider.of<AdState>(context, listen: false).toggleAds(context, true);
} else {
listenToPurchaseUpdated(context, purchaseDetailsList);
}
}, onDone: () {
_subscription.cancel();
}, onError: (error) {
});
await inAppPurchase.restorePurchases(); // If I comment this line everything works
}
return this.purchases;
}
Again, I made no changes on my code, just updating Flutter
I am posting a map on button click using provider, which calls Chopper service to post a map data to the server. It gives an error to the server which is something like this.
I/flutter ( 4801): Observatory listening on ************************************
E/flutter ( 4801): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Converting object to an encodable object failed: Instance of 'DateTime'
E/flutter ( 4801): #0 _JsonStringifier.writeObject (dart:convert/json.dart:688:7)
E/flutter ( 4801): #1 _JsonStringifier.writeMap (dart:convert/json.dart:769:7)
E/flutter ( 4801): #2 _JsonStringifier.writeJsonValue (dart:convert/json.dart:724:21)
E/flutter ( 4801): #3 _JsonStringifier.writeObject (dart:convert/json.dart:679:9)
E/flutter ( 4801): #4 _JsonStringStringifier.printOn (dart:convert/json.dart:877:17)
E/flutter ( 4801): #5 _JsonStringStringifier.stringify (dart:convert/json.dart:862:5)
E/flutter ( 4801): #6 JsonEncoder.convert (dart:convert/json.dart:262:30)
E/flutter ( 4801): #7 JsonCodec.encode (dart:convert/json.dart:172:45)
E/flutter ( 4801): #8 JsonConverter.encodeJson
E/flutter ( 4801): #9 JsonConverter.convertRequest
E/flutter ( 4801): #10 ChopperClient._encodeRequest
E/flutter ( 4801): #11 ChopperClient._handleRequestConverter
E/flutter ( 4801): #12 ChopperClient.send
E/flutter ( 4801): #13 _$PersonalPostingService.postPersonal
E/flutter ( 4801): #14 _FormState.build.<anonymous closure>.<anonymous closure>
E/flutter ( 4801): #15 _FormState.build.<anonymous closure>.<anonymous closure>
E/flutter ( 4801): #33 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:282:7)
E/flutter ( 4801): #34 _dispatchPointerDataPacket (dart:ui/hooks.dart:96:31)
E/flutter ( 4801):
Exited (1)
This is where I am calling the function the body is a MAP of string, dynamic
child: RaisedButton(
onPressed: () async {
final form = _formKey.currentState;
if (form!.validate()) {
form.save();
showNotification();
await Provider.of<PersonalPostingService>(
context,
listen: false)
.postPersonal(data);
}
},
child: Text('Save'))),
The GET requests are working fine and are easily being displayed in a listview but the POST function is not working, just for the reference below is the chopper service for POST
#Post(path: 'http://157.......:8040/personal')
Future<Response> postPersonal(
#Body() Map<String, dynamic> body,
);
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
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'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.