Dart changing a variable value using own extension method - android

I was trying to delete elements of a list using my own extension but I got an error. This error says the extension is only readable.
This is my extension
extension ToListExtention on List {
List toDatatable() {
List columns = [];
List rows = [];
(this.first as Map).forEach((key, value) {columns.add(key);});
this.forEach((element) {
rows.add((element as Map).values);
});
**this.clear();**
return [columns,rows];
}
}
and this is the error that I got
E/flutter (24973): [ERROR:flutter/lib/ui/ui_dart_state.cc(199)] Unhandled Exception: Unsupported operation: read-only
E/flutter (24973): #0 QueryResultSet.length= (package:sqflite_common/src/collection_utils.dart:109:5)
E/flutter (24973): #1 ListMixin.clear (dart:collection/list.dart:342:10)
E/flutter (24973): #2 ToListExtention.toDatatable (package:dbdeneme/Extentions.dart:9:10)
E/flutter (24973): #3 _AnasayfaState.build.<anonymous closure>.<anonymous closure> (package:dbdeneme/main.dart:58:27)
E/flutter (24973): #4 _rootRunUnary (dart:async/zone.dart:1362:47)
E/flutter (24973): #5 _CustomZone.runUnary (dart:async/zone.dart:1265:19)
E/flutter (24973): <asynchronous suspension>
So, as you understand, the bolded line doesn't work. How can I do it inside my own extension?

In extensions, you cannot change the original value of the object.
You can copy the list and then do all kinds of manipulation on that list. But you cannot change the list.

Your problem is that the list you are calling toDatatable on is a QueryResultSet which implementation can be found here:
https://github.com/tekartik/sqflite/blob/81c0c30aa59d7d3f229bf6ce0494458f96f893c2/sqflite_common/lib/src/collection_utils.dart#L74
Which implements length (called by clear()) with the following:
#override
set length(int newLength) {
throw UnsupportedError('read-only');
}
So your current extension method are not going to work on this kind of List (List are just an interface in this case and QueryResultSet are implementing that interface).

Related

I got error when I run my app like type 'Null' is not a subtype of type 'Widget'

type 'Null' is not a subtype of type 'Widget'
When the exception was thrown, this was the stack:
#0 Home.build.<anonymous closure> (package:habittracker1/main.dart:230:29)
#1 SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:471:22)
#2 SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:1236:28)
#3 SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1250:55)
#4 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2597:19)
#5 SliverMultiBoxAdaptorElement.createChild (package:flutter/src/widgets/sliver.dart:1242:12)
#6 RenderSliverMultiBoxAdaptor._createOrObtainChild.<anonymous closure> (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:349:23)
#7 RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:2025:59)
the widget used in the main file line 230 giving a null value,
please post a screenshot of your code showing the line (package:habittracker1/main.dart:230:29)
The error is called because something should be drawn. You don't have an element that will draw. To eliminate this, do return SizedBox() in SliverChildBuilderDelegate.build

I face that error when i use url lancher packege in flutter

I try to run a url using url lancher package
https://pub.dev/packages/url_launcher
and i got this error , i use a package to display my app over apps , using that package https://pub.dev/packages/flutter_overlay_window , and i added a button inside the overlay and when i press it it supposed to send a message to whatsapp using url lancher package , but the problem is that when your app is over apps you will get that error :
E/flutter (24166): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(NO_ACTIVITY, Launching a URL requires a foreground activity., null, null)
E/flutter (24166): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (24166): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18)E/flutter (24166): <asynchronous suspension>
E/flutter (24166): #2 launchUrlString (package:url_launcher/src/url_launcher_string.dart:39:10)
E/flutter (24166): <asynchronous suspension>
E/flutter (24166): #3 launchUrl (package:url_launcher/src/url_launcher_uri.dart:57:10)

Flutter ble writing fails

Flutter ble - write characteristic error
I'm not being able to write on ble pheriperal device, using flutter_blue library, it throws this exception:
Unhandled Exception: PlatformException(write_characteristic_error, service (0000ff06-0000-1000-8000-00805f9b34fb) could not be located on the device, null, null)
E/flutter (29808): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (29808): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18)
E/flutter (29808): <asynchronous suspension>
E/flutter (29808): #2 BluetoothCharacteristic.write (package:flutter_blue/src/bluetooth_characteristic.dart:120:18)
E/flutter (29808): <asynchronous suspension>
E/flutter (29808): #3 DeviceScreen._buildServiceTiles.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:untitled/main.dart:176:23)
or another error saying : Write is not permited.
I'm using example code provided by flutter blue library, here is the code that im trying to write after device is connected:
onWritePressed: () async {
await c.write(_getRandomBytes(), withoutResponse: true);
await c.read();
},
onNotificationPressed: () async {
await c.setNotifyValue(!c.isNotifying);
if (c.properties.read) {
await c.read();
}
List<int> _getRandomBytes(){
String command = "55 AA 00 01 50 3C 00";
return command.codeUnits;
}
The hardware device is working fine in Kotlin, data is sent and received.

Flutter | NoSuchMethodError: The method 'round' was called on null. E/flutter (25849): Receiver: null

Constantly getting this error since i override the ErrorWidget.builder in the main function. I only see the exception i navigate to a specific widget(Not initially. I be on the page for few minutes, this starts getting printed automatically in console gradually & keeps printing. Once this error appears on console, i see this error every time i tap on something. package:flutter/src/widgets/navigator.dart': Failed assertion: line 1748 pos 12: '!_debugLocked': is not true. ) . The problem i face is , i don't know where to lookup for the reason..came up all in sudden today & i have no clue to debug. Has anybody else seen this error before ??
E/flutter (25849): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method 'round' was called on null.
E/flutter (25849): Receiver: null
E/flutter (25849): Tried calling: round()
E/flutter (25849): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
E/flutter (25849): #1 PageController.nextPage (package:flutter/src/widgets/page_view.dart:227:31)
E/flutter (25849): #2 _CarouselSliderState.getTimer.<anonymous closure> (package:carousel_slider/carousel_slider.dart:172:14)
E/flutter (25849): #3 _rootRunUnary (dart:async/zone.dart:1192:38)
E/flutter (25849): #4 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter (25849): #5 _CustomZone.runUnaryGuarded (dart:async/zone.dart:987:7)
E/flutter (25849): #6 _CustomZone.bindUnaryCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1024:26)
E/flutter (25849): #7 _rootRunUnary (dart:async/zone.dart:1196:13)
E/flutter (25849): #8 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter (25849): #9 _CustomZone.bindUnaryCallback.<anonymous closure> (dart:async/zone.dart:1008:26)
E/flutter (25849): #10 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398:19)
E/flutter (25849): #11 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429:5)
E/flutter (25849): #12 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter (25849):
if you use carousel_pro. it's from the plugin src.
try update
if ((_controller.page!=null) && (_controller.page.round() == widget.images.length - 1)) {
I already create pull request to the source. hope it will be updated.
cheers

PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null)

I've searched the whole internet, tried every possible solution, still I'm not being able to sign in using GoogleSignIn from my flutter app.
Things I've tried :
1. Added SHA-1 Certificate
2. Added SHA-256 Certificate
3. Filled O-Auth Screen
4. Enabled GoogleSignIn in firebase
5. Added support email
Testing currently only in debug mode. As the app is in its initial stages right now I don't want to build a release version yet. Using debug SHA-1 and SHA-256 fingerprints.
Future<FirebaseUser> _signIn(BuildContext context) async {
final GoogleSignInAccount googleUser = await _googleSignIn.signIn();
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken, idToken: googleAuth.idToken);
AuthResult userDetails =
await _firebaseAuth.signInWithCredential(credential);
ProviderDetails providerInfo =
ProviderDetails(userDetails.user.providerId);
List<ProviderDetails> providerData = List<ProviderDetails>();
providerData.add(providerInfo);
UserDetails details = UserDetails(
providerDetails: userDetails.user.providerId,
userEmail: userDetails.user.email,
userName: userDetails.user.displayName,
photoUrl: userDetails.user.photoUrl,
providerData: providerData);
return userDetails.user;
}
Error I get
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception:
PlatformException(sign_in_failed,
com.google.android.gms.common.api.ApiException: 10: , null)
E/flutter (12322): #0 StandardMethodCodec.decodeEnvelope
package:flutter/…/services/message_codecs.dart:564
E/flutter (12322): #1 MethodChannel.invokeMethod
package:flutter/…/services/platform_channel.dart:316
E/flutter (12322): <asynchronous suspension>
E/flutter (12322): #2 MethodChannel.invokeMapMethod
package:flutter/…/services/platform_channel.dart:344
E/flutter (12322): <asynchronous suspension>
E/flutter (12322): #3 GoogleSignIn._callMethod
package:google_sign_in/google_sign_in.dart:218
E/flutter (12322): <asynchronous suspension>
E/flutter (12322): #4 GoogleSignIn._addMethodCall.<anonymous closure>
package:google_sign_in/google_sign_in.dart:27
E/flutter (12322): #5 _rootRun (dart:async/zone.dart:1120:38)
E/flutter (12322): #6 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (12322): #7 _FutureListener.handleWhenComplete
(dart:async/future_impl.dart:150:18)
E/flutter (12322): #8
Future._propagateToListeners.handleWhenCompleteCallback
(dart:async/future_impl.dart:609:39)
E/flutter (12322): #9 Future._propagateToListeners
(dart:async/future_impl.dart:665:37)
E/flutter (12322): #10 Future._addListener.<anonymous closure>
(dart:async/future_impl.dart:348:9)
E/flutter (12322): #11 _rootRun (dart:async/zone.dart:1124:13)
E/flutter (12322): #12 _CustomZone.run (dart:async/zone.dart:1021:19)
E/flutter (12322): #13 _CustomZone.runGuarded
(dart:async/zone.dart:923:7)
E/flutter (12322): #14 _CustomZone.bindCallbackGuarded.<anonymous
closure> (dart:async/zone.dart:963:23)
E/flutter (12322): #15 _microtaskLoop
(dart:async/schedule_microtask.dart:41:21)
E/flutter (12322): #16 _startMicrotaskLoop
(dart:async/schedule_microtask.dart:50:5)
E/flutter (12322):
I know this question was posted quite some time ago but in case anybody else had issues, in addition to all of the above steps, I also enabled Google People API. Make sure that you are on the right email and project.
https://console.developers.google.com/apis/library/people.googleapis.com?q=people&id=5877a7af-1d13-4098-a53e-b5e2d7a87a4f&project=phamton-test
Did you rebuild the project after adding the dependencies?
Sometimes you need to rebuild your project whenever you add any platform specific plugin before it can be used effectively
So as regards to this error, if you find yourself facing it at any point.
There are 2 things that could possibly be wrong
Your app is not on the playstore and you're testing locally with a signed app.
You should probably go and add more SHA keys, if you have only SHA-1 go ahead and put SHA-256. Also be weary of your test environment as it could also mean that your apk mode(Testing or Production) is not correlating.

Categories

Resources