Flutter: ListView.builder not showing data - flutter

Well i'm using List view builder to show data from a specific API but it shows nothing even that the response body contains data.
CODE LINK !!

Did it help you?
void initState(){
super.initState();
myList = getTrendingGamesBloc..getTrendingGames();
}

Related

LateInitializationError: Field '_splitScreenMode' has not been initialized flutter

I'm facing this "LateInitializationError: Field '_splitScreenMode' has not been initialized." error, when I run the flutter app. can you help me?
When working with the late keyword. You must initialize it before using it. Most of the time, you initialized it within the initState. Take a look at how I did it below:
late bool _splitScreenMode; // I used bool type for this example
// setting/initializing the _splitScreenMode
#override
void initState() {
_splitScreenMode = true;
super.initState();
}
For more help with any questions, leave a comment below.

How do I make the update page display data according to the index and the data can be saved to the database when updating?

I'm a new flutter user, so this time I want to explain my problem. I made a data update. When I open the edit data page, the data cannot appear automatically according to the index, then when an update is made, the data that has been entered cannot be saved. Here's the full source code of my flutter lib.
Link source code: https://github.com/azmi1700018002/akm-front
the update form does not appear automatically
After updating the data cannot be stored in the database
For starters instead of
#override
void initState() {
super.initState();
_nama_debiturController.text;
_alamatController.text;
_no_telpController.text;
_no_ktpController.text;
_no_selularController.text;
}
do
#override
void initState() {
super.initState();
_nama_debiturController.text = nasabah.debiturElement;
_alamatController.text = nasabah.alamatElement;
_no_telpController.text = nasabah.telp;
_no_ktpController.text = nasabah.ktp;
_no_selularController.text = nasabah.selular;
}
Also dispose them in dispose method (same as initstate)
#override
void dispose() {
_controller.dispose();//dispose all of them
super.dispose();
}
I guess the object values will get updated in the validator of the textfield, so try that if it does not work write in the comments.

Api data null whe nthe pages load even i use initState

im using post method to get api data/response.body in initState and i get all the response/data then i put it in my variables surveyData, but when i load the pages with widget looped by the response.body length it goes error and say response.body.length is null but when i save the text editor/ hot reload, all the data entered and it's not null anymore and the widget appear.
fyi: the http.post method is my own function not from import 'package:http/http.dart' as http; so don't mind it
Variables that contain the response
dynamic surveyData;
initState Code
#override
void initState() {
super.initState();
// GET PAGES
surveyPages = widget.surveyPages;
// GET FORM DETAIL
http.post(
'survey-pre-mitsu/form-detail',
body: {
"survey_form_header_id": 1,
},
).then(
(res) {
surveyData = res['data'];
},
);
}
Widget that looped by surveyData.length
for (var i = 0; i < surveyData.length; i++)
AdditionalForm(questionLabel: surveyData[i]['label'],
questionType: surveyData[i]['type'],),
This is what the error
And this is what it looks like when i do hot reload
First, I suggest you to use future builder to resolve this problem.
First, I suggest performing post(even though its your own code) as a asynchronous operation, hence not inside initState(). Preferably write the logic in a separate class/file with packages like a provider package. Try this first and then post the error after that.
You need to add Some delay , In this Delay you can show a loading icon . for delay you can use :
Future.delayed(const Duration(milliseconds: 500), () {
// Here you can write your code
setState(() {
// Here you can write your code for open new view
});
});
This will solve your problem

changing variables inside listview builder

i want to change variable values when the widget is loading the data from the web,
just want to do something like this:
_playid = _notes[1].id;
title = _notes[1].title;
but wherever I put it, i get an error,
I tried to put it in a set state inside listview builder, but no luck since I don't want it with onPress or on tap methods
could someone help, please?
i just found out,
simply we have to use setstate in fetch inside initstate
void initState() {
title = " ";
fetchNotes().then((value) {
setState(() {
_notes.addAll(value);
_playid = _notes[0].numb;
});
});
}

Controller's length property does not match the number of tabs present in TabBar's tabs property

I am implementing an TabBar but getting the error, as state above. I know the reason this is happening, but can't figure how to fix this.
I have an async function designed to pull data from Firebase which populates a list. The function is described below. The data pulled by this function is used to pass the length to the TabController.
Function to call data from Firebase:
Future functionName async {
await function actions...
List example = ['item1', 'item2', 'item3', 'item4'];
}
This function is used in a Future Builder, which returns a widget to display, as soon as the function execution is complete.
The future of the Future Builder is initialised in the initState() of the class. The init() state looks like:
#override
void initState() {
super.initState();
_future = functionName();
tabController = TabController(length: example.length, vsync: this, initialIndex: 0);
tabController.addListener(_setActiveTabIndex);
}
Now, I get the error, as stated above. Which is obvious, why!
As the function is an async function and is built in a Future Builder, initially the list 'example' is empty. And the TabController gets a length of 0. But as this list gets populated, the length increases, but the length of the TabController does not change.
I have tried using :
#override
void initState() {
super.initState();
_future = functionName();
setState(() {
tabController = TabController(length : example. length, vsync : this, initialIndex : 0)
}
)
But this doesn't work either.
It's annoying to know the issue, but not being able to fix it. Any help on this will be highly appreciated.
You already know the reason of the problem.
The hole idea it's kind of backwards.
You are trying to build the TabBar, before you know how many tabs you need.
You can
Execute your FutureBuilder and then build the TabBar with the data received.
Or you can
Get the data before you go to that screen, so have the data already.
I hope this put you on the right track