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

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);

Related

showSnackBar crash : Null check operator used on a null value. Error thrown null

Hello firebase crashlytics report this crash, but I don't understand how to resolve this
Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: Null check operator used on a null value. Error thrown null.
at State.context(framework.dart:949)
at analyse2State.sauvegarde.<fn>.<fn>(tableau_de_bord.dart:2629)
in this line :
ScaffoldMessenger.of(context).showSnackBar
Future.delayed(const Duration(seconds: 10), () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: const Text("XXX"),
action: SnackBarAction(
label: 'XXX', onPressed: XXX),
));
});

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.

Error Message: A nullable expression can't be used as a condition

How to fix this. Error message A nullable expression can't be used as a condition.
Try checking that the value isn't 'null' before using it as a condition.
This is my code.
floatingActionButton: FloatingActionButton(
onPressed: () => _webcamVideoElement.srcObject.active ? _webcamVideoElement.play() : _webcamVideoElement.pause(),
tooltip: 'Start stream, stop stream',
child: Icon(Icons.camera_alt),
),
);
}
Try this:
onPressed: () => _webcamVideoElement?.srcObject?.active ? _webcamVideoElement.play() : _webcamVideoElement.pause(),
It's pretty simple, before each property that can be null you should check null, try to click "Quick Fix" with Ctrl+. (Mac Command+.) to see what is suggested and that will probably fix it.
Also you didn't showed all your code, so I only can guess you are dealing with (VideoElement)[https://api.flutter.dev/flutter/dart-html/VideoElement-class.html] in that case your srcObject can (be null)[https://api.flutter.dev/flutter/dart-html/MediaElement/srcObject.html] in this case pretty close to what #Mohammad said, I suggest you to try this:
floatingActionButton: FloatingActionButton(
onPressed: () => _webcamVideoElement.srcObject?.active ? _webcamVideoElement.play() : _webcamVideoElement.pause(),
tooltip: 'Start stream, stop stream',
child: Icon(Icons.camera_alt),
),
);
}

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.

Can any one tell what is wrong with this Dialog?

I have this dialog But when I call it it gives me this error :
Unhandled Exception: 'package:flutter/src/widgets/localizations.dart': Failed assertion: line 453 pos 12: 'context != null': is not true.,
My Code:
return showDialog(
context: context,
child: AlertDialog(
title: Text(title),
content: Text(msg),
actions: [cancel, ok],
),
);
The error message tells you exactly what's wrong: your variable context is null.
You need to provide a context that is not null.
You should also provide builder instead of a child, because that way to build a dialog is deprecated for good reason.