I'm trying to build a Flutter Application. The application mostly consists of ListViews which are filled with data fetched from an API. Randomly the application freezes, not responsive at all, even tapping on buttons which are not part of the current interface (i.e menu). No error messages are shown in the debugger and even hot restart does not work in this case, the application must be stopped and run from start. Does anyone have any idea what may cause this issue? Thanks
Widget _buildMessageDisplay() {
return Consumer<ChatScreenProvider>(
builder: (context, chatState, child) {
return FutureBuilder(
builder: (context, projectSnap) {
if (projectSnap.connectionState == ConnectionState.done) {
return Padding(
padding: EdgeInsets.symmetric(
horizontal: 4.0,
),
child: ListView.builder(
physics: ClampingScrollPhysics(),
controller: _scrollController,
itemCount: chatState.messages.length,
reverse: true,
itemBuilder: (context, index) {
final ct = _buildChatThread(chatState.messages[index]);
return ct;
},
),
);
}
return Text('');
},
future: _getMessages,
);
},
);
}
I have also encountered the same problem, though restarting and rebuilding usually fixes this for me... Make sure that you have the latest version of flutter, by running flutter upgrade in the terminal or command prompt. Additionally, you could also restart your computer, reinstall the emulators, or even reinstall flutter and perform its setup from scratch. May I know if you are using a simulator or a physical device so that I could try to pinpoint the error? Thanks, and I hope this helps.
Since this error is project specific, I would suggest running flutter clean, which removes unwanted and unused files which could be causing your error
Also, how often does this error occur for you? Is it specific to this project or it is stuck on all projects?
Related
When opening the application for the first time images and stream values are not rendering until I tap on the screen or start scrolling. Made sure that the snapshot.data is printing out the correct values before returning the widget in the stream builder.
Row(
mainAxisSize: MainAxisSize.min,
children: [
Image.asset(
'assets/profile_image.png',
height: 36.0,
width: 36.0,
),
SizedBox(width: 10.0),
StreamBuilder<String>(
stream: context.read<UserBloc>().balanceStream,
builder: (context, snapshot) {
print('ConnectionState is ${snapshot.connectionState}');
switch (snapshot.connectionState) {
case ConnectionState.active:
print('Value is ${snapshot.data}');
return NonScalingTextView(
"\$ ${snapshot.data}",
style: TitleTiny,
);
break;
default:
return Container();
}
},
),
],
);
Performing some user interaction or hot reloading or hot restarting the application after first launch, the widgets render as expected.
I had an Authentication Bloc parenting the Material App. Inside I had a User Bloc created on successful Auth. I had the above issues when this was the case. The issue was only happening on the Widgets rendered based on the states emitted by the User Bloc. So rather than returning these widgets on state changes I changed my listener to navigate to these widgets on state changes. Now in order to call on my User Bloc from this navigated route, I had to move the User Bloc on top of the Material App. And doing this solved my issue.
This solved it but I still don't know what caused the former architecture to fail. If anyone can explain me, it'd be great.
I have made a list of images and using ListView.builder to display the images and its working perfectly fine while debugging and even in debug apk of the app but when i use release apk its not showing the images.
List<Activity> act = [
Activity('assets/sports.png', 'Sports', false),
Activity('assets/sleeping.png', 'Sleep', false),
Activity('assets/shop.png', 'Shop', false),
Activity('assets/relax.png', 'Relax', false),]
I am using ListView.builder to show images like this:
ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: act.length,
itemBuilder: (context, index) {
return Row(children: <Widget>[
SizedBox(
width: 15,
),
GestureDetector(
child: ActivityIcon(act[index].image)));
Make sure that you've "use-material-design: true" line above assets
There doesn't seem to be an issue from the code you've provided. It'll greatly help if you're able to provide any errors received from the app when the issue occurred. Another way that you can try is by switching to different Flutter channels and see if the app performs better.
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
I'm working on a project and meet this problem, with the device which is modified font of iPhone system in Setting => General => Accessibility => Larger Text is ON, I worked around and find a way to fix font size with the code below:
new MaterialApp(
builder: (context, child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: //element go here
)
}
)
This way is worked fine with common TextView and pop-up but I'm using flutter_datetime_picker
I read the documentation and still not find out how to fix font of DateTime picker when the pop-up shows up, How can I solve this problem, thank you, here is a picture to demonstrate it.
You are almost there....
I had the same issue too. I tried so much time and found out the solution.
The below builder is the parameter of "showDatePicker".
builder: (context, child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1),
child: Theme(......)
)
}
Just wrap the theme with MediaQuery. That's all. It works smoothly for me.
I might be misunderstanding the usage of this tool but I see the following
which is not good because it goes over 16ms. That piece of red bars happens always the first time that I load a page (widget) that has a FutureBuilder:
#override
Widget build(BuildContext context) {
// Page template is a StatelessWidget that wraps a Scaffold with common widgets, nothing special
return PageTemplate(
child: FutureBuilder(
future: getList(), // <-- this takes about 1 second
builder: (context, snapshot) {
if (snapshot.hasData) {
List<Operator> list = snapshot.data;
return ListView.builder(
itemCount: list.length,
itemBuilder: (context, index) {
return MyWidget();
},
);
}
return Center(
child: CircularProgressIndicator(),
);
},
),
);
The app is in Run mode: profile. Sometimes the page with the FutureBuilder might generate even more red bars so I am wondering:
is this fine because I am just misunderstanding the tool? The overlays above the app tell me that on averages I am at GPU 10ms/frame and UI 6 ms/frame so it should be fine. But I can't get why sometimes I get this in the future (taken from android studio; dotted white line is 16fps limit):
I suspect the above "issue" (if we can call it issue) might happen because I am not properly using the FutureBuilder. I read this (I try to put const everywhere and I split widgets as much as I can to optimize when rebuild happens) and I think that futurebuilder rebuilds a lot so this might be the problem. But it has to rebuild to check if the future has finished! So?
thanks