I'm calling shared prefs in page I made as splash screen
void initState() {
super.initState();
getPreferences().then((value){
Timer(
Duration(seconds: 2),
(() => {
Navigator.of(context).pushReplacement(new MaterialPageRoute(
builder: (BuildContext context) => value))
}),
);
});
}
and here is my method
getPreferences() async {
WidgetsFlutterBinding.ensureInitialized();//??**
SharedPreferences prefs = await SharedPreferences.getInstance();//the same with home screen in the skip button
bool loadingScreen=prefs.getBool('seen');
print("loadingScreen = $loadingScreen");
StatefulWidget _screen= LoginScr();
if (loadingScreen == null|| loadingScreen == false){
_screen = Tut();
}
else if (loadingScreen == true){
userName = prefs.getString('userName');
if(userName ==null||userName=="null") {
print(userName+' userName in main');
_screen = LoginScr();
} else {
print(userName +'userName in main');
_screen = HomePage();
}
}
return _screen;
}
By the way I don't know what is this line
Widge,tsFlutterBinding.ensureInitialized();//??**
and here is my log
Performing hot restart... Syncing files to device Android SDK built
for x86... Restarted application in 1,776ms. I/flutter ( 8982):
loadingScreen = true E/flutter ( 8982):
[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception:
NoSuchMethodError: The method '+' was called on null. E/flutter (
8982): Receiver: null E/flutter ( 8982): Tried calling: +(" userName
in main") E/flutter ( 8982): #0 Object.noSuchMethod
(dart:core-patch/object_patch.dart:51:5) E/flutter ( 8982): #1
_SplashSCRState.getPreferences (package:plaster/UI/SplashSCR.dart:138:24) E/flutter ( 8982):
E/flutter ( 8982): #2
_SplashSCRState.initState (package:plaster/UI/SplashSCR.dart:26:5) E/flutter ( 8982): #3 StatefulElement._firstBuild
(package:flutter/src/widgets/framework.dart:4765:58) E/flutter (
8982): #4 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 8982):
#5 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter (
8982): #6 Element.updateChild
(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (
8982): #7 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:6118:14) E/flutter (
8982): #8 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3569:14) E/flutter (
8982): #9 Element.updateChild
(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (
8982): #10 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:4652:16) E/flutter (
8982): #11 Element.rebuild
(package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 8982):
#12 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5) E/flutter ( 8982):
#13 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 8982):
#14 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter (
8982): #15 Element.updateChild
(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (
8982): #16 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:6118:14) E/flutter (
8982): #17 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3569:14) E/flutter (
8982): #18 Element.updateChild
(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (
8982): #19 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:6118:14) E/flutter (
8982): #20 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3569:14) E/flutter (
8982): #21 Element.updateChild
(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (
8982): #22 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:4652:16) E/flutter (
8982): #23 StatefulElement.performRebuild
(package:flutter/src/widgets/framework.dart:4800:11) E/flutter (
8982): #24 Element.rebuild
(package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 8982):
#25 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5) E/flutter ( 8982):
#26 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4791:11) E/flutter (
8982): #27 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 8982):
#28 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter (
8982): #29 Element.updateChild
(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (
8982): #30 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:6118:14) E/flutter (
8982): #31 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3569:14) E/flutter (
8982): #32 Element.updateChild
(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (
8982): #33 SingleChildRenderObjectElement.mount
(package:flutter/src/widgets/framework.dart:6118:14) E/flutter (
8982): #34 Element.inflateWidget
(package:flutter/src/widgets/framework.dart:3569:14) E/flutter (
8982): #35 Element.updateChild
(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (
8982): #36 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:4652:16) E/flutter (
8982): #37 StatefulElement.performRebuild
(package:flutter/src/widgets/framework.dart:4800:11) E/flutter (
8982): #38 Element.rebuild
(package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 8982):
#39 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5) E/flutter ( 8982):
#40 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4791:11) E/flutter (
8982): #41 ComponentElement.mount
(package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 8982):
#42 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter (
8982): #43 Element.updateChild
(package:flutter/src/widgets/framework.dart:3327:18) E/flutter (
8982): #44 ComponentElement.performRebuild
(package:flutter/src/widgets/framework.dart:4652:16) E/flutter (
8982): #45 Element.r
You trying to print log:
print(userName + ' userName in main');
When userName is null:
if (userName == null || userName == "null")
And it raises exception. Modify print method usage ant try again. It should be like this:
userName = prefs.getString('userName');
if(userName == null || userName == "null") {
print('first start, userName in main is null');
_screen = LoginScr();
} else {
print('$userName is userName in main');
_screen = HomePage();
}
Related
In my code, i have a listview widget, and i gave data to it from firestore using firebase, and tried to display data on screen as text. But nothing happens, i am not getting any error or something. Still my page is blank. So can anyone tell me that is there a mistake in firebase part or listview one. It will be very helpfull.
Here's my code -
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';
import 'package:social_app/widgets/header.dart';
import 'package:social_app/widgets/progress.dart';
final userRef = FirebaseFirestore.instance.collection("users");
class Timeline extends StatefulWidget {
#override
_TimelineState createState() => _TimelineState();
}
class _TimelineState extends State<Timeline> {
List<dynamic> users = [];
#override
void initState() {
// TODO: implement initState
super.initState();
getUserById();
getUsers();
}
getUserById() {
}
getUsers() async {
final QuerySnapshot snapshot = await userRef.get();
setState(() {
users = snapshot.docs;
});
// snapshot.docs.forEach((DocumentSnapshot doc) {
// print(doc.data());
// print(doc.id);
// print(doc.exists);
// });
}
#override
Widget build(context) {
return SafeArea(
child: Scaffold(
backgroundColor: Colors.black,
appBar: header(context, isAppTitle: true),
body: Container(
child: ListView(
children: users.map((user) => Text(user['username'], style: TextStyle(color: Colors.white),)).toList()
),
),
),
);
}
}
Here's my run output -
Performing hot reload...
Syncing files to device sdk gphone x86...
Reloaded 3 of 800 libraries in 817ms.
W/Firestore( 3283): (21.7.1) [Firestore]: Listen for Query(target=Query(users order by __name__);limitType=LIMIT_TO_FIRST) failed: Status{code=PERMISSION_DENIED, description=Missing or insufficient permissions., cause=null}
E/flutter ( 3283): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: [cloud_firestore/permission-denied] The caller does not have permission to execute the specified operation.
E/flutter ( 3283): #0 MethodChannelQuery.get (package:cloud_firestore_platform_interface/src/method_channel/method_channel_query.dart:105:7)
E/flutter ( 3283): <asynchronous suspension>
E/flutter ( 3283): #1 Query.get (package:cloud_firestore/src/query.dart:178:25)
E/flutter ( 3283): #2 _TimelineState.getUsers (package:social_app/pages/timeline.dart:29:50)
E/flutter ( 3283): #3 _TimelineState.initState (package:social_app/pages/timeline.dart:22:5)
E/flutter ( 3283): #4 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4765:58)
E/flutter ( 3283): #5 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
E/flutter ( 3283): #6 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter ( 3283): #7 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter ( 3283): #8 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6118:14)
E/flutter ( 3283): #9 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter ( 3283): #10 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter ( 3283): #11 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6118:14)
E/flutter ( 3283): #12 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter ( 3283): #13 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter ( 3283): #14 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter ( 3283): #15 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter ( 3283): #16 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5)
E/flutter ( 3283): #17 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
E/flutter ( 3283): #18 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter ( 3283): #19 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter ( 3283): #20 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter ( 3283): #21 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter ( 3283): #22 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5)
E/flutter ( 3283): #23 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
E/flutter ( 3283): #24 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter ( 3283): #25 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter ( 3283): #26 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter ( 3283): #27 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11)
E/flutter ( 3283): #28 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter ( 3283): #29 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5)
E/flutter ( 3283): #30 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4791:11)
E/flutter ( 3283): #31 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
E/flutter ( 3283): #32 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter ( 3283): #33 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter ( 3283): #34 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16)
E/flutter ( 3283): #35 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5)
E/flutter ( 3283): #36 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5)
E/flutter ( 3283): #37 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5)
E/flutter ( 3283): #38 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14)
E/flutter ( 3283): #39 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18)
E/flutter ( 3283): #40 SliverMultiBoxAdaptorElement.updateChild (package:flutter/src/widgets/sliver.dart:1158:36)
E/flutter ( 3283): #41 SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1143:20)
E/flutter ( 3283): #42 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2683:19)
E/flutter ( 3283): #43 SliverMultiBoxAdaptorElement.createChild (package:flutter/src/widgets/sliver.dart:1136:11)
E/flutter ( 3283): #44 RenderSliverMultiBoxAdaptor._createOrObtainChild.<anonymous closure> (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:350:23)
E/flutter ( 3283): #45 RenderObject.invokeLayoutCallback.<anonymous closure> (package:flutter/src/rendering/object.dart:1883:59)
E/flutter ( 3283): #46 PipelineOwner._enableMutationsToDirtySubtrees (package:flutter/src/rendering/object.dart:915:15)
E/flutter ( 3283): #47 RenderObject.invokeLayoutCallback (package:flutter/src/rendering/object.dart:1883:14)
E/flutter ( 3283): #48 RenderSliverMultiBoxAdaptor._createOrObtainChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:339:5)
E/flutter ( 3283): #49 RenderSliverMultiBoxAdaptor.insertAndLayoutLeadingChild (package:flutter/src/rendering/sliver_multi_box_adaptor.dart:455:5)
E/flutter ( 3283): #50 RenderSliverFixedExtentBoxAdaptor.performLayout (package:flutter/src/rendering/sliver_fixed_extent_list.dart:234:32)
E/flutter ( 3283): #51 RenderObject.layout (package:flutter/src/rendering/object.dart:1777:7)
E/flutter ( 3283): #52 RenderSliverEdgeInsetsPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:132:12)
E/flutter ( 3283): #53 _RenderSliverFractionalPadding.performLayout (package:flutter/src/widgets/sliver_fill.dart:170:11)
E/flutter ( 3283): #54 RenderObject.layout (package:flutter/src/rendering/object.dart:1777:7)
E/flutter ( 3283): #55 RenderViewportBase.layoutChildSequence (package:flutter/src/rendering/viewport.dart:507:13)
E/flutter ( 3283): #56 RenderViewport._attemptLayout (package:flutter/src/rendering/viewport.dart:1561:12)
E/flutter ( 3283): #57 RenderViewport.performLayout (package:flutter/src/rendering/viewport.dart:1470:20)
E/flutter ( 3283): #58 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1634:7)
E/flutter ( 3283): #59 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:884:18)
E/flutter ( 3283): #60 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:436:19)
E/flutter ( 3283): #61 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:914:13)
E/flutter ( 3283): #62 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:302:5)
E/flutter ( 3283): #63 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15)
E/flutter ( 3283): #64 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1055:9)
E/flutter ( 3283): #65 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:971:5)
E/flutter ( 3283): #66 _rootRun (dart:async/zone.dart:1190:13)
E/flutter ( 3283): #67 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter ( 3283): #68 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter ( 3283): #69 _invoke (dart:ui/hooks.dart:251:10)
E/flutter ( 3283): #70 _drawFrame (dart:ui/hooks.dart:209:3)
E/flutter ( 3283):
W/Firestore( 3283): (21.7.1) [WatchStream]: (a99c49e) Stream closed with status: Status{code=CANCELLED, description=Disconnecting idle stream. Timed out waiting for new targets., cause=null}.
W/ansh.social_ap( 3283): Accessing hidden method Ldalvik/system/CloseGuard;->close()V (greylist,core-platform-api, linking, allowed)
Your code seems to be working fine. Let me explain your problem.
When you create your cloud_firestore for the first time, then permission for accessing the data is set to public in the rules tab. This permission is public for 30 days. After that firestore turned it off and you have to define your own rule.
Here, rules are the actual permission which decide who can access your data and who cannot. Hence, for the time being you can again make the data public by changing the Rules.
Access the Rule tab by following the image below:
Change the Rules at firestore console accordingly. Here is the link to rules documentation.
Note:
You can make the Rules public for testing purposes but don't make it public permanently it will make your data insecure.
Using Google sign in API for a month now
Getting this error before google sign-in
Changed Cloud Firestore Rules, still showing the same results
API error? (sign_in_failed, com.google.android.gms.common.api.ApiException: 10:, null)
E/flutter ( 8552): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: type 'PlatformException' is not a subtype of type 'String'
E/flutter ( 8552): #0 _SignInState.initState.<anonymous closure> (package:event_management/google_signin.dart:35:32)
E/flutter ( 8552): #1 _rootRunUnary (dart:async/zone.dart:1198:47)
E/flutter ( 8552): #2 _CustomZone.runUnary (dart:async/zone.dart:1100:19)
E/flutter ( 8552): #3 _FutureListener.handleError (dart:async/future_impl.dart:160:20)
E/flutter ( 8552): #4 Future._propagateToListeners.handleError (dart:async/future_impl.dart:708:47)
E/flutter ( 8552): #5 Future._propagateToListeners (dart:async/future_impl.dart:729:24)
E/flutter ( 8552): #6 Future._completeError (dart:async/future_impl.dart:537:5)
E/flutter ( 8552): #7 _AsyncAwaitCompleter.completeError (dart:async-patch/async_patch.dart:47:15)
E/flutter ( 8552): #8 GoogleSignIn.signInSilently (package:google_sign_in/google_sign_in.dart)
E/flutter ( 8552): <asynchronous suspension>
E/flutter ( 8552): #9 _SignInState.initState (package:event_management/google_signin.dart:32:13)
E/flutter ( 8552): #10 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4684:58)
E/flutter ( 8552): #11 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
E/flutter ( 8552): #12 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter ( 8552): #13 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter ( 8552): #14 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5874:14)
E/flutter ( 8552): #15 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter ( 8552): #16 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter ( 8552): #17 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
E/flutter ( 8552): #18 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
E/flutter ( 8552): #19 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
E/flutter ( 8552): #20 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
E/flutter ( 8552): #21 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter ( 8552): #22 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter ( 8552): #23 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5874:14)
E/flutter ( 8552): #24 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter ( 8552): #25 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter ( 8552): #26 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5874:14)
E/flutter ( 8552): #27 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter ( 8552): #28 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter ( 8552): #29 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
E/flutter ( 8552): #30 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4719:11)
E/flutter ( 8552): #31 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
E/flutter ( 8552): #32 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4525:5)
E/flutter ( 8552): #33 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4710:11)
E/flutter ( 8552): #34 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4520:5)
E/flutter ( 8552): #35 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter ( 8552): #36 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter ( 8552): #37 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5874:14)
E/flutter ( 8552): #38 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter ( 8552): #39 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter ( 8552): #40 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5874:14)
E/flutter ( 8552): #41 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3490:14)
E/flutter ( 8552): #42 Element.updateChild (package:flutter/src/widgets/framework.dart:3258:18)
E/flutter ( 8552): #43 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4571:16)
E/flutter ( 8552): #44 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4719:11)
E/flutter ( 8552): #45 Element.rebuild (package:flutter/src/widgets/framework.dart:4262:5)
E/flutter ( 8552): #46 ComponentElement._firstBuild (package
Cloud Firestore Rules:
`
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.time < timestamp.date(2020, 8, 31);
}
}
}
`
Cause:
This Problem occured as I had re-installed Android Studio in my external ssd, so SHA-1 values changed.
Solution:
Get SHA-1 again using "gradlew signingReport" command in gradlew terminal.
Add new SHA-1 value into the Firebase, it might solve your issue.
I'm a beginner at Flutter and I'm currently following along with a tutorial to built a task planner (https://www.youtube.com/watch?v=xJSestoFlJ8&list=PLF9bFmu3NqWqchwS3DO9MDSl15IiHQWcr&index=9)
After rewriting the code by hand (the database, etc), when I restarted to app to show the items I saved into the database in the debug console, I got an error saying while working with initstate and setstate
Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index'
Here is the code related to the error
final TextEditingController _textEditingController = TextEditingController();
var db = DatabaseHelper();
#override
void initState() {
super.initState();
_readTaskList();
}
void _handleSubmitted(String text) async {
_textEditingController.clear();
Tasks tasksItem = Tasks(text, DateTime.now().toIso8601String());
int savedItemId = await db.saveItem(tasksItem);
print("Item saved ID: $savedItemId");
}
_readTaskList() async {
List items = await db.getItems();
items.forEach((item) {
Tasks tasksItem = Tasks.map(items);
print("DB Items: ${tasksItem.itemName}");
});
}
and here is the full debug console log
E/flutter ( 8249): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: type 'String' is not a subtype of type 'int' of 'index'
E/flutter ( 8249): #0 new Tasks.map
package:gatorblocks_rbt/models/tasks.dart:12
E/flutter ( 8249): #1 _TaskPlannerState._readTaskList.<anonymous closure>
package:gatorblocks_rbt/pages/taskPlanner.dart:105
E/flutter ( 8249): #2 List.forEach (dart:core-patch/growable_array.dart:285:8)
E/flutter ( 8249): #3 _TaskPlannerState._readTaskList
package:gatorblocks_rbt/pages/taskPlanner.dart:104
E/flutter ( 8249): <asynchronous suspension>
E/flutter ( 8249): #4 _TaskPlannerState.initState
package:gatorblocks_rbt/pages/taskPlanner.dart:24
E/flutter ( 8249): #5 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4355
E/flutter ( 8249): #6 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4201
E/flutter ( 8249): #7 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #8 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #9 SingleChildRenderObjectElement.mount
package:flutter/…/widgets/framework.dart:5445
E/flutter ( 8249): #10 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #11 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #12 ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4243
E/flutter ( 8249): #13 Element.rebuild
package:flutter/…/widgets/framework.dart:3947
E/flutter ( 8249): #14 ComponentElement._firstBuild
package:flutter/…/widgets/framework.dart:4206
E/flutter ( 8249): #15 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4201
E/flutter ( 8249): #16 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #17 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #18 SingleChildRenderObjectElement.mount
package:flutter/…/widgets/framework.dart:5445
E/flutter ( 8249): #19 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #20 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #21 SingleChildRenderObjectElement.mount
package:flutter/…/widgets/framework.dart:5445
E/flutter ( 8249): #22 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #23 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #24 ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4243
E/flutter ( 8249): #25 Element.rebuild
package:flutter/…/widgets/framework.dart:3947
E/flutter ( 8249): #26 ComponentElement._firstBuild
package:flutter/…/widgets/framework.dart:4206
E/flutter ( 8249): #27 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4381
E/flutter ( 8249): #28 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4201
E/flutter ( 8249): #29 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #30 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #31 SingleChildRenderObjectElement.mount
package:flutter/…/widgets/framework.dart:5445
E/flutter ( 8249): #32 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #33 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #34 SingleChildRenderObjectElement.mount
package:flutter/…/widgets/framework.dart:5445
E/flutter ( 8249): #35 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #36 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #37 ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4243
E/flutter ( 8249): #38 Element.rebuild
package:flutter/…/widgets/framework.dart:3947
E/flutter ( 8249): #39 ComponentElement._firstBuild
package:flutter/…/widgets/framework.dart:4206
E/flutter ( 8249): #40 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4381
E/flutter ( 8249): #41 ComponentElement.mount
package:flutter/…/widgets/framework.dart:4201
E/flutter ( 8249): #42 Element.inflateWidget
package:flutter/…/widgets/framework.dart:3194
E/flutter ( 8249): #43 Element.updateChild
package:flutter/…/widgets/framework.dart:2988
E/flutter ( 8249): #44 ComponentElement.performRebuild
package:flutter/…/widgets/framework.dart:4243
E/flutter ( 8249): #45 Element.rebuild (package:flutte
Here is a screenshot
The app works perfectly fine, it doesn't crash or anything, just fails to properly show the items that I've saved into the database.
You are getting the error because you are putting a int into a Text widget that accepts a String.
You can solve that by converting the int using the toString() method.
Check the code below: Replace it with your handleSubmitted function:
void _handleSubmitted(String text) async {
_textEditingController.clear();
Tasks tasksItem = Tasks(text, DateTime.now().toIso8601String());
int savedItemId = await db.saveItem(tasksItem);
// convert savedItemId to a string using toString() method
print("Item saved ID: $savedItemId.toString()");
}
I hope this helps.
UPDATED
After going through your code, I can see you are trying to access the field id which you didn't define in your Tasks constructor.
Why you are getting the error:
Type String is not a subtype of int index
Hope this solves your error.
I'm attempting to get a flutter app, made in android studio, to connect to a c# api hosted locally. Running the api on IIS Express gives a url of https://localhost:44364/api/trip, which I believe relates to http://10.0.2.2:44364/api in Android studio when using the emulator.
I'm attempting to retrieve a list of Trips from the db via API. Postman works fine.
I get multiple errors. I have tried the emulator, I've also tried plugging a phone in directly and switching the address to my ip address. I've even tried switching the api to run in the console and not IIS. Nothing works.
I did attempt to reach the api through the emulator browser and was told the site was unsafe, leading me to think it's a certificate problem.
The flutter project is fairly simple, it's in its infancy stage and I'm still learning how to program it.
Here are the three flutter files, and the error list.
main.dart
import 'dart:convert';
import 'package:bike_client/API.dart';
import 'package:bike_client/models/Trip.dart';
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Track It',
theme: new ThemeData(
primarySwatch: Colors.red,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
#override
createState() => new _MyHomePageState();
}
class _MyHomePageState extends State {
var trips = new List<Trip>();
_getTrips() {
API.getTrips().then((response) {
setState(() {
Iterable list = json.decode(response.body);
trips = list.map((model) => Trip.fromJson(model)).toList();
});
});
}
initState() {
super.initState();
_getTrips();
}
dispose() {
super.dispose();
}
#override
build(context) {
return Scaffold(
appBar: AppBar(
title: Text("Trip List"),
),
body: ListView.builder(
itemCount: trips.length,
itemBuilder: (context, index) {
return ListTile(title: Text((trips[index].tripId).toString()));
},
));
}
}
API.dart
import 'dart:async';
import 'package:http/http.dart' as http;
//const baseUrl = "https://192.168.1.14:44364/api";
const baseUrl = "http://10.0.2.2:44364/api";
class API {
static Future getTrips() {
var url = baseUrl + "/trip/1";
return http.get(url);
}
}
Trip.dart
class Trip {
int tripId;
int userId;
Trip(int tripId, int userId) {
this.tripId = tripId;
this.userId = userId;
}
Trip.fromJson(Map json)
: tripId = json['tripId'],
userId = json['userId'];
Map toJson() {
return {'tripId': tripId, 'userId': userId};
}
}
Console
Launching lib\main.dart on AOSP on IA Emulator in debug mode...
Running Gradle task 'assembleDebug'...
E/flutter ( 7781): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 38612
E/flutter ( 7781): #0 IOClient.send (package:http/src/io_client.dart:33:24)
E/flutter ( 7781): <asynchronous suspension>
E/flutter ( 7781): #1 BaseClient._sendUnstreamed (package:http/src/base_client.dart:176:38)
E/flutter ( 7781): #2 BaseClient.get (package:http/src/base_client.dart:35:7)
E/flutter ( 7781): #3 get.<anonymous closure> (package:http/http.dart:46:36)
E/flutter ( 7781): #4 _withClient (package:http/http.dart:166:20)
E/flutter ( 7781): #5 get (package:http/http.dart:46:5)
E/flutter ( 7781): #6 API.getTrips (package:bike_client/API.dart:9:12)
E/flutter ( 7781): #7 _MyHomePageState._getTrips (package:bike_client/main.dart:30:9)
E/flutter ( 7781): #8 _MyHomePageState.initState (package:bike_client/main.dart:40:5)
E/flutter ( 7781): #9 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4355:58)
E/flutter ( 7781): #10 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 7781): #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #13 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #14 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #15 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #16 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter ( 7781): #17 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter ( 7781): #18 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
E/flutter ( 7781): #19 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 7781): #20 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #21 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #22 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #23 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #24 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #25 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #26 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #27 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #28 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter ( 7781): #29 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter ( 7781): #30 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
E/flutter ( 7781): #31 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
E/flutter ( 7781): #32 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 7781): #33 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #34 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #35 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #36 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #37 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #38 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #39 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #40 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #41 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter ( 7781): #42 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter ( 7781): #43 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
E/flutter ( 7781): #44 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
E/flutter ( 7781): #45 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 7781): #46 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #47 Element.updateChild (package:flutter/src/wid
E/flutter ( 7781): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 38760
E/flutter ( 7781): #0 IOClient.send (package:http/src/io_client.dart:33:24)
E/flutter ( 7781): <asynchronous suspension>
E/flutter ( 7781): #1 BaseClient._sendUnstreamed (package:http/src/base_client.dart:176:38)
E/flutter ( 7781): #2 BaseClient.get (package:http/src/base_client.dart:35:7)
E/flutter ( 7781): #3 get.<anonymous closure> (package:http/http.dart:46:36)
E/flutter ( 7781): #4 _withClient (package:http/http.dart:166:20)
E/flutter ( 7781): #5 get (package:http/http.dart:46:5)
E/flutter ( 7781): #6 API.getTrips (package:bike_client/API.dart:9:12)
E/flutter ( 7781): #7 _MyHomePageState._getTrips (package:bike_client/main.dart:30:9)
E/flutter ( 7781): #8 _MyHomePageState.initState (package:bike_client/main.dart:40:5)
E/flutter ( 7781): #9 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4355:58)
E/flutter ( 7781): #10 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 7781): #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #13 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #14 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #15 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #16 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter ( 7781): #17 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter ( 7781): #18 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
E/flutter ( 7781): #19 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 7781): #20 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #21 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #22 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #23 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #24 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #25 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #26 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #27 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #28 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter ( 7781): #29 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter ( 7781): #30 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
E/flutter ( 7781): #31 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
E/flutter ( 7781): #32 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 7781): #33 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #34 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #35 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #36 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #37 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #38 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #39 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #40 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #41 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter ( 7781): #42 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter ( 7781): #43 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
E/flutter ( 7781): #44 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
E/flutter ( 7781): #45 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 7781): #46 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #47 Element.updateChild (package:flutter/src/wid
E/flutter ( 7781): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: SocketException: OS Error: Connection refused, errno = 111, address = localhost, port = 38884
E/flutter ( 7781): #0 IOClient.send (package:http/src/io_client.dart:33:24)
E/flutter ( 7781): <asynchronous suspension>
E/flutter ( 7781): #1 BaseClient._sendUnstreamed (package:http/src/base_client.dart:176:38)
E/flutter ( 7781): #2 BaseClient.get (package:http/src/base_client.dart:35:7)
E/flutter ( 7781): #3 get.<anonymous closure> (package:http/http.dart:46:36)
E/flutter ( 7781): #4 _withClient (package:http/http.dart:166:20)
E/flutter ( 7781): #5 get (package:http/http.dart:46:5)
E/flutter ( 7781): #6 API.getTrips (package:bike_client/API.dart:9:12)
E/flutter ( 7781): #7 _MyHomePageState._getTrips (package:bike_client/main.dart:30:9)
E/flutter ( 7781): #8 _MyHomePageState.initState (package:bike_client/main.dart:40:5)
E/flutter ( 7781): #9 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4355:58)
E/flutter ( 7781): #10 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 7781): #11 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #12 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #13 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #14 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #15 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #16 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter ( 7781): #17 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter ( 7781): #18 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
E/flutter ( 7781): #19 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 7781): #20 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #21 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #22 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #23 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #24 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #25 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #26 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #27 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #28 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter ( 7781): #29 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter ( 7781): #30 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
E/flutter ( 7781): #31 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
E/flutter ( 7781): #32 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 7781): #33 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #34 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #35 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #36 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #37 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #38 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14)
E/flutter ( 7781): #39 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #40 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12)
E/flutter ( 7781): #41 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16)
E/flutter ( 7781): #42 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5)
E/flutter ( 7781): #43 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5)
E/flutter ( 7781): #44 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11)
E/flutter ( 7781): #45 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5)
E/flutter ( 7781): #46 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14)
E/flutter ( 7781): #47 Element.updateChild (package:flutter/src/wid
E/flutter ( 7781): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: SocketException:
AND MUCH MORE!
This error occurs mostly when your android AVD or android device is not connected to internet. Sometimes, the developer tries to access plugin on localhost from android device instead of AVD, in such cases, same error occurs. I hope this solves your problem.
Other scenarios involves port blocked by firewalls on serverside.
Kindly upvote if you find my answer usable.
Learn Cybers
If you use the emulator with localhost. please change the IP address from 127.0.0.1 to 10.0.2.2 in API urls.
to avoid the following problems:
write failed
connection closed before ...
Flutter Doctor Error - SocketException: Write failed (OS Error: Broken pipe, errno = 32)
you need to add the correct parameters in the headers.
In my case these problems occur with uploading images and sending base64 encoded requests.
I solved it by adding the following 'connection' header: 'keep-alive',
final response = await this.httpClient.put(
url,
encoding: Utf8Codec(),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Accept': "*/*",
'connection': 'keep-alive',
'Accept-Encoding' : 'gzip, deflate, br',
},
body: body,
);
it works for me
I had the same problem.
I've connencted my PC to my Phone hotspot, got my ip adress using "ipconfig" and made it as my base URL like this
"http://PC_IP_Adress:8000/api"
In my project audio_service and firebase_messaging not working together.
Error message is:
E/flutter ( 5794): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'void com.ryanheise.audioservice.AudioServicePlugin$BackgroundHandler.init(io.flutter.plugin.common.PluginRegistry$Registrar)' on a null object reference, null) E/flutter ( 5794): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7) E/flutter ( 5794): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33) E/flutter ( 5794): E/flutter ( 5794): #2 FirebaseMessaging.configure (package:firebase_messaging/firebase_messaging.dart:118:16) E/flutter ( 5794): #4 StatefulElement.build (package:flutter/src/widgets/framework.dart:4334:27) E/flutter ( 5794): #5 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4223:15) E/flutter ( 5794): #6 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter ( 5794): #7 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5) E/flutter ( 5794): #8 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11) E/flutter ( 5794): #9 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5) E/flutter ( 5794): #10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter ( 5794): #11 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter ( 5794): #12 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14) E/flutter ( 5794): #13 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter ( 5794): #14 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter ( 5794): #15 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16) E/flutter ( 5794): #16 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter ( 5794): #17 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5) E/flutter ( 5794): #18 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5) E/flutter ( 5794): #19 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter ( 5794): #20 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter ( 5794): #21 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14) E/flutter ( 5794): #22 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter ( 5794): #23 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter ( 5794): #24 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14) E/flutter ( 5794): #25 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter ( 5794): #26 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter ( 5794): #27 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16) E/flutter ( 5794): #28 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter ( 5794): #29 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5) E/flutter ( 5794): #30 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11) E/flutter ( 5794): #31 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5) E/flutter ( 5794): #32 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter ( 5794): #33 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter ( 5794): #34 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14) E/flutter ( 5794): #35 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter ( 5794): #36 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter ( 5794): #37 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14) E/flutter ( 5794): #38 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter ( 5794): #39 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter ( 5794): #40 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16) E/flutter ( 5794): #41 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter ( 5794): #42 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5) E/flutter ( 5794): #43 StatefulElement._firs E/flutter ( 5794): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: MissingPluginException(No implementation found for method FcmDartService#initialized on channel plugins.flutter.io/firebase_messaging_background) E/flutter ( 5794): #0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:319:7) E/flutter ( 5794): E/flutter ( 5794): #1 _fcmSetupBackgroundChannel (package:firebase_messaging/firebase_messaging.dart:50:21) E/flutter ( 5794): #2 _AsyncAwaitCompleter.start (dart:async-patch/async_patch.dart:45:6) E/flutter ( 5794): #3 _fcmSetupBackgroundChannel (package:firebase_messaging/firebase_messaging.dart:23:32) E/flutter ( 5794): #4 _runMainZoned.. (dart:ui/hooks.dart:239:25) E/flutter ( 5794): #5 _rootRun (dart:async/zone.dart:1126:13) E/flutter ( 5794): #6 _CustomZone.run (dart:async/zone.dart:1023:19) E/flutter ( 5794): #7 _runZoned (dart:async/zone.dart:1518:10) E/flutter ( 5794): #8 runZoned (dart:async/zone.dart:1502:12) E/flutter ( 5794): #9 _runMainZoned. (dart:ui/hooks.dart:231:5) E/flutter ( 5794): #10 _startIsolate. (dart:isolate-patch/isolate_patch.dart:307:19) E/flutter ( 5794): #11 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)*
Someone has any idea about this error?
Thanks!