The named parameter isn't defined (data persistence) - flutter

There is my error , I want to solve this problem
enter image description here
The named parameter 'itemCount' isn't defined.
The named parameter 'itemBuilder' isn't defined.

You are using the default constructor that has different named parameters, you need to use ListView.builder() to use those named arguments.

Hello Syed i might thing that your try to use Listview() on Place of Listview.builder()....
ListView(
children: [
Container(),
],
),
ListView.builder(
itemCount: 2,
itemBuilder: (context, index){
return Container();
}
),

A ListView() don't have thies properties but a ListView.builder() have they.
list view have children and not itembuilder.

Related

Flutter : Display data in listview with static string and scrollable array

My data is like this:
I want to display it like this:
In the example, the title and subtitle are static. But in my case, it is dynamic. How do I achieve this UI? I tried like putting it in a ListView.builder with horizontal scrolling. But again do I need another ListView.builder to show restaurant list from rests array? Or any other ways to do this?
That can depend on your layout.
You can look at the use case below.
Using ListView + ListView:
If you want to give your second ListView full height.
ListView(
children: [
// Other widgets ...
ListView.builder(
shrinkWrap: true, // <-- Set this to true
physics: ScrollPhysics(), // <-- Also change physics
itemBuilder: ...,
),
],
)
YES; You can use listview to implement this functionality.
demo(){
List<Map> restaurantArray = [
{"name":"breakfase 1","cover":"http://......."},
{"name":"breakfase 2","cover":"http://......."},
{"name":"breakfase 3","cover":"http://......."},
{"name":"breakfase 4","cover":"http://......."},
{"name":"breakfase 5","cover":"http://......."},
];
return ListView.builder(
itemCount: restaurantArray.length,
itemBuilder: (ctx,index){
// return your cell with data
return Container(
child: Text(restaurantArray[index]["name"].toString()),
);
}
);
}

Flutter Riverpod listview index length

I have a listview which is using flutter_riverpod. The listview have 2 variable.
First variable is word text and second variable is length of index.
ListView.builder(
itemCount: ref.watch(itemsProvider).length,
itemBuilder: (BuildContext context, int index) {
return Row(
children: [
Text(ref.watch(itemsProvider)[index]),
Text(ref.watch(itemsProvider)[index].length),
],
);
},
),
I am using this listview.builder. the first text of Row is working but second text of Row is not working.
The error:
the argument type 'int ' can't be assigned to the parameter type 'string'
How can I solve this problem. The is no problem in widget. I am using consumerwidget, ref and widgetref. and scopped runapp.
Text widget seeks from String, Use string format
Text("${ref.watch(itemsProvider)[index].length}"),
Also, you can use .toString()
More about dart-core

Flutter GridView "type 'List<Widget> is not a subtype of type Widget"

it feels like I am doing something out of the ordinary!
I have 2 sub collections (subColl1 and subColl2) within 1 Collection in firebase firestore.
I get access to them with CollectionGroup
children: [
FutureBuilder<List<dynamic>>(
//<QuerySnapshot>(
future: Future.wait([
FirebaseFirestore.instance.collectionGroup('subColl1').get(),
FirebaseFirestore.instance.collectionGroup('subColl2').get(),
]),
Now I want to display both collections into a GridView.count() here:
return GridView.count(
restorationId: 'dashboardGridView',
crossAxisCount: 2,
mainAxisSpacing: 8,
crossAxisSpacing: 8,
padding: const EdgeInsets.all(8),
childAspectRatio: 1,
children: <Widget>[
snapshot.data[0].docs.map<Widget>((document) {
return _DashboardGridViewItem(
document: document,
);
}).toList(),
snapshot.data[1].docs.map<Widget>((document) {
return _DashboardGridViewItem(
document: document,
);
}).toList(),
],
);
I tried individually snapshot.data[0].... and snapshot.data[1].... and they worked. But doing it like the above (which is both at the same time) throws an error type 'List<Widget>' is not a subtype of type 'Widget'
I understand the error but there must be a way to display both collections in the same gridview...
you will notice that I pass a document to a private method _DashboardGridViewItem(document: document), which is used to display information from the document. The other way I was thinking is to use a for loop surrounding the gridview and use the index i inside the snapshot.data[i]..... but then am I not returning 2 Gridviews???
need direction..
It is expecting a [Widget, Widget, Widget ..], you are instead giving [[Widgets], [Widgets]]
Simplest way to solve is to use the spread operator '...' as in below:
children: <Widget>[
...snapshot.data[0].docs.map<Widget>((document) {
return _DashboardGridViewItem(
document: document,
);
}).toList(),
...snapshot.data[1].docs.map<Widget>((document) {
return _DashboardGridViewItem(
document: document,
);
}).toList(),
],

error: The return type 'NetworkImage' isn't a 'Widget', as required by the closure's context

import 'package:carousel_pro/carousel_pro.dart';
import '../models/post_model.dart';
Carousel(
animationDuration: null,
images: [
ListView.builder(
itemCount: posts[index].MediaImage.length,
physics: ScrollPhysics(),
itemBuilder: (context, index) {
return NetworkImage(posts[index].MediaImage[index].image);
}, ) ],) ,
I am trying to show multiple images from Network.
Does anybody know why i am getting this error?
Return the following in your itemBuilder
return Image.network(posts[index].MediaImage[index].image);
You cant use a ListView.builder inside of carousel, why would you even use that ??
Carousel expect NetworkImage only as a string of url and placing any other widget inside of that will land you to this error.
0
import 'package:carousel_pro/carousel_pro.dart';
import '../models/post_model.dart';
Carousel(
animationDuration: null,
images: [NetworkImage(posts[i].MediaImage[i].image.toString(),],) ,
This is the correct way , .toString(), is often required as NetworkImage expects a String.
If you have multiple images use :
for(int i =0;i<="please specify your length here", i++);
I have added i in place of index.
Carousel never takes anyother Widget than AssetImage or NetworkImage directly.
It's a bit confusing from the way that Flutter names things, but NetworkImage is an ImageProvider, not a Widget (which actually shows the image). The widget you want is Image, which can be constructed from an ImageProvider, or can be constructed from an URL directly via its Image.network constructor.

How to make this containers in flutter depending on length from api?

I try to make this column but data come form API, so i need solve to this problem ?
You can used Listview with builder
ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
ProjectModel project = snapshot.data[index];
return Column(
children: <Widget>[
// Widget to display the list of project
],
);
},
);
here snapshot.data is coming from future API for an example if your API gives list of object you can use FutureBuilder to wait until request is complete. And fetch snapshot data to ListView.builder here docs about future builder you can find clear idea from this