How to select larger or max id from database flutter - flutter

I am developing an application through which I need to display a larger id. It was previously added to the database through the following query:
Future<String> getLogin() async {
var response = await http.get(Uri.encodeFull("http://xxxxxxxxx/Noti.php"),);
setState(() {
var convertDataToJson = json.decode(response.body.toString());
data = convertDataToJson['result'];
if (data != null) {
User_ID =int.parse(data[0]['id']);
}
}
);
}
<?php
require_once 'connt.php';
$query="SELECT * FROM addcomment";
$result = mysqli_query($con,$query);
$array = array();
while ($row = mysqli_fetch_assoc($result))
{
$array[] = $row;
}
echo ($result) ?
json_encode(array("code" => 1, "result"=>$array)) :
json_encode(array("code" => 0, "message"=>"Data not found !"));
?>
Now like the example above works fine, but I need to take a higher id.
I created a php file like this:
<?php
require_once 'connt.php';
$query="SELECT MAX( id ) FROM addcomment";
$result = mysqli_query($con,$query);
$array = array();
while ($row = mysqli_fetch_assoc($result))
{
$array[] = $row;
}
echo ($result) ?
json_encode(array("code" => 1, "result"=>$array)) :
json_encode(array("code" => 0, "message"=>"Data not found !"));
?>
But I got the following problem:
E/flutter (29294): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: Invalid argument(s): The source must not be null
E/flutter (29294): #0 int.parse (dart:core-patch/integers_patch.dart:51:25)
E/flutter (29294): #1 AddCommentsState.getLogin.<anonymous closure> (package:flutter_apptestqeuriy/Ready.dart:89:22)
E/flutter (29294): #2 State.setState (package:flutter/src/widgets/framework.dart:1240:30)
E/flutter (29294): #3 AddCommentsState.getLogin (package:flutter_apptestqeuriy/Ready.dart:85:5)
E/flutter (29294): <asynchronous suspension>
E/flutter (29294): #4 AddCommentsState.initState.<anonymous closure> (package:flutter_apptestqeuriy/Ready.dart:58:9)
E/flutter (29294): #5 interval.function (package:flutter_apptestqeuriy/Ready.dart:16:9)
E/flutter (29294): #6 _rootRun (dart:async/zone.dart:1182:47)
E/flutter (29294): #7 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (29294): #8 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter (29294): #9 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter (29294): #10 _rootRun (dart:async/zone.dart:1190:13)
E/flutter (29294): #11 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (29294): #12 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1021:23)
E/flutter (29294): #13 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter (29294): #14 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19)
E/flutter (29294): #15 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5)
E/flutter (29294): #16 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter (29294):
I don't know what is the problem. But I need to display the highest id in the field. If someone knows the solution, please help me.

Replace;
$query="SELECT MAX( id ) AS max_id FROM addcomment";
And echo row[“max_id”]

Related

Flutter: Null check operator used on a null value with in_app_purchases

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

How to convert JSON response to Dart Map<String, int> object ...?

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

How to save values from query in shared_preferences with conditional statement flutter

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.

type '() => Future<List<Food>>' is not a subtype of type <List<Food>

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.

Simple GET API request in Flutter

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...