Navigate to same page with new data on GETX navigation - flutter

GetPage(
name: _Paths.PRODUCT_DETAILS_PAGE,
page: () => const ProductDetailsPageView(),
binding: ProductDetailsPageBinding(),
middlewares: [
ProductDetailsMiddleware(),
],
),
Navigate to ProductDetailsPage from ProductDetailsPage with some new data using GetMiddleware by parameters:
Get.toNamed(
Routes.PRODUCT_DETAILS_PAGE,
preventDuplicates: true,
parameters: {
'model': json.encode(product),
},
);
and this navigation continue by several times.
After that Navigate to back constantly with different previous data
But when I second time navigate this page an error happened like:
I/flutter (22387): The widget on which setState() or markNeedsBuild() was called was:
I/flutter (22387): Obx
I/flutter (22387): The widget which was currently being built when the offending call was made was:
I/flutter (22387): Builder

Related

Flutter State not getting updated

i am trying to comment section in social media app in android,the issue is after making the post comment ,the newly added comment is not showing in real time,the state is not getting updated , i tried to check the order of function calls by making print data in console,
console log
I/flutter ( 2069): comment posted succesfully
10
I/flutter ( 2069): getcomments
I/flutter ( 2069): setstate called
)),
GestureDetector(
onTap: () async {
await CommentService().postComment(
commentText: controller.text, postid: widget.postid);
await CommentService().getCommentsdata(post_id: widget.postid);
setState(() {
controller.clear();
print('setstate called');
});
},

type 'Null' is not a subtype of type 'String' of 'function result' when update the provider model

Provider version and dart
provider: ^6.0.1
sdk: ">=2.12.0 <3.0.0"
I have two screens.
Screen A - I have a form. when you tap on the textbox it will open a Screen B Full screen Modal.
Screen B - you will choose an item from the list in and return back to Screen A.
In the Screen A textbox i have wrapped with consumer method.
Consumer<AgentModel>( // <--- Consumer
builder: (context, agentModel, child) {
agentController.text = agentModel.name.toString();
return AppInputWrapper(
marginBottom: 'small',
widgets: Column(
children: [
TextFormField(
style: appInputStyle,
keyboardType: TextInputType.text,
autocorrect: false,
enableSuggestions: false,
decoration: AppInputStyleDecoration.textFieldStyle(hintTextStr: "Agent"),
controller: agentController,
validator: (value) {
return validateAgent(value);
},
readOnly: true,
onTap: (){
Navigator.push( context, MaterialPageRoute( builder: (context) => AgentFormComponent(),),);
},
),
],
),
);
}
)
When the first instance it comes from screen B to screen A its not loading the value from provider. i get the following error.
======== Exception caught by widgets library =======================================================
The following _TypeError was thrown building Consumer<AgentModel>(dirty, dependencies: [_InheritedProviderScope<AgentModel?>]):
type 'Null' is not a subtype of type 'String' of 'function result'
The relevant error-causing widget was:
Consumer<AgentModel> file:///Users/soundharraj/StudioProjects/LHMarine/lib/screens/jobs/create/form.dart:389:13
When the exception was thrown, this was the stack:
#0 _Location.file (package:flutter/src/widgets/widget_inspector.dart)
#1 _Location.toJsonMap (package:flutter/src/widgets/widget_inspector.dart:2844:15)
#2 _Location.toJsonMap.<anonymous closure> (package:flutter/src/widgets/widget_inspector.dart:2853:42)
#3 MappedListIterable.elementAt (dart:_internal/iterable.dart:412:31)
#4 ListIterator.moveNext (dart:_internal/iterable.dart:341:26)
...
====================================================================================================
Reloaded 1 of 1128 libraries in 592ms.
I am not sure how to check the provider value is NULL. its turn the string.
Thanks
Wrap your TextFormField with Gesturedetector on write your function on the ontab.

Why showcaseview throws error on first try?

Hey I am using ShowCaseView in my Flutterapp. When I first open my app, after registration there is no showcase, not even the icon which should be 'showcased' is shown. But when I am closing the app and opening it again it works just fine.
Thats the code referring to showcase:
class _HomeSearchPageState extends State<HomeSearchPage> {
final keyOne = GlobalKey();
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback(
(_) => ShowCaseWidget.of(context).startShowCase([
keyOne,
]),
);
}
And now the scaffold:
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(getTopBarSize()),
child: AppBar(
automaticallyImplyLeading: false,
title: Text(
'username',
style: TextStyle(fontSize: 14),
),
actions: <Widget>[
Showcase(
key: keyOne,
description: 'test',
child: IconButton(
icon: Icon(Icons.search),
onPressed: () {
showSearch(context: context, delegate: DataSearch())
.whenComplete(() => setName());
}),
),
],
),
),)
I did exactly the same as in the Github example but still it throws this error the first time:
════════ Exception caught by widgets library ═══════════════════════════════════
The following NoSuchMethodError was thrown building IconTheme(color: Color(0xffffffff)):
The getter 'activeWidgetIds' was called on null.
Receiver: null
Tried calling: activeWidgetIds
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
When the exception was thrown, this was the stack
#0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5)
#1 ShowCaseWidget.activeTargetWidget
package:showcaseview/showcase_widget.dart:51
#2 _ShowcaseState.showOverlay
package:showcaseview/showcase.dart:171
#3 _ShowcaseState.didChangeDependencies
package:showcaseview/showcase.dart:164
#4 StatefulElement._firstBuild
package:flutter/…/widgets/framework.dart:4786
════════ Exception caught by rendering library ═════════════════════════════════
Each child must be laid out exactly once.
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by scheduler library ═════════════════════════════════
Exception: Please provide ShowCaseView context
════════ Exception caught by widgets library ═══════════════════════════════════
'package:flutter/src/widgets/framework.dart': Failed assertion: line 6224 pos 12: '_children.contains(child)': is not true.
The relevant error-causing widget was
AppBar
lib\Views\HomeSearchPage.dart:182
════════════════════════════════════════════════════════════════════════════════
These errors are kind a looped, so the debug console shows them all the time.
The only difference between the first app opening and the second one is: In the first one the user enters a registrationpage and after this he enters the page with the showcaseview. In the second the user enters directly the page with the showcaseview. How can this affect the showcase and more accurate why does this throw the errors?
Not sure if we share a similar issue but maybe my answer will help you somehow :). The issue occurs when I navigate to the page where I have Showcase widget, but it does not occur when I navigate "back" to the page from the other page.
Maybe you can check this page "This error is thrown if you haven't wrapped your widget with ShowCaseWidget. This is not the problem with the package itself."
Thus, I tried raising the level of the ShowCaseWidget in the main.dart and the issue was solved.
void main() {
// runApp(MyApp());
runApp(
ShowCaseWidget(
autoPlay: false,
autoPlayDelay: Duration(seconds: 8),
autoPlayLockEnable: false,
builder: Builder(
builder: (context) => MyApp(),
),
onStart: (index, key) {
print('onStart: $index, $key');
},
onComplete: (index, key) {
print('onComplete: $index, $key');
},
),
);
}
So far the app still works well. I will report again here in case any issues occur.

Flutter Error "Could not navigate to inital root in my app"

Performing hot restart...
Syncing files to device Android SDK built for x86...
Restarted application in 2,632ms.
I/flutter (17581): ══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════
I/flutter (17581): The following message was thrown:
I/flutter (17581): Could not navigate to initial route.
I/flutter (17581): The requested route name was: "/home"
I/flutter (17581): There was no corresponding route in the app, and therefore the initial route specified will be
I/flutter (17581): ignored and "/" will be used instead.
I/flutter (17581): ════════════════════════════════════════════════════════════════════════════════════════════════════
I just want to override the '/' route for now, '/home' need this to be my first screen that message appear. some help me, I'm the new guy to flutter
My code here
import 'package:flutter/material.dart';
import 'package:worldtime/pages/choose_location.dart';
import 'package:worldtime/pages/home.dart';
import 'package:worldtime/pages/loading.dart';
void main() => runApp(MaterialApp(
initialRoute: '/home',
routes: {
'/': (context) => Loading(),
'home': (context) => Home(),
'/location': (context) => ChooseLocation()
},
));
You mis-typed the route. You have written route as:
'home': (context) => Home(),
You need to change that to:
'/home': (context) => Home(),

How to fix "the method 'cancel' called on null" while working with http requests flutter

I'm trying to athenticate using APIs from a flutter app but i get these errors everytime i click Login Button
final resp = await http.post("http://192.168.73.5/myserv/login.php", body: {
"login": "login",
"apid": "re0b53fd92d4b1593db1880az322d66ea9d4",
"email": _email,
"pass": _password,
});
var __data =json.decode(resp.body);
if (__data.length == 0) {
final snackbar = SnackBar(
content: Text('Server error'),
);
scaffoldKey.currentState.showSnackBar(snackbar);
} else if (__data[0]['resp'] == 'error') {
final snackbar = SnackBar(
content: Text('Password or email is incorrect!'),
);
scaffoldKey.currentState.showSnackBar(snackbar);
} else if (__data[0]['resp'] == 'sucess') {
final snackbar = SnackBar(
content: Text('You are logged in'),
);
scaffoldKey.currentState.showSnackBar(snackbar);
Navigator.of(context)
.pushReplacement(MaterialPageRoute(builder: (context) => HomeApp()));
}
}
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (29517): The following NoSuchMethodError was thrown while finalizing the widget tree:
I/flutter (29517): The method 'cancel' was called on null.
I/flutter (29517): Receiver: null
I/flutter (29517): Tried calling: cancel()
I/flutter (29517): When the exception was thrown, this was the stack:
My suggestion would be to take a look to your dispose method. There you might notice a statement calling a cancel method on something that was never initiated or used, only declared. In my case I got this error because at the disposed method I was trying to cancel a subscription to a Firebase service that I had not used. I never attached a listener to it, therefore when trying to cancel it, Flutter complained saying "the method cancel was called on null". I deleted the unnecessary line at dispose method and the error resolved. Hope the explanation helps somebody.