Passing data/message from flutter apps to other apps - dart

i am trying to pass data from my flutter app to other apps. The purpose is to send the download link for my app to another app(say watsapp,facebook,twitter etc.).
I am using flutter plugin share 0.6.0+1. i added the package as instructed. But when i ran the program, the following error was displayed:
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method share on channel plugins.flutter.io/share)
E/flutter ( 8153): #0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:300:7)
E/flutter ( 8153): <asynchronous suspension>
E/flutter ( 8153): #1 Share.share (package:share/share.dart:44:20)
E/flutter ( 8153): #2 _MyHomePageState.build.<anonymous closure> (package:unit_converter/main.dart:409:34)
E/flutter ( 8153): #3 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:513:14)
E/flutter ( 8153): #4 _InkResponseState.build.<anonymous closure> (package:flutter/src/material/ink_well.dart:568:30)
E/flutter ( 8153): #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:120:24)
E/flutter ( 8153): #6 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:242:9)
E/flutter ( 8153): #7 TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:204:7)
E/flutter ( 8153): #8 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter ( 8153): #9 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:218:20)
E/flutter ( 8153): #10 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:192:22)
E/flutter ( 8153): #11 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:149:7)
E/flutter ( 8153): #12 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:101:7)
E/flutter ( 8153): #13 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:85:7)
E/flutter ( 8153): #14 _rootRunUnary (dart:async/zone.dart:1136:13)
E/flutter ( 8153): #15 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
E/flutter ( 8153): #16 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
E/flutter ( 8153): #17 _invoke1 (dart:ui/hooks.dart:223:10)
E/flutter ( 8153): #18 _dispatchPointerDataPacket (dart:ui/hooks.dart:144:5)
The following is the content of my pubspec.yaml file:
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dart2_constant: ^1.0.2+dart2
math_expressions: ^1.0.0
shared_preferences: ^0.4.3
#loader_search_bar: ^1.0.3+1
material_search: ^0.2.8
path_provider: '>=0.3.0'
sqflite: any
flutter_colorpicker: ^0.2.1
intl: ^0.15.7
auto_size_text: ^0.3.0
cloud_firestore: ^0.9.0
animated_text_kit: ^1.3.0
share: ^0.6.0+1
The following is my implementation:
Share.share('Hi, take a time to click and download this app: market://search?q=pname:com.myappbase.appname');
Please can anyone point me to what i am doing wrong. i seem to have tried ieverything but these same errors have been coming up.Or is there a more elegant way this can be done? Thanks

You must terminate the app and rerun it from scratch as share dependency required platform channel methods to be called. the app has to terminate and rerun from scratch.

Related

Flutter: Issue when opening 10.000 files: StackOverflow

I just generated 10000 files in the Flutter app project in VSC:
{placeholder0, placeholder1 ..., placeholder10000}
Each file contains simple widget returning next Placeholder, like Placeholder0 widget returns Placeholder1 widget and so on.. where Placeholder10000 returns just Text('test').
(What I also noticed VSC behaviour is getting strange once so much files is placed inside the project, like Dart Analyzer is super lagging. I could not fint any info about number of files limitations within the project). Actually is it possible to run the project with such of big number of files inside it?
Once I put Placeholder0 widget in the body of my HomePage try to run the app on simulator (iOS Simulator) i got following StackOverFlow error:
The relevant error-causing widget was
Placeholder453
lib/placeholders/placeholder452.dart:9
When the exception was thrown, this was the stack
#0 _HashBase._isDeleted (dart:collection-patch/compact_hash.dart:198:3)
#1 _LinkedHashMapMixin._init (dart:collection-patch/compact_hash.dart:429:24)
#2 _LinkedHashMapMixin._rehash (dart:collection-patch/compact_hash.dart:399:7)
#3 _LinkedHashMapMixin._insert (dart:collection-patch/compact_hash.dart:456:7)
#4 _LinkedHashMapMixin._set (dart:collection-patch/compact_hash.dart:511:7)
#5 _LinkedHashMapMixin.[]= (dart:collection-patch/compact_hash.dart:499:5)
#6 MapMixin.addAll.<anonymous closure> (dart:collection/maps.dart:129:11)
#7 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:617:13)
#8 MapMixin.addAll (dart:collection/maps.dart:128:11)
#9 _InternalLinkedHashMap.addAll (dart:collection-patch/compact_hash.dart:301:11)
#10 DiagnosticsNode.toJsonMap.<anonymous closure>
package:flutter/…/foundation/diagnostics.dart:1646
#11 DiagnosticsNode.toJsonMap
package:flutter/…/foundation/diagnostics.dart:1661
#12 DiagnosticsProperty.toJsonMap
package:flutter/…/foundation/diagnostics.dart:2666
#13 DiagnosticsNode.toJsonList.<anonymous closure>
package:flutter/…/foundation/diagnostics.dart:1686
#14 MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31)
#15 ListIterator.moveNext (dart:_internal/iterable.dart:342:26)
#16 new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
#17 new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#18 new List.of (dart:core-patch/array_patch.dart:51:28)
#19 ListIterable.toList (dart:_internal/iterable.dart:213:44)
#20 DiagnosticsNode.toJsonList
package:flutter/…/foundation/diagnostics.dart:1687
#21 DiagnosticsNode.toJsonMap.<anonymous closure>
package:flutter/…/foundation/diagnostics.dart:1648
#22 DiagnosticsNode.toJsonMap
package:flutter/…/foundation/diagnostics.dart:1661
#23 DiagnosticsNode.toJsonList.<anonymous closure>
package:flutter/…/foundation/diagnostics.dart:1686
#24 MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31)
#25 ListIterator.moveNext (dart:_internal/iterable.dart:342:26)
#26 new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
#27 new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#28 new List.of (dart:core-patch/array_patch.dart:51:28)
#29 ListIterable.toList (dart:_internal/iterable.dart:213:44)
#30 DiagnosticsNode.toJsonList
package:flutter/…/foundation/diagnostics.dart:1687
#31 DiagnosticsNode.toJsonMap.<anonymous closure>
package:flutter/…/foundation/diagnostics.dart:1648
#32 DiagnosticsNode.toJsonMap
package:flutter/…/foundation/diagnostics.dart:1661
#33 WidgetInspectorService._nodeToJson
package:flutter/…/widgets/widget_inspector.dart:1606
#34 WidgetInspectorService._reportStructuredError
package:flutter/…/widgets/widget_inspector.dart:937
#35 FlutterError.reportError
package:flutter/…/foundation/assertions.dart:1184
#36 _debugReportException
package:flutter/…/widgets/framework.dart:6493
#37 ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4908
#38 Element.rebuild
package:flutter/…/widgets/framework.dart:4604
#39 ComponentElement._firstBuild
package:flutter/…/widgets/framework.dart:4859
#40 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4853
#41 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3863
#42 Element.updateChild
package:flutter/…/widgets/framework.dart:3592
2
...
#4116 Element.rebuild
package:flutter/…/widgets/framework.dart:4604
#4117 ComponentElement._firstBuild
package:flutter/…/widgets/framework.dart:4859
#4118 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:5041
#4119 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4853
... Normal element mounting (27 frames)

Sending self sms from iPhone via flutter

I'm using the flutter_otp plugin for SMS.
It works fine on Android but I get this error on iPhone.
I tried different format for phone number but still the same error.
<asynchronous suspension>
#1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:334:12)
#2 EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:542:29)
#3 EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:528:64)
#8 new SmsSender._private (package:sms/sms.dart:313:44)
#9 new SmsSender (package:sms/sms.dart:307:23)
#10 FlutterOtp.sendOtp (package:flutter_otp/flutter_otp.dart:37:28)
#11 SignUpViewModel.sendOTP (package:checkin/backend/viewModels/signup_view_model.dart:122:17)
#12 SignUpView.build.<anonymous closure>.<anonymous closure> (package:checkin/backend/views/signup_view.dart:93:39)
#13 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:184:24)
#14 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:524:11)
#15 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:284:5)
#16 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:256:7)
#17 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:158:27)
#18 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:224:20)
#19 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:200:22)
#20 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:158:7)
#21 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:104:7)
#22 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:88:7)
#26 _invoke1 (dart:ui/hooks.dart:267:10)
#27 _dispatchPointerDataPacket (dart:ui/hooks.dart:176:5)
(elided 7 frames from dart:async)
═════════════════════════════════════════════════════════════════════════════

No implementation found for method getAndroidDeviceInfo

i am trying to run this example in the plugin page
and i get this error
I/flutter ( 3273): MissingPluginException(No implementation found for method getAndroidDeviceInfo on channel plugins.flutter.io/device_info)
I/flutter ( 3273): #0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:153:7)
I/flutter ( 3273): <asynchronous suspension>
I/flutter ( 3273): #1 DeviceInfoPlugin.androidInfo (package:device_info/device_info.dart:25:35)
I/flutter ( 3273): <asynchronous suspension>
I/flutter ( 3273): #2 _MyAppState.initPlatformState (/data/user/0/com.yourcompany.demos/cache/demosSWKRJL/demos/lib/main.dart:37:67)
I/flutter ( 3273): <asynchronous suspension>
I/flutter ( 3273): #3 _MyAppState.initState (/data/user/0/com.yourcompany.demos/cache/demosSWKRJL/demos/lib/main.dart:29:5)
I/flutter ( 3273): #4 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3734:58)
I/flutter ( 3273): #5 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3600:5)
I/flutter ( 3273): #6 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2890:14)
I/flutter ( 3273): #7 Element.updateChild (package:flutter/src/widgets/framework.dart:2693:12)
I/flutter ( 3273): #8 RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:852:16)
I/flutter ( 3273): #9 RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:823:5)
I/flutter ( 3273): #10 RenderObje
this isn't a bug
and it isn't about platform specific coding as #challenget answered
you just need to re-build and run the app again for flutter-plugin to be added and work correctly.
hot-restart won't work
:hearts [this is a feature-request btw]
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
if (Platform.isAndroid) {
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
} else if (Platform.isIOS) {
IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
}
You need to judge the device.
follow this 4 steps it will work
flutter clean
flutter pub get
flutter clean
flutter run
follow these 4 steps it will work
flutter clean
flutter pub get
flutter clean
flutter run
or
Stop the app and restart the build. This worked for me.
Stop the app and restart the build. This worked for me.

Flutter : Mongo Dart Plugin is not working

i want to use mongo to store my app data, but when ever i try to await db.open() this error appear on the console:
[ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (11408): type 'Future<dynamic>' is not a subtype of type 'Future<bool>' where
E/flutter (11408): Future is from dart:async
E/flutter (11408): Future is from dart:async
E/flutter (11408): bool is from dart:core
E/flutter (11408):
E/flutter (11408): #0 _Connection.connect (file:///C:/Users/Picmix/flutter/.pub-cache/hosted/pub.dartlang.org/mongo_dart-0.3.1/lib/src/network/connection.dart:73:22)
E/flutter (11408): #1 _ConnectionManager._connect (file:///C:/Users/Picmix/flutter/.pub-cache/hosted/pub.dartlang.org/mongo_dart-0.3.1/lib/src/network/connection_manager.dart:23:22)
E/flutter (11408): <asynchronous suspension>
E/flutter (11408): #2 _ConnectionManager.open.<anonymous closure> (file:///C:/Users/Picmix/flutter/.pub-cache/hosted/pub.dartlang.org/mongo_dart-0.3.1/lib/src/network/connection_manager.dart:58:14)
E/flutter (11408): #3 Future.forEach.<anonymous closure> (dart:async/future.dart:484:26)
E/flutter (11408): #4 Future.doWhile.<anonymous closure> (dart:async/future.dart:526:26)
E/flutter (11408): #5 _RootZone.runUnaryGuarded (dart:async/zone.dart:1316:10)
E/flutter (11408): #6 _RootZone.bindUnaryCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1355:26)
E/flutter (11408): #7 Future.doWhile (dart:async/future.dart:541:18)
E/flutter (11408): #8 Future.forEach (dart:async/future.dart:482:12)
E/flutter (11408): #9 _ConnectionManager.open (file:///C:/Users/Picmix/flutter/.pub-cache/hosted/pub.dartlang.org/mongo_dart-0.3.1/lib/src/network/connection_manager.dart:56:19)
E/flutter (11408): #10 Db.open.<anonymous closure> (file:///C:/Users/Picmix/flutter/.pub-cache/hosted/pub.dartlang.org/mongo_dart-0.3.1/lib/src/database/db.dart:252:33)
E/flutter (11408): #11 new Future.sync (dart:async/future.dart:222:31)
E/flutter (11408): #12 Db.open (file:///C:/Users/Picmix/flutter/.pub-cache/hosted/pub.dartlang.org/mongo_dart-0.3.1/lib/src/database/db.dart:239:16)
E/flutter (11408): #13 main (file:///F:/Jamil/WORKSHOP/MY-PRACTICE/FLUTTER/FLUTTERMONGO/simplecrud/lib/main.dart:6:6)
E/flutter (11408): <asynchronous suspension>
E/flutter (11408): #14 _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
E/flutter (11408): #15 _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)
E/flutter (11408): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (11408): type '(MongoReplyMessage) => void' is not a subtype of type '(dynamic) => void'
E/flutter (11408): #0 _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:1114:29)
E/flutter (11408): #1 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (11408): #2 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
and this is the simple code that i write to open connection between mlab and the app:
import 'package:mongo_dart/mongo_dart.dart';
void main() async {
print('hello');
Db db = new Db('mongodb://<myusername><mypassword>#ds147659.mlab.com:47659/simple-crud');
db.open().then((success) {
if (success) print('connected');
});
}
any idea sir?
This is due to the latest flutter update beta2.
Please check this blog by flutter
Seems like there is a flutter version mismatch of your project and Mongo plugin.
Mongo's latest plugin was updated on Oct 24, 2017.
There is already an issue on their git. You can keep track of it.
Meanwhile, according to this issue:
you can try changing the plugin code from
Future<bool> get isOn => _channel.invokeMethod('isOn');
to
Future<bool> get isOn async {
final bool isOn = await _channel.invokeMethod('isOn');
return isOn;
}
NOTE: Above is just an example, please check the plugin dart file for the correct function to change.

Cannot open file, path = 'file:///path' (OS Error: No such file or directory, errno = 2)

Hi I am trying reduce image size picked from gallery using image library
while trying that I am facing error like this
E/flutter (13796): [ERROR:lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (13796): FileSystemException: Cannot open file, path = 'file:///storage/emulated/0/WhatsApp/Media/WhatsApp%20Images/IMG-20171016-WA0020.jpg' (OS Error: No such file or directory, errno = 2)
E/flutter (13796): #0 _File.throwIfError (file_impl.dart:618)
E/flutter (13796): #1 _File.openSync (file_impl.dart:473)
E/flutter (13796): #2 _File.readAsBytesSync (file_impl.dart:533)
E/flutter (13796): #3 _AddNewUserState.qqq (/data/data/com.prayuta.chitfunds/cache/chitfundsUNFPRG/chitfunds/lib/users.dart:420:97)
E/flutter (13796): <asynchronous suspension>
E/flutter (13796): #4 _AddNewUserState.build.<anonymous closure> (/data/data/com.prayuta.chitfunds/cache/chitfundsUNFPRG/chitfunds/lib/users.dart:686:19)
E/flutter (13796): #5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:102:24)
E/flutter (13796): #6 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:149:9)
E/flutter (13796): #7 TapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:119:7)
E/flutter (13796): #8 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:156:27)
E/flutter (13796): #9 BindingBase&SchedulerBinding&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:147:20)
E/flutter (13796): #10 BindingBase&SchedulerBinding&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:121:22)
E/flutter (13796): #11 BindingBase&SchedulerBinding&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:101:7)
E/flutter (13796): #12 BindingBase&SchedulerBinding&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:64:7)
E/flutter (13796): #13 BindingBase&SchedulerBinding&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:48:7)
E/flutter (13796): #14 _invoke1 (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:100)
E/flutter (13796): #15 _dispatchPointerDataPacket (file:///b/build/slave/Linux_Engine/build/src/flutter/lib/ui/hooks.dart:58)
can any one help and my code look like this
import 'package:image/image.dart' as convertinglib;
File imageFile = await ImagePicker.pickImage();
convertinglib.Image image = convertinglib.decodeImage(new Io.File(imageFile.uri.toString()).readAsBytesSync());
convertinglib.Image thumbnail = convertinglib.copyResize(image, 120);
I suppose the issue is passing the Image URI as a String.
There is a fromUri constructor where you can pass the file URI.
Try using
new Io.File.fromUri(imageFile.uri)
instead of
new Io.File(imageFile.uri.toString())
The problem is not in reading the file with the image picker or with the conversion to a smaller size but with the writing of the file to the file system. I take it, you took the example code of the dart image package
which writes the file to the file system after resizing it. This is in this form not possible on smartphones.
The code you posted didn't actually cause the error but this line did:
new Io.File(imageFile.uri.toString())
..writeAsBytesSync(convertingLib.encodePng(thumbnail))
The problem with this is that the imagePicker hides the real uri of the image. It gives you a path that looks something like this: .../tmp/image_picker_1547A964-791E-426F-A682-33D3AFA995BA-18295-0003861F9255294A.jpg which can't be used to save your new thumbnail.
You can either try to avoid saving the file in the first place or save it to a location that actually exists (you could use for example the path_provider plugin for that purpose).

Resources