I cant Upload image as a background to a container, i have added the image in assets folder and added it to pubspec.yaml and showing me that error :
I/flutter ( 6664): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter ( 6664): The following assertion was thrown resolving an image codec:
I/flutter ( 6664): Unable to load asset: assets/images/img.png
I/flutter ( 6664):
I/flutter ( 6664): When the exception was thrown, this was the stack:
I/flutter ( 6664): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
I/flutter ( 6664): <asynchronous suspension>
I/flutter ( 6664): #1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:484:44)
I/flutter ( 6664): #2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:469:14)
I/flutter ( 6664): #3 ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:327:17)
I/flutter ( 6664): #4 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:160:22)
I/flutter ( 6664): #5 ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:325:84)
I/flutter ( 6664): (elided 13 frames from package dart:async)
I/flutter ( 6664):
I/flutter ( 6664): Image provider: AssetImage(bundle: null, name: "assets/images/img.png")
I/flutter ( 6664): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#99877(), name: "assets/images/img.png",
I/flutter ( 6664): scale: 1.0)
I/flutter ( 6664): ════════════════════════════════════════════════════════════════════════════════════════════════════
code :
body: Form(
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/img.png"),
fit: BoxFit.cover,
),
),
I have added
assets:
- assets/images/
to pubspec.yaml
the image folder
and at
assets:
- assets/images/img.png
I/flutter ( 6664): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter ( 6664): The following assertion was thrown resolving an image codec:
I/flutter ( 6664): Unable to load asset: assets/images/img.png
I/flutter ( 6664):
I/flutter ( 6664): When the exception was thrown, this was the stack:
I/flutter ( 6664): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
I/flutter ( 6664): <asynchronous suspension>
I/flutter ( 6664): #1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:484:44)
I/flutter ( 6664): #2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:469:14)
I/flutter ( 6664): #3 ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:327:17)
I/flutter ( 6664): #4 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:160:22)
I/flutter ( 6664): #5 ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:325:84)
I/flutter ( 6664): (elided 13 frames from package dart:async)
I/flutter ( 6664):
I/flutter ( 6664): Image provider: AssetImage(bundle: null, name: "assets/images/img.png")
I/flutter ( 6664): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#c1182(), name: "assets/images/img.png",
I/flutter ( 6664): scale: 1.0)
I/flutter ( 6664): ════════════════════════════════════════════════════════════════════════════════════════════════════
you need add like that
flutter:
assets:
- assets/images/img.png
In my case, I needed package property as the image was in my library project and I was running the example project.
package: [your parent directory or project name]
eg. My project name is 'flutter_demo'
AssetImage('assets/images/ic_welcome.png', package: 'flutter_demo'),
pubspect.yaml
flutter:
assets:
- assets/images/
Directory structure:
flutter_demo
-- assets
-- images
-- ic_welcome.png
I encountered this error and here's how I solved it:
First make sure the assets folder is located at the root of your project, outside the lib folder.
Check there's no slash in front of the image path string inside AssetImage().
Check the file name and path is correct in both the pubspec.yaml and AssetImage.
Always remember to save the file and hot reload after making changes.
For svg files, use the flutter_svg package.
try this:
flutter:
assets:
-android/assests/directory/
Related
I came across an error which is :
E/flutter ( 6195): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: FormatException: Invalid double
E/flutter ( 6195): "41.16568"
E/flutter ( 6195): #0 double.parse (dart:core-patch/double_patch.dart:111:28)
E/flutter ( 6195): #1 _GuessTheLocationState.build.respon.<anonymous closure> (package:geoguess/main.dart:1175:34)
E/flutter ( 6195): #2 State.setState (package:flutter/src/widgets/framework.dart:1121:30)
E/flutter ( 6195): #3 _GuessTheLocationState.build.respon (package:geoguess/main.dart:1174:11)
E/flutter ( 6195): <asynchronous suspension>
I have no idea how does it not work. Code:
//sort 5 is String that is filled with random double. Example : "3.141"
//lattDouble is double
lattDouble = double.parse(sort5);
this is my splash screen and I provide the future method to navigate automatically to another screen,
class SplashScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
Provider.of<DataBaseProvider>(context).getAllEmployees();
Future.delayed(Duration(seconds: 2)).then((value) {
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context) => ListViewEmployees()));
});
return Scaffold(
body: Container(
child: Center(
child: GestureDetector(
onTap: (){
Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (context) => ListViewEmployees()));
},
child: Text(
'Hello!' ,
style: TextStyle(
color: Colors.deepPurple ,
fontSize: 18 ,
),
),
),
),
),
);
}
}
and this is the error message
E/flutter ( 8699): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
E/flutter ( 8699): At this point the state of the widget's element tree is no longer stable.
E/flutter ( 8699): To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.
E/flutter ( 8699): #0 Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure> (package:flutter/src/widgets/framework.dart:3825:9)
E/flutter ( 8699): #1 _Closure.call (dart:core-patch/function.dart)
E/flutter ( 8699): #2 Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:3839:6)
E/flutter ( 8699): #3 Element.findAncestorStateOfType (package:flutter/src/widgets/framework.dart:3958:12)
E/flutter ( 8699): #4 Navigator.of (package:flutter/src/widgets/navigator.dart:2185:40)
E/flutter ( 8699): #5 SplashScreen.build.<anonymous closure> (package:gsg_sqlitedb/ui/splash_screen.dart:12:17)
E/flutter ( 8699): #6 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 8699): #7 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 8699): #8 _FutureListener.handleValue (dart:async/future_impl.dart:143:18)
E/flutter ( 8699): #9 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45)
E/flutter ( 8699): #10 Future._propagateToListeners (dart:async/future_impl.dart:725:32)
E/flutter ( 8699): #11 Future._complete (dart:async/future_impl.dart:519:7)
E/flutter ( 8699): #12 new Future.delayed.<anonymous closure> (dart:async/future.dart:322:16)
E/flutter ( 8699): #13 _rootRun (dart:async/zone.dart:1182:47)
E/flutter ( 8699): #14 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 8699): #15 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter ( 8699): #16 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1037:23)
E/flutter ( 8699): #17 _rootRun (dart:async/zone.dart:1190:13)
E/flutter ( 8699): #18 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 8699): #19 _CustomZone.bindCallback.<anonymous closure> (dart:async/zone.dart:1021:23)
E/flutter ( 8699): #20 Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18:15)
E/flutter ( 8699): #21 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19)
E/flutter ( 8699): #22 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5)
E/flutter ( 8699): #23 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
when I delete future delayed, and make the navigate by a button click, the error disappear
SOLVED !!!!!! here
Test breaks when using Future.delayed
The reason for this error is that you're trying to Navigate to a page while the current screen is still being rendered. Future.delayed() can be potentially used as it provides a delay while the current screen is being built. What happens when the screen being built is still not finished and Future.delayed() is that the workaround causes issues.
Another workaround is setting a fixed Timer
Timer(const Duration(seconds: 4), () {
// Navigate to next screen
});
It's still best to avoid automatically navigating to a next screen if possible.
Until a moment ago, I was working on an emulator and everything was fine.
Now I have installed the app on my Android I have an error message.
I use in http Package.
On the login page, a request is sent to sign in. An email variable and a password variable.
It was sent in the request of an HTTP package. It comes to the server for testing and return of result.
If it is positive it connects to the next page. If not it remains on the same page.
So far it has worked wonderfully.
Suddenly it does not work, why?
The Console:
E/flutter ( 5005): [ERROR:flutter/lib/ui/ui_dart_state.cc(171)] Unhandled Exception: SocketException: Insecure socket connections are disallowed by platform: almog.*******.com
E/flutter ( 5005): #0 Socket.startConnect (dart:io/socket.dart:823:9)
E/flutter ( 5005): #1 _ConnectionTarget.connect (dart:_http/http_impl.dart:2196:18)
E/flutter ( 5005): #2 _HttpClient._getConnection.connect (dart:_http/http_impl.dart:2547:12)
E/flutter ( 5005): #3 _HttpClient._getConnection (dart:_http/http_impl.dart:2552:19)
E/flutter ( 5005): #4 _HttpClient._openUrl (dart:_http/http_impl.dart:2438:12)
E/flutter ( 5005): #5 _HttpClient.openUrl (dart:_http/http_impl.dart:2323:7)
E/flutter ( 5005): #6 IOClient.send (package:http/src/io_client.dart:31:37)
E/flutter ( 5005): #7 BaseClient._sendUnstreamed (package:http/src/base_client.dart:91:38)
E/flutter ( 5005): #8 BaseClient.post (package:http/src/base_client.dart:32:7)
E/flutter ( 5005): #9 post.<anonymous closure> (package:http/http.dart:70:16)
E/flutter ( 5005): #10 _withClient (package:http/http.dart:166:20)
E/flutter ( 5005): #11 post (package:http/http.dart:69:5)
E/flutter ( 5005): #12 _LoginPageState.signIn (package:kibuiramon/service/service_log.dart:103:26)
E/flutter ( 5005): <asynchronous suspension>
E/flutter ( 5005): #13 _LoginPageState.showPrimaryButton.<anonymous closure> (package:kibuiramon/service/service_log.dart:346:15)
E/flutter ( 5005): #14 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:993:19)
E/flutter ( 5005): #15 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:1111:38)
E/flutter ( 5005): #16 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:183:24)
E/flutter ( 5005): #17 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:598:11)
E/flutter ( 5005): #18 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:287:5)
E/flutter ( 5005): #19 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:259:7)
E/flutter ( 5005): #20 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:157:27)
E/flutter ( 5005): #21 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:362:20)
E/flutter ( 5005): #22 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:338:22)
E/flutter ( 5005): #23 RendererBinding.dispatchEvent (package:flutter/src/rendering/binding.dart:267:11)
E/flutter ( 5005): #24 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:295:7)
E/flutter ( 5005): #25 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:240:7)
E/flutter ( 5005): #26 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:213:7)
E/flutter ( 5005): #27 _rootRunUnary (dart:async/zone.dart:1206:13)
E/flutter ( 5005): #28 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 5005): #29 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7)
E/flutter ( 5005): #30 _invoke1 (dart:ui/hooks.dart:265:10)
E/flutter ( 5005): #31 _dispatchPointerDataPacket (dart:ui/hooks.dart:174:5)
E/flutter ( 5005):
The permission in Manifest:
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="READ_PRIVILEGED_PHONE_STATE"/>
<uses-permission android:name="REQUEST_PHONE_CALL" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
The sign in function :
signIn(String email, pass) async {
var prefs = await SharedPreferences.getInstance();
print(email+pass);
Map data = {'email': email, 'password': pass , };
var response = await http.post("http://************.com?do=check_user",body: data);
if (response.statusCode == 200) {
List<dynamic> jsonResponse = json.decode(response.body);
if (jsonResponse[0]['error'] == 'true')
{
ErrorConnect = true;
setState(() {
_isLoading = false;
});
}else{ErrorConnect = false;}
if(ErrorConnect == false) {
id = jsonResponse[0]['id'];
log = jsonResponse[0]['log_in'];
banned = jsonResponse[0]['banned'];
prefs.setString("id", id);
prefs.setString("log_in", log);
prefs.setString("banned", banned);
prefs.setString('email', jsonResponse[0]['email']);
if (banned == '1') {
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(builder: (BuildContext context) => NotFound()),
(Route<dynamic> route) => false);
} else {
Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(builder: (BuildContext context) => RoutePage()),
(Route<dynamic> route) => false);
}
} else {
setState(() {
_isLoading = false;
});
}
}
}
EDIT
Now its work !
I needed to convert the url from http to https .
simple..
you need to convert http: to https:
it will work like a charm..
If you can't convert http to https, you can enable cleartextTraffic.
Android:
Create a file res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">your-http-domain.com</domain>
</domain-config>
</network-security-config>
After that, add this to your AndroidManifest:
</application>
...
<meta-data android:name="io.flutter.network-policy"
android:resource="#xml/network_security_config"/>
</application>
For testing purposes I would like to disable encryption so that I can connect my Flutter app to a server running on my localhost using http, not https. I've already been able to do it with https, but I get a crash for http because both Android and iOS do not allow plain text requests by default.
Here is my error:
E/flutter ( 9119): [ERROR:flutter/shell/common/shell.cc(186)] Dart Error: Unhandled exception:
E/flutter ( 9119): SocketException: OS Error: Connection refused, errno = 111, address = 10.0.2.2, port = 40738
E/flutter ( 9119): #0 IOClient.send (package:http/src/io_client.dart:33:23)
E/flutter ( 9119): <asynchronous suspension>
E/flutter ( 9119): #1 BaseClient._sendUnstreamed (package:http/src/base_client.dart:169:38)
E/flutter ( 9119): <asynchronous suspension>
E/flutter ( 9119): #2 BaseClient.get (package:http/src/base_client.dart:32:7)
E/flutter ( 9119): #3 get.<anonymous closure> (package:http/http.dart:46:36)
E/flutter ( 9119): #4 _withClient (package:http/http.dart:166:20)
E/flutter ( 9119): <asynchronous suspension>
E/flutter ( 9119): #5 get (package:http/http.dart:46:5)
E/flutter ( 9119): #6 _makeGetRequest (package:flutter_client/main.dart:64:29)
E/flutter ( 9119): <asynchronous suspension>
E/flutter ( 9119): #7 BodyWidgetState.build.<anonymous closure> (package:flutter_client/main.dart:48:19)
E/flutter ( 9119): #8 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:507:14)
E/flutter ( 9119): #9 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:562:30)
E/flutter ( 9119): #10 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
E/flutter ( 9119): #11 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
E/flutter ( 9119): #12 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:175:7)
E/flutter ( 9119): #13 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:315:9)
E/flutter ( 9119): #14 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
E/flutter ( 9119): #15 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
E/flutter ( 9119): #16 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:180:19)
E/flutter ( 9119): #17 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:158:22)
E/flutter ( 9119): #18 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:138:7)
E/flutter ( 9119): #19 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
E/flutter ( 9119): #20 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
E/flutter ( 9119): #21 _invoke1 (dart:ui/hooks.dart:173:13)
E/flutter ( 9119): #22 _dispatchPointerDataPacket (dart:ui/hooks.dart:127:5)
In Android I can disable encryption by adding a setting to the manifest:
android:usesCleartextTraffic="true"
In iOS I can do the same by adding a setting to Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
But I don't know how to do that in Flutter.
Supplemental code
Flutter main.dart
import 'package:flutter/material.dart';
import 'package:http/http.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Node server demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(title: Text('Flutter Client')),
body: BodyWidget(),
),
);
}
}
class BodyWidget extends StatefulWidget {
#override
BodyWidgetState createState() {
return new BodyWidgetState();
}
}
class BodyWidgetState extends State<BodyWidget> {
String serverResponse = 'Server response';
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(32.0),
child: Align(
alignment: Alignment.topCenter,
child: SizedBox(
width: 200,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
RaisedButton(
child: Text('Send request to server'),
onPressed: () {
_makeGetRequest();
},
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(serverResponse),
),
],
),
),
),
);
}
}
_makeGetRequest() async {
Response response = await get('http://10.0.2.2:3000');
int statusCode = response.statusCode;
Map<String, String> headers = response.headers;
String contentType = headers['content-type'];
String json = response.body;
print(statusCode);
print(headers);
print(contentType);
print(json);
}
Flutter pubspec.yaml
name: flutter_client
description: Flutter client to test Node.js server
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
http: ^0.12.0+1
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
Node.js app.js
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Testing with Android 9 emulator (API 28).
Update 1:
I tried adding android:usesCleartextTraffic="true" to the Android manifest in Flutter, but that didn't prevent the Dart error.
Update 2:
I was using https in my code rather than http. I updated that above and also changed to the new error message.
Update 3
Hmm, Flutter had an update (1.2.2) and I upgraded. Then I restarted Android Studio. And now it is working without any errors just with the code above. I don't know what was causing the exception. Could it be that Flutter doesn't require https?
create a new httpclient and disable certificate checking
HttpClient httpClient = new HttpClient()
..badCertificateCallback =
((X509Certificate cert, String host, int port) => true);
IOClient ioClient = new IOClient(httpClient);
ioClient.get(url);
i am trying to read all the characteristics from all services from a device with the plugin https://github.com/pauldemarco/flutter_blue but it is throwing me this error:
[ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (24425): PlatformException(read_characteristic_error, unknown reason, may occur if readCharacteristic was called before last read finished., null)
E/flutter (24425): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:547:7)
E/flutter (24425): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:279:18)
E/flutter (24425): <asynchronous suspension>
E/flutter (24425): #2 BluetoothDevice.readCharacteristic (file:///C:/Users/Downloads/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_blue-0.3.3/lib/src/bluetooth_device.dart:56:10)
E/flutter (24425): <asynchronous suspension>
E/flutter (24425): #3 _ListTabState._connectToDevice._readCarachteristics (file:///C:/Users/AndroidStudioProjects/my_app/lib/tab_base.dart:125:49)
E/flutter (24425): <asynchronous suspension>
E/flutter (24425): #4 _ListTabState._connectToDevice._showServices (file:///C:/Users/AndroidStudioProjects/my_app/lib/tab_base.dart:157:27)
E/flutter (24425): <asynchronous suspension>
E/flutter (24425): #5 _ListTabState._connectToDevice._connect.<anonymous closure> (file:///C:/Users/AndroidStudioProjects/my_app/lib/tab_base.dart:197:24)
E/flutter (24425): #6 _RootZone.runUnaryGuarded (dart:async/zone.dart:1316:10)
E/flutter (24425): #7 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:330:11)
E/flutter (24425): #8 _DelayedData.perform (dart:async/stream_impl.dart:578:14)
E/flutter (24425): #9 _StreamImplEvents.handleNext (dart:async/stream_impl.dart:694:11)
E/flutter (24425): #10 _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:654:7)
E/flutter (24425): #11 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (24425): #12 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
Here is the code i am using:
_readCarachteristics(services) async {
for (BluetoothService service in services){
_characteristics = service.characteristics;
for (BluetoothCharacteristic characteristic in _characteristics) {
final List<int> value = await _device.readCharacteristic(characteristic);
}
}
_services = await device.discoverServices();
_readCarachteristics(_services);
I read this issue: https://github.com/pauldemarco/flutter_blue/issues/57 but could'nt manage to solve it. Thanks for your support.
UPDATED
It seems that there are specific characteristics sent by the beacon that are composed in a special way that is breaking the readCharacteristic method. They are supposed to contain two subtypes of uuid that are not been read by the readDescriptor function.
There are three services out of which the third one should be used to read and write characteristic.The first two are generic and the third one is custom service using which it will work. Try this :
_scanResult.device.discoverServices().then((services){
services[2].characteristics[0].read();
});