I get the following errors. I am using chopper flutter library and providers. I haven't used providers much. I am sending dummy data but on the form button click.
I/flutter (28363): Observatory listening on ************************************
E/flutter (28363): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Converting object to an encodable object failed: Instance of 'DateTime'
E/flutter (28363): #0 _JsonStringifier.writeObject (dart:convert/json.dart:688:7)
E/flutter (28363): #1 _JsonStringifier.writeMap (dart:convert/json.dart:769:7)
E/flutter (28363): #2 _JsonStringifier.writeJsonValue (dart:convert/json.dart:724:21)
E/flutter (28363): #3 _JsonStringifier.writeObject (dart:convert/json.dart:679:9)
E/flutter (28363): #4 _JsonStringStringifier.printOn (dart:convert/json.dart:877:17)
E/flutter (28363): #5 _JsonStringStringifier.stringify (dart:convert/json.dart:862:5)
E/flutter (28363): #6 JsonEncoder.convert (dart:convert/json.dart:262:30)
E/flutter (28363): #7 JsonCodec.encode (dart:convert/json.dart:172:45)
E/flutter (28363): #8 JsonConverter.encodeJson
E/flutter (28363): #9 JsonConverter.convertRequest
E/flutter (28363): #10 ChopperClient._encodeRequest
E/flutter (28363): #11 ChopperClient._handleRequestConverter
E/flutter (28363): #12 ChopperClient.send
E/flutter (28363): #13 _$PersonalPostingService.postPersonal
E/flutter (28363): #14 _FormState.build.<anonymous closure>.<anonymous closure>
E/flutter (28363): #15 _FormState.build.<anonymous closure>.<anonymous closure>
E/flutter (28363): #16 _InkResponseState._handleTap
E/flutter (28363): #17 GestureRecognizer.invokeCallback
E/flutter (28363): #18 TapGestureRecognizer.handleTapUp
E/flutter (28363): #19 BaseTapGestureRecognizer._checkUp
E/flutter (28363): #20 BaseTapGestureRecognizer.acceptGesture
E/flutter (28363): #21 GestureArenaManager.sweep
E/flutter (28363): #22 GestureBinding.handleEvent
E/flutter (28363): #23 GestureBinding.dispatchEvent
E/flutter (28363): #24 RendererBinding.dispatchEvent
E/flutter (28363): #25 GestureBinding._handlePointerEventImmediately
E/flutter (28363): #26 GestureBinding.handlePointerEvent
E/flutter (28363): #27 GestureBinding._flushPointerEventQueue
E/flutter (28363): #28 GestureBinding._handlePointerDataPacket
E/flutter (28363): #29 _rootRunUnary (dart:async/zone.dart:1370:13)
E/flutter (28363): #30 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter (28363): #31 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1170:7)
E/flutter (28363): #32 _invoke1 (dart:ui/hooks.dart:182:10)
E/flutter (28363): #33 PlatformDispatcher._dispatchPointerDataPacket (dart:ui/platform_dispatcher.dart:282:7)
E/flutter (28363): #34 _dispatchPointerDataPacket (dart:ui/hooks.dart:96:31)
E/flutter (28363):
Exited (1)
The following is my onPressed() method of the button
The form is just useless sitting there I am using hardcoded values in a map from another class
child: RaisedButton(
onPressed: () async {
final form = _formKey.currentState;
if (form!.validate()) {
form.save();
//_user.makePostRequest();
showNotification();
await Provider.of<PersonalPostingService>(
context,
listen: false)
.postPersonal(_user.data);
}
},
child: Text('Save'))),
Related
My code:
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:multi_select_flutter/multi_select_flutter.dart';
import 'package:shared_preferences/shared_preferences.dart';
class Item {
final int id;
final String name;
Item({
this.id,
this.name,
});
Item.fromJson(Map<String, dynamic> json)
: id = json['i'],
name = json['n'];
Map<String, dynamic> toJson() {
return {
'i' : id,
'n' : name,
};
}
}
class ProfileScreen extends StatefulWidget {
#override
_ProfileScreenState createState() => _ProfileScreenState();
}
class _ProfileScreenState extends State<ProfileScreen> {
List<Item> selectedDogSizes = [];
#override
void initState() {
getData("dogSizes");
}
getData(String key) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var myList;
setState(() {
myList = prefs.getString(key);
});
selectedDogSizes = jsonDecode(myList) ?? [];
}
setData(List<Item> items, String key) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var myList = jsonEncode(items);
prefs.setString(key, myList);
}
List<Item> dogSizes = [
Item(id: 1, name: "Small"),
Item(id: 2, name: "Medium"),
Item(id: 3, name: "Big"),
];
#override
Widget build(BuildContext context) {
return ListView(
children: [
MultiSelectChipField<Item>(
items: dogSizes
.map((item) => MultiSelectItem<Item>(item, item.name))
.toList(),
initialValue: selectedDogSizes,
icon: Icon(Icons.check),
onTap: (values) {
selectedDogSizes = values;
setData(selectedDogSizes, "dogSizes");
},
),
],
);
}
}
I'm trying to store if user chose one of the option. To do it I used a list of object 'Items' and everytime the list of chosen elements were changed I tried to encode the list and store it.
E/flutter (10651): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: type 'List<dynamic>' is not a subtype of type 'List<Item>'
E/flutter (10651): #0 _ProfileScreenState.getData (package:woofdates/screens/profileScreen.dart:47:5)
E/flutter (10651): <asynchronous suspension>
E/flutter (10651): #1 _ProfileScreenState.initState (package:woofdates/screens/profileScreen.dart:38:5)
E/flutter (10651): #2 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4765:58)
E/flutter (10651): #3 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
E/flutter (10651): #4 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter (10651): #5 Element.updateChild (package:flutter/src/widgets/framework.dart:3324:20)
E/flutter (10651): #6 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (10651): #7 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (10651): #8 StatelessElement.update (package:flutter/src/widgets/framework.dart:4708:5)
E/flutter (10651): #9 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #10 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (10651): #11 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (10651): #12 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5)
E/flutter (10651): #13 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #14 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (10651): #15 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (10651): #16 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5)
E/flutter (10651): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #18 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5647:32)
E/flutter (10651): #19 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6246:17)
E/flutter (10651): #20 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #21 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (10651): #22 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
E/flutter (10651): #23 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (10651): #24 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
E/flutter (10651): #25 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #26 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (10651): #27 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (10651): #28 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5)
E/flutter (10651): #29 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #30 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (10651): #31 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
E/flutter (10651): #32 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (10651): #33 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
E/flutter (10651): #34 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #35 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14)
E/flutter (10651): #36 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #37 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (10651): #38 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (10651): #39 StatelessElement.update (package:flutter/src/widgets/framework.dart:4708:5)
E/flutter (10651): #40 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #41 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6125:14)
E/flutter (10651): #42 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #43 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (10651): #44 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
E/flutter (10651): #45 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (10651): #46 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
E/flutter (10651): #47 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #48 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (10651): #49 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
E/flutter (10651): #50 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (10651): #51 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
E/flutter (10651): #52 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #53 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (10651): #54 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (10651): #55 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5)
E/flutter (10651): #56 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #57 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (10651): #58 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (10651): #59 ProxyElement.update (package:flutter/src/widgets/framework.dart:4987:5)
E/flutter (10651): #60 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #61 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (10651): #62 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
E/flutter (10651): #63 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (10651): #64 StatefulElement.update (package:flutter/src/widgets/framework.dart:4832:5)
E/flutter (10651): #65 Element.updateChild (package:flutter/src/widgets/framework.dart:3314:15)
E/flutter (10651): #66 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter (10651): #67 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
E/flutter (10651): #68 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter (10651): #69 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2730:33)
E/flutter (10651): #70 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:913:20)
E/flutter (10651): #71 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:302:5)
E/flutter (10651): #72 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
E/flutter (10651): #73 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1055:9)
E/flutter (10651): #74 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:971:5)
E/flutter (10651): #75 _rootRun (dart:async/zone.dart:1190:13)
E/flutter (10651): #76 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (10651): #77 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter (10651): #78 _invoke (dart:ui/hooks.dart:251:10)
E/flutter (10651): #79 _drawFrame (dart:ui/hooks.dart:209:3)
E/flutter (10651):
I also tried using package json_serializable with results of the same errors.
I could also just make it a list of integers of id's and then encode it to json, but I don't know how to get integers from multiple objects either.
Decode it like this:
getData(String key) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
var myList;
setState(() {
myList = prefs.getString(key);
});
var decodedString= jsonDecode(myList) ?? [];
selectedDogSizes = (decodedString as List).map((i) => Item.fromJson(i)).toList();
}
Then:
onTap: (values) {
selectedDogSizes = values;
setData(selectedDogSizes, "dogSizes");
getData("dogSizes");
setState((){});
},
when i try to make a simple select with mysql1 dart library, the app throws this exception:
E/flutter (11252): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: Invalid argument(s): Illegal length 0
E/flutter (11252): #0 _NativeSocket.read (dart:io-patch/socket_patch.dart:819:7)
E/flutter (11252): #1 _RawSocket.read (dart:io-patch/socket_patch.dart:1614:22)
E/flutter (11252): #2 Buffer.readFromSocket (package:mysql1/src/buffer.dart:48:30)
E/flutter (11252): #3 BufferedSocket._readBuffer (package:mysql1/src/buffered_socket.dart:178:36)
E/flutter (11252): #4 BufferedSocket._onData (package:mysql1/src/buffered_socket.dart:93:9)
E/flutter (11252): #5 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter (11252): #6 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter (11252): #7 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter (11252): #8 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:357:11)
E/flutter (11252): #9 _BufferingStreamSubscription._add (dart:async/stream_impl.dart:285:7)
E/flutter (11252): #10 _SyncStreamControllerDispatch._sendData (dart:async/stream_controller.dart:808:19)
E/flutter (11252): #11 _StreamController._add (dart:async/stream_controller.dart:682:7)
E/flutter (11252): #12 _StreamController.add (dart:async/stream_controller.dart:624:5)
E/flutter (11252): #13 new _RawSocket.<anonymous closure> (dart:io-patch/socket_patch.dart:1556:33)
E/flutter (11252): #14 _NativeSocket.issueReadEvent.issue (dart:io-patch/socket_patch.dart:1052:14)
E/flutter (11252): #15 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (11252): #16 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
E/flutter (11252):
this is the function that makes the query (I call that function in a FutureBuilder in flutter):
Future<bool> askPlacaTurno(String idServicio)async{
var conexion = await conectarse();
var res = await conexion.query("select placa from servicios where id = ?", [idServicio]);
bool usaPlaca = false;
for(var row in res){
usaPlaca = row[0] == 'on' ? true : false;
}
return usaPlaca;
}
EDITED
the connection and close connection functions, here is the problem, i've tried to make a connection without execute any query and throws the same exception:
Future conectarse() async{
final conexion = await MySqlConnection.connect(ConnectionSettings(
host: "192.168.0.18",
port: 3306,
user: "root",
password: '',
db: "gobernacion"
)
);
print("conectado a la base de datos");
return conexion;
}
Future desconectarse(MySqlConnection conexion) async{
await conexion.close();
}
So I am trying to add the Google Places API inside the code of my application, but I am getting these errors:
E/flutter (18565): #4 _rootRun (dart:async/zone.dart:1122:38)
E/flutter (18565): #5 _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (18565): #6 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
E/flutter (18565): #7 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:965:23)
E/flutter (18565): #8 _rootRun (dart:async/zone.dart:1126:13)
E/flutter (18565): #9 _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter (18565): #10 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:949:23)
E/flutter (18565): #11 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:23:15)
E/flutter (18565): #12 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:384:19)
E/flutter (18565): #13 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:418:5)
E/flutter (18565): #14 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
Some of my code:
Future<void> fetchAddress() async {
Prediction prediction =
await PlacesAutocomplete.show(
context: context,
onError: onError,
apiKey: 'dummy',
mode: Mode.fullscreen, // Mode.overlay
language: "en");
setState(() {
selectedAddress1 = prediction.description;
});
}
I am trying to integrate stripe payment in my Flutter project with backend Laravel. For some reason I am getting error at json.decode.
E/flutter (10999): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)]
Unhandled Exception: FormatException: Unexpected character (at
character 1) E/flutter (10999): <!doctype html>
FlatButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(7.0)),
color: Colors.redAccent,
onPressed: () {
var payment = Payment();
payment.name = _cardHolderName.text;
payment.email = _cardHolderEmail.text;
payment.cardNumber = _cardNumber.text;
payment.expiryMonth = _expiryMonth.text;
payment.expiryYear = _expiryYear.text;
payment.cvcNumber = _cvcNumber.text;
_makePayment(context, payment);
},
child: Text('Make Payment',
style: TextStyle(color: Colors.white)),
),
void _makePayment(BuildContext context, Payment payment) async {
PaymentService _paymentService = PaymentService();
var paymentData = await _paymentService.makePayment(payment);
var result = json.decode(paymentData.body);
if (result['result'] == true) {
CartService _cartService = CartService();
this.widget.cartItems.forEach((cartItem){
_cartService.deleteCartItemById(cartItem.productId);
});
_showPaymentSuccessMessage(context);
Timer(Duration(seconds: 2), () {
Navigator.pop(context);
Navigator.push(
context, MaterialPageRoute(builder: (context) => HomeScreen()));
});
}
}
Payment Service
class PaymentService {
Repository _repository;
PaymentService(){
_repository = Repository();
}
makePayment(Payment payment) async {
return await _repository.httpPost('make-payment', payment.toJson());
}
}
Laravel Code
public function makePayment(Request $request)
{
\Stripe\Stripe::setApiKey('sk_test_7422pw1lMsdRfN2FaPmfFKlt00AtiIJD9O');
$token = Token::create([
'card'=>[
'number'=>$request-input('cardNumber'),
'exp_month'=>$request-input('expiryMonth'),
'exp_year'=>$request-input('expiryYear'),
'cvc'=>$request-input('cvcNumber')
]
]);
\Stripe\PaymentIntent::create([
'amount' => 1000,
'currency' => 'inr',
'source' => $token,
'receipt_email' => $request->input('email'),
]);
}
Error
E/flutter (10999): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: FormatException: Unexpected character (at character 1)
E/flutter (10999): <!doctype html>
E/flutter (10999): ^
E/flutter (10999):
E/flutter (10999): #0 _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1394:5)
E/flutter (10999): #1 _ChunkedJsonParser.parseNumber (dart:convert-patch/convert_patch.dart:1261:9)
E/flutter (10999): #2 _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:926:22)
E/flutter (10999): #3 _parseJson (dart:convert-patch/convert_patch.dart:31:10)
E/flutter (10999): #4 JsonDecoder.convert (dart:convert/json.dart:495:36)
E/flutter (10999): #5 JsonCodec.decode (dart:convert/json.dart:153:41)
E/flutter (10999): #6 _PaymentScreenState._makePayment (package:factory2homes/screens/payment_screen.dart:160:23)
E/flutter (10999): <asynchronous suspension>
E/flutter (10999): #7 _PaymentScreenState.build.<anonymous closure> (package:factory2homes/screens/payment_screen.dart:142:23)
E/flutter (10999): #8 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:706:14)
E/flutter (10999): #9 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:789:36)
E/flutter (10999): #10 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (10999): #11 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:486:11)
E/flutter (10999): #12 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:264:5)
E/flutter (10999): #13 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:236:7)
E/flutter (10999): #14 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter (10999): #15 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:222:20)
E/flutter (10999): #16 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:198:22)
E/flutter (10999): #17 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
E/flutter (10999): #18 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
E/flutter (10999): #19 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
E/flutter (10999): #20 _rootRunUnary (dart:async/zone.dart:1138:13)
E/flutter (10999): #21 _CustomZone.runUnary (dart:async/zone.dart:1031:19)
E/flutter (10999): #22 _CustomZone.runUnaryGuarded (dart:async/zone.dart:933:7)
E/flutter (10999): #23 _invoke1 (dart:ui/hooks.dart:273:10)
E/flutter (10999): #24 _dispatchPointerDataPacket (dart:ui/hooks.dart:182:5)
E/flutter (10999):
This error happens when the server return an html body or some error occurred on the server side while handling your request. Try to use debugger and watch the response of the request to see if response status is 200 and also check the response body to see what the server is sending for your request.
Also try to wrap you jsonDecode inside try-catch to handle future exceptions.
I'm trying to fetch nearby places in my app, but there is some error.
If there is same topic please notice me
I'm looking forward for your advice
void _searchNearby(double latitude, double longitude) async {
setState(() {
markers.clear();
});
String url =
'${googlePlaceURL}/json?location=${latitude},${longitude}&radius=1500&type=${placeType}&key=${mapAPI}';
print(url);
http.Response response = await http.get(url);
print('********'+'$response');
if (response.statusCode == 200) {
final data = json.decode(response.body);
print(data);
} else {
throw Exception('An error occurred getting places nearby');
}
}
Error:
I/flutter (10208): https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.4219983,-122.084&radius=1500&type=subway_station&key=AIzaSyAjclu-U5mgWji4rENX0LxvrfYXljfK5pg
E/flutter (10208): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: FormatException: Scheme not starting with alphabetic character (at character 1)
E/flutter (10208): https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=37.4...
E/flutter (10208): ^
E/flutter (10208):
E/flutter (10208): #0 _Uri._fail (dart:core/uri.dart:1623:5)
E/flutter (10208): #1 _Uri._makeScheme (dart:core/uri.dart:2184:7)
E/flutter (10208): #2 new _Uri.notSimple (dart:core/uri.dart:1465:18)
E/flutter (10208): #3 Uri.parse (dart:core/uri.dart:1022:17)
E/flutter (10208): #4 BaseClient._sendUnstreamed (package:http/src/base_client.dart:152:34)
E/flutter (10208): <asynchronous suspension>
E/flutter (10208): #5 BaseClient.get (package:http/src/base_client.dart:32:7)
E/flutter (10208): #6 get.<anonymous closure> (package:http/http.dart:46:36)
E/flutter (10208): #7 _withClient (package:http/http.dart:166:20)
E/flutter (10208): <asynchronous suspension>
E/flutter (10208): #8 get (package:http/http.dart:46:5)
E/flutter (10208): #9 MapSampleState._searchNearby (package:flutter_course/Map/map.dart:44:36)
E/flutter (10208): <asynchronous suspension>
E/flutter (10208): #10 MapSampleState.build.<anonymous closure> (package:flutter_course/Map/map.dart:119:11)
It looks like the variable googlePlaceURL start with space. Check it out, I think you can solve it in an easy way.