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

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.

Related

Navigate to same page with new data on GETX navigation

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

The following _TypeError was thrown building: type 'MappedListIterable<AkcijeDokument, Widget>' is not a subtype of type 'Widget'

I am fetching list of documents from api and every document has property actions(List of actions). Documents are displayed in a List and i want to display actions in ActionPane/SlidableAction an I get an error: "Another exception was thrown: type 'MappedListIterable<AkcijeDokument, dynamic>' is not a subtype of type 'Widget'".
And error "The following _TypeError was thrown building:
type 'MappedListIterable<AkcijeDokument, dynamic>' is not a subtype of type 'Widget'"...
When I print actions like this params[index].akcije.map((ak) => print(ak.nazivAkcije)) I get response: "I/flutter (25152): Potvrdi
I/flutter (25152): Odbij", "Potvrdi" and "Odbij" are the actions that i need to fetch and display in List for each document.
And here is the code where I'm trying to display the actions
params[index].akcije.map<Widget>(
(ak) => SlidableAction(
onPressed: (context) {},
icon: Icons.bookmark,
backgroundColor: Colors.red,
label: ak.nazivAkcije,
),
),,```
First error is because you use map<Widget>() when the type you have in. a map is {AkcjeDokument, dynamic}
If what you want is to just print them use .map()
You can try:
List<Widget> ak_list;
for (var ak in params[index].akcije) {
ak_list.add(SlidableAction(
onPressed: (context) {},
icon: Icons.bookmark,
backgroundColor: Colors.red,
label: ak.nazivAkcije,
));
}
and use
//example after init
Column(children: ak_list);

Flutter Form Builder with Date Picker. No named parameter with the name 'anchorPoint'. anchorPoint: widget.anchorPoint,

I have a strange problem, I used Flutter Form Builder before and I can't fix any issues but when I use it in other project this is occurred with me.
I cleaned my project and run flutter pub get then flutter run but no thing is changed
this is complete error:
Error Image
FormBuilder(
key: _formKey,
child: Column(
children: [
FormBuilderTextField(
name: 'age',
decoration: const InputDecoration(
labelText:
'This value is passed along to the [Text.maxLines] attribute of the [Text] widget used to display the hint text.',
),
onChanged: (value) {},
// valueTransformer: (text) => num.tryParse(text),
keyboardType: TextInputType.number,
),
],
),
)
Error
../../FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_form_builder-7.2.1/lib/src/fields/for
m_builder_date_time_picker.dart:355:7: Error: No named parameter with the name 'anchorPoint'.
anchorPoint: widget.anchorPoint,
^^^^^^^^^^^
../../FlutterDev/flutter/packages/flutter/lib/src/material/date_picker.dart:133:19: Context: Found this
candidate, but the arguments don't match.
Future<DateTime?> showDatePicker({
^^^^^^^^^^^^^^
../../FlutterDev/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_form_builder-7.2.1/lib/src/fields/for
m_builder_date_time_picker.dart:373:7: Error: No named parameter with the name 'anchorPoint'.
anchorPoint: widget.anchorPoint,
^^^^^^^^^^^
../../FlutterDev/flutter/packages/flutter/lib/src/material/time_picker.dart:2413:20: Context: Found this
candidate, but the arguments don't match.
Future<TimeOfDay?> showTimePicker({
^^^^^^^^^^^^^^
add form_builder_extra_fields: ^8.2.0 dependencies.

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.

Image does not show on leading part of list tile when using Circle Avatar and back ground image

I am building this app and just have a small UI problem. I am using a ListView builder. On the leading part of the tile, I want a circular icon to display with the desired image.
I believe my implementation is correct but when I run my code the circle avatar does come out on the leading part of the tile but it does not display the desired image. Instead, it just shows a blue circle on the leading end of each tile.
I am also getting an exception from the terminal. I will attach my code and the exception that I am getting. I would really appreciate suggestions from anyone. Thank you all!
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
List<String> titles = ["Covid-19 Cases", "Covid-19 Vaccine Tracker",
"Dr. John Campbell Youtube Channel", "Medcram YouTube Channel"];
List<String> files = ["cases.png", "vaccineIMG.png", "dr.johncampbell.png",
"Medcram.png"];
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.black54,
appBar: AppBar(
backgroundColor: Colors.redAccent,
title: Text("Your Covid-19 Briefing"),
),
body: ListView.builder(
itemCount: titles.length,
itemBuilder: (context, index) {
return Card(
child: ListTile(
onTap: () {
_launchUrl(index);
},
title: Text(
titles[index],
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
letterSpacing: 1.0,
color: Colors.black,
),
),
leading: CircleAvatar(
backgroundImage: AssetImage('assets/${files[index]}'),
),
),
);
}
),
),
);
}
_launchUrl(index) async {
List<String> _urlsToLaunch = [
"https://www.worldometers.info/coronavirus/",
"https://www.nytimes.com/interactive/2020/science/coronavirus-vaccine-tracker.html",
"https://www.youtube.com/c/Campbellteaching/videos/",
"https://www.youtube.com/c/Medcram/videos"
];
if (await canLaunch(_urlsToLaunch[index])) {
await launch(_urlsToLaunch[index]);
} else {
throw "Could not open $_urlsToLaunch";
}
}
}
Error:
════════ Exception caught by image resource service ════════════════════════════════════════════════
The following assertion was thrown resolving an image codec:
Unable to load asset: assets/cases.png
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:664:31)
#2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:648:14)
#3 ImageProvider.resolveStreamForKey.<anonymous closure> (package:flutter/src/painting/image_provider.dart:501:13)
...
Image provider: AssetImage(bundle: null, name: "assets/cases.png")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#e7274(), name: "assets/cases.png", scale: 1.0)
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
Unable to load asset: assets/vaccineIMG.png
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
Unable to load asset: assets/dr.johncampbell.png
════════════════════════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by image resource service ════════════════════════════════════════════════
Unable to load asset: assets/Medcram.png
════════════════════════════════════════════════════════════════════════════════════════════════════
pubspec.yaml file:
name: coronavirus_news_updates
description: A new Flutter application.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
url_launcher: ^5.4.11
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
Have you included your assets in your pubspec.yaml file?
flutter:
assets:
- assets/your_image_name.png
or to incude the entire folder:
flutter:
assets:
- assets/