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.
Related
When user changes the text size in their display settings, my flutter app text size is also changing and it is disturbing nearby widgets, there by some part of the UI is becoming unusable. Is there any option to prevent changing of my flutter app text font sizes when system font size changes? If no option is available, how to overcome this problem? Surprisingly there is no much content about this issue on internet. Did anyone face such issues before?No code is req.
You need to set the textScaleFactor of your texts. Like:
Text(
'hello',
textScaleFactor: 1.0,
),
Or you can globally set it to 1.0 by:
MaterialApp(
builder: (BuildContext context, Widget child) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(textScaleFactor: 1.0),
child: child,
);
},
title: 'Home Page',
);
You can set textScaleFactor: 1 in Text Widget
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?
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
I have a Flutter app that is functioning properly in all respects except when I select a TextField (or TextFormField). When I select the TextField, the cursor blinks in the TextField, but I can't type anything AND all other buttons like the floatingActionButton and the back button in the AppBar quit working. Essentially, the app appears to be frozen, but I don't get any error messages.
After numerous attempts to fix the problem in two different pages that contain FocusNodes and TextEditingControllers, I went back to square one by incorporating a new page with code straight from Flutter's website, but the TextField in this barebones code still locks up the app.
import 'package:flutter/material.dart';
class EventDetailForm extends StatefulWidget {
static const String routeName = "/events/event-detail-form";
#override
_EventDetailFormState createState() => _EventDetailFormState();
}
class _EventDetailFormState extends State<EventDetailForm> {
final myController = TextEditingController();
#override
void dispose() {
myController.dispose();
super.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Event Detail')),
body: Padding(
padding: const EdgeInsets.all(16),
child: TextField(
controller: myController,
)),
floatingActionButton: FloatingActionButton(
onPressed: () {
return showDialog(
context: context,
builder: (context) {
return AlertDialog(
content: Text(myController.text),
);
});
},
child: Icon(Icons.text_fields),
),
);
}
}
Unfortunately, I am not getting any error messages. The cursor just blinks in the TextField and everything else loses function and I have to quit and restart. I am not sure what else I should be considering. Does anyone have any ideas on what might be causing this?
Simulator -> Device -> Erase All Content And Settings works for me.
Had same problem when I upgraded Xcode to ios 13.1. I switched to a different simulator, and the problem went away.
This maybe late, but it happened to me too just today. I also changed the channel to beta but unfortunately did not work too. Apparently what worked for me is when I restarted the simulator after I put back the channel to stable.
I had the same bug, solved by switching to the beta channel of Flutter.
In your terminal use
flutter channel beta
flutter upgrade
About channels you can read here https://github.com/flutter/flutter/wiki/Flutter-build-release-channels
I did not change channel, a simple flutter upgrade was enough to fix this problem. I also closed Android Studio and all simulators and when I restarted, the problem was gone.
I think I am late to the party but the issue still exists in 2021.
I tried all the solutions but couldn't fix it. Whatever I was typing in TextField or TextFormField or autocomplete_textfield, the characters were not visible.
I fixed it by opening the Widget as a showGeneralDialog() instead of using Navigator.of(...). Here is the sample code.
await showGeneralDialog(
barrierColor: AppStyle.primaryColor.withOpacity(0.3),
transitionBuilder: (context, a1, a2, widget) {
return Transform.scale(
scale: a1.value,
child: Opacity(opacity: a1.value, child: WidgetScreenToOpen()),
);
},
transitionDuration: Duration(milliseconds: 500),
barrierDismissible: true,
barrierLabel: 'Label',
context: context,
pageBuilder: (context, animation1, animation2) {
return Container();
}).then((result) {
return result;
});
I am working on a Flutter Application where I need to show an AdMob's Banner Ad. I have noticed that the banner overlaps my list view. I tried to search for the solution but I did not find anything much useful.
One solution I found is to provide fix margin of 50px at the bottom. I feel a little uncomfortable with this solution as I read somewhere that the screen size may affect this solution.
Also when I put a fake bottom bar then it also overlaps my bottom tab bar and bottom sheets.
Please see the below image for more details.
Thank you for your time.
I found one solution for you my cast Banner bottom Flutter Application little bit padding. Fix it with below code.
var paddingBottom = 48.0;
new MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Name',
home: new MyHomePage(
title: "NMame",
),
builder: (context, widget) {
final mediaQuery = MediaQuery.of(context);
return new Padding(
child: widget,
padding: new EdgeInsets.only(bottom: paddingBottom),
);
},
routes: <String, WidgetBuilder>{
'/HomeScreen': (BuildContext context) =>
new MyHomePage(title: 'UPSC Question Papers')
})
handle when the app is not getting loaded Ads
if(event == MobileAdEvent.failedToLoad){
setState(() {
paddingBottom = 0.0;
});
}
Thank you
If you're using a Scaffold Widget, try using the persistentFooterButtons: parameter. Tutorial here: http://cogitas.net/show-firebase-admob-banner-ad-in-flutter/
Set following params in the banner ad show() function:
bannerAd = Utils().myBanner
..load()
..show(
anchorType: AnchorType.bottom,
anchorOffset: 55.0);
And also need to set margin: const EdgeInsets.only(bottom: 55) on the container