List connectProfile = [];
connectProfile = response['data']['other_profile_verified'];
GridView.builder(
shrinkWrap: true,
dragStartBehavior: DragStartBehavior.down,
scrollDirection: Axis.horizontal,
gridDelegate:
const SliverGridDelegateWithFixedCrossAxisCount(
childAspectRatio: 3 / 2.2,
crossAxisSpacing: 20,
mainAxisSpacing: 5,
crossAxisCount: 1,
),
itemCount: connectProfile.length,
itemBuilder:
(BuildContext context, int index) {
return displayCardConatiner(
MediaQuery.of(context).size.width,
MediaQuery.of(context).size.height,
connectProfile[index],
index);
// ProfileCard(
// item: connectProfile[index],
// );
}),
i get data(Array) from API like this,how can i apply infinite pagination on this data.
first time only 10 data display , after that user reach to last profile ,next 10 data will be display.
how want to apply pagination on grid view.
Related
How to parse and json to websocket data in flutter
StreamBuilder(
stream: _channel.stream,
builder: (context, snapshot) {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.hashCode.bitLength,
scrollDirection: Axis.vertical,
physics: NeverScrollableScrollPhysics(),
itemBuilder: (context, index){
// final List documents = snapshot.data.hashCode.bitLength as List;
// final Map<String, dynamic> doc = snapshot.data.hashCode.bitLength as Map<String, dynamic>;
// final course = snapshot.data!.hashCode.bitLength;
return Card(
child: Container(
child: Column(
children: [
Text('Recieve'),
Text(snapshot.hasData ? '${snapshot.data}' : '')
],
),
),
);
});
},
),
i have get data and show in list inside screen but how to parse these data to websocket using json to the server
First of all you can use this package to send and get data
web_socket_channel: ^2.1.0
https://pub.dev/packages/web_socket_channel
Plus For parsing json data you can read this document
https://docs.flutter.dev/development/data-and-backend/json
I am working on a test application in Dart. The application is used for displaying and inserting data into a database hosted with 000webhost.com
I am displaying my json data into a table in my app. I would like all the columns to be inside of one table. With my current code it is displaying every column inside of a brand new table
like shown here:
Below is the relevant code for my project:
class ViewData extends StatelessWidget{
final String url = 'https://fourieristic-thousa.000webhostapp.com/index.code.php?action=view';
Future<List<dynamic>> fetchData() async {
var result = await http.get(
Uri.parse(url),
);
print(json.decode(result.body));
return json.decode(result.body);
}
// First entry of each column.
String _test(dynamic test, int index){
return test[index]['testColumn'];
}
// Second entry of each column.
int _test2(dynamic test, int index){
return json.decode(test[index]['testColumn2']);
}
// Third entry of each column (Will some day be a delete function)
int _id(dynamic test, int index){
return json.decode(test[index]['ID']);
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Test data table'),
),
body: Container(
child: FutureBuilder<List<dynamic>>(
future: fetchData(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if(snapshot.hasData){
return ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: DataTable(
columns: const <DataColumn>[
DataColumn(
label: Text(
'Test',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
DataColumn(
label: Text(
'Test2',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
DataColumn(
label: Text(
'Delete',
style: TextStyle(fontStyle: FontStyle.italic),
),
),
],
rows: <DataRow>[
DataRow(
cells: <DataCell>[
DataCell(
Text(_test(snapshot.data, index).toString())
),
DataCell(
Text(_test2(snapshot.data, index).toString())
),
DataCell(
Text(_id(snapshot.data, index).toString())
)
],
),
],
),
);
}
);
} else {
return Center(child: CircularProgressIndicator());
}
},
),
),
);
}
}
I have tried looking for an answer online with no result. I have also tried rewriting my code to attempt to find anything wrong with it. I understand why the app is showing the data in individual tables, but I can not find a way to fix it.
You claim to know what the problem is so I won't go in depth, but the main issue is your ListView.builder; there is no reason to have it there. Instead, you should replace the code between if(snapshot.hasData){ and return SingleChildScrollView( with something like this:
List<DataRow> dataRows = [];
for (var index = 0; index < snapshot.data.length; index++) {
dataRows.add(
DataRow(
cells: <DataCell>[
DataCell(
Text(_test(snapshot.data, index).toString())
),
DataCell(
Text(_test2(snapshot.data, index).toString())
),
DataCell(
Text(_id(snapshot.data, index).toString())
),
],
),
);
}
and then put the dataRows variable in the rows: field of your DataTable. Your tree should end up being Scaffold -> Container -> FutureBuilder -> SingleChildScrollView -> DataTable. This way you won't be building a new table for every entry.
```{"Piece": "[{\"sno\":7,\"valueName\":\"3\",\"value\":\"200\"},{\"sno\":7,\"valueName\":\"3\",\"value\":\"200\"},{\"sno\":7,\"valueName\":\"3\",\"value\":\"200\"}]",
"Caret": "[{\"sno\":1,\"valueName\":\"18k\",\"value\":\"1000\"},{\"sno\":1,\"valueName\":\"18k\",\"value\":\"1000\"},{\"sno\":1,\"valueName\":\"18k\",\"value\":\"1000\"},{\"sno\":1,\"valueName\":\"18k\",\"value\":\"1000\"}]"
}```
I have a json response from server like above. and I want to create dropdownbuttons dynamically in a way that how many keys are available like 'Caret' and 'piece' in json, it will create the same no of dropdown and each key has its own list and I want to deploy that list inside the drop down. and when I select any valueName like '18k','22k', it will return value like '1000','2000'.
please help me.
I tried...
Container(
padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0.0),
child: ListView.builder(
itemCount: data2.keys.length,
primary: false,
shrinkWrap: true,
itemBuilder: (context, i) {
List valueList;
List attributeNameList= List();
data2.forEach((key, value) {attributeNameList.add(key);valueList=jsonDecode(value);});
return DropdownButton<dynamic>(
items: valueList.map((map) {
return DropdownMenuItem(
child: Text(map['valueName']),
value: map['value'],
);
}).toList(),
onChanged: (value) {
print(value);
},
);
},
),
),```
I'm trying to display all the values from retrieved from an API request.
Here's what it's showing at the moment:
I'm using a listview builder for the page. The JSON can be retrieved from this link: Here
This is my entire code for the page: Code
The error is in your ListViewBuilder:
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: _ListFamilyPageState.data.body.family.length,
itemBuilder: (context, index) {
return Container(
height: 74.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topRight: const Radius.circular(20.0),
bottomRight: const Radius.circular(20.0)),
),
width: MediaQuery.of(context).size.width - 50.0,
child: Center(
child: Text(
data.body.friends[index].id.toString(),
style:
TextStyle(fontSize: 24.0),
)));
},
)
You specified that there are family.length items (in your data: 15),
but you are pulling actual data from friends[index] (8 items in your data).
This gives you RangeError when rendering item at index 8.
On top of that: you use static data in your state:
class _ListFamilyPageState extends State<ListFamily> {
static Relations data;
// ...
}
Don't do that.
You've set the itemCount attribute of the ListView with _ListFamilyPageState.data.body.family.length and you've use the index of it's builder with another list data.body.friends[index].id.toString()
I don't think both have the same number of elements
I'm working on flutter app in which I want to show feeds, I want to show 1st list(Horizontal list) with 4 workouts, 2nd list (Vertical list) with 4 posts, 3rd list (Horizontal list) with 4 coaches and 4th list again 4 posts. At the end of list there is 'Load More' button and after click on button again repeating 1st step i.e. 4 workouts, 4 Posts, 4 Coaches and 4 Posts. My question is What is the best way to display this type of view.
Video For clear my points
Here is an example of what you want to achieve:
List<List<String>> lists = [["A1","A2","A3","A4","A5"],["B1","B2","B3"],["C1","C2","C3","C4","C5"],["D1","D2","D3"]];
Widget buildCard(String text) {
return Container(
margin: EdgeInsets.all(4.0),
padding: EdgeInsets.all(40.0),
alignment: Alignment.center,
color: Colors.lightGreenAccent,
child: Text(text),
);
}
Widget buildHorizontalList(List<String> sublist) {
return SizedBox(
height: 200.0,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: sublist.length,
itemBuilder: (context, index) => buildCard("${sublist[index]}"),
),
);
}
Widget buildVerticalList(List<String> sublist) {
return ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: sublist.length,
itemBuilder: (context, index) {
return buildCard("${sublist[index]}");
},
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: lists.length + 1,
itemBuilder: (context, index) {
if (index <= lists.length - 1) {
return index.isEven ? buildHorizontalList(lists[index]) : buildVerticalList(lists[index]);
}
return RaisedButton(
child: Text('Load More'),
onPressed: () {
setState(() {
lists.addAll([["X1","X2","X3","X4","X5"],["Y1","Y2","Y3"]]);
});
},
);
}),
);
}
Edit: I added the Load More button functionality, basically the button just update the 'lists' variable (a list that contains all the sublists). Then the ListViews are being build according to the 'lists' content.
Can't you, instead of showing every listview within another listview, just show it all within a SingleChildScrollView, and then just add all the listviews to a row widget.
SingleChildScrollView(
child: Column(
children<widget>[
// Put listviews here.
],
),
),