Flutter padding issues on Android devices - android

I have the following widget in my Flutter app, which is pretty basic but for some reason, the padding is not working on some Android devices attached screenshot and code.
Code:
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
centerTitle: true,
title: Column(children: [
Text(
'register',
style: new TextStyle(
fontSize: 24.0,
color: Colors.white,
),
),
Text(
'Availability results',
style: new TextStyle(
fontSize: 18.0,
color: Colors.white,
),
),
]),
),
body: ListView(
children: <Widget>[
Column(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 12.0, bottom: 6.0),
child: Text(
'Showing results for',
style: Theme.of(context).textTheme.headline,
),
),
Padding(
padding: EdgeInsets.only(bottom: 12.0),
child: Text(
'"${_availabilityRespose.query}"',
style: Theme.of(context).textTheme.title,
),
),
It's bascially the padding in the list view

instead of using static values you should use dynamic values with
MediaQuery.of(context).size.width
MediaQuery.of(context).size.height
which may solve your problem but it is not a good solution. try to use Expanded with flex
Expanded(flex: 1, child: yourChild())
and you can test on device or emulator with different size and densities

Related

Some some code crashes my application on flutter

Im new in flutter, so i follow someone's tutorial to make music player app, everything normal until my app suddenly crashed, i tried to re-run the app but still it's crashed and i try to remove the code that last time i create and the app run normal, so what's wrong with the code?, sorry for my bad english.
....////
Widget _buildWidgetArtistName(MediaQueryData mediaQuery) {
return SizedBox(
height: mediaQuery.size.height / 1.8,
child: Padding(
padding: const EdgeInsets.only(left: 20.0),
child: LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return Stack(
children: <Widget>[
Positioned(
child: Text(
'Grande',
style: TextStyle(
color: Colors.white,
fontFamily: 'CoralPen',
fontSize: 72.0,
),
),
top: constraints.maxHeight - 100.0,
),
Positioned(
child: Text(
'Ariana',
style: TextStyle(
color: Colors.white,
fontFamily: 'CoralPen',
fontSize: 72.0,
),
),
top: constraints.maxHeight - 140.0,
),
Positioned(
child: Text(
'Tranding',
style: TextStyle(
color: Color(0xFF7D9AFF),
fontSize: 14.0,
fontFamily: 'Campton_Light',
fontWeight: FontWeight.w800,
),
),
top: constraints.maxHeight - 160.0,
),
],
);
},
),
),
);
}
#override
Widget build(BuildContext context) {
var mediaQuery = MediaQuery.of(context);
return Scaffold(
key: scaffoldState,
body: Stack(
children: [
_buildWidgetAlbumCover(mediaQuery),
_buildWidgetActionAppBar(mediaQuery),
_buildWidgetArtistName(mediaQuery), // This causing crash
],
),
);
}

RenderFlex children have non-zero flex but incoming width constraints are unbounded

I am writing code for my news project in flutter.I have copied this code from one tutorial. But I got exceptions and errors in my code. Anybody please help me to solve the issues. My code is:
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(97),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 32),
decoration: BoxDecoration(
color: Colors.white,
border: Border(
bottom: BorderSide(
width: 0.5,
color: Colors.white,
))),
child: AppBar(
title: Text(
'News',
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 30,
),
),
),
// height: 100,
)
]),
),
body: ListView.builder(
itemBuilder: (context, index) {
return _listItem(index);
},
itemCount: _newsInApp.length,
));
}
My console output is:
Launching lib/main.dart on iPhone 11 Pro Max in debug mode...
Running Xcode build...
Xcode build done. 22.9s
Syncing files to device iPhone 11 Pro Max...
flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during performLayout():
flutter: RenderFlex children have non-zero flex but incoming width constraints are unbounded.
Replace your listItem widget method with :
_listItem(index) {
return Padding(
padding: const EdgeInsets.only(left: 15, top: 1, right: 1, bottom: 1),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.only(bottom: 15),
child: Text(
_newsInApp[index].title,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
),
),
IconButton(
iconSize: 16,
color: Colors.black26,
icon: Icon(Icons.arrow_forward_ios),
onPressed: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) {},
),
),
),
],
),
);
}

Flutter Flatbutton onpressed not working while trying to open phone dialer

Hello new to flutter here. I am trying to open phone dialer with a predefined phone number after pressing Call button that is Flatbutton inside Positioned, but it is not working and does not show any error either. I tried printing some values on onpressed as well but it did not print any. I have called this widget in another dart file.
Here i am using url_launcher package to launch the phone dialog.
If any other alternative way please help.
(Removed some unimportant design codes below)
class CallCard extends StatefulWidget {
#override
_CallCardState createState() => _CallCardState();
}
class _CallCardState extends State<CallCard> {
#override
Widget build(BuildContext context) {
return Positioned(
bottom: -170,
child: Container(
child: Column(
children: <Widget>[
SizedBox(
height: 15,
),
Text(
'Are you feeling well today?',
style: TextStyle(
fontSize: 24.0,
),
),
Text(
'Give us a call or visit our website.',
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.w300,
),
),
SizedBox(
height: 23.0,
),
Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
FlatButton(
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 15),
color: Color(0xff9ce47c),
onPressed: () {
final String phone = "01-4441577";
launch(phone);
print('here');
},
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.black),
borderRadius: BorderRadius.circular(50),
),
child: Row(
children: <Widget>[
Icon(
LineAwesomeIcons.phone,
size: 22,
),
SizedBox(
width: 5.0,
),
Text(
'Call Now',
style: TextStyle(
fontSize: 16,
),
),
],
),
),
SizedBox(
width: 1.0,
),
],
),
),
],
)
],
),
));
}
}
This is the code where I have called this widget (inside Stack)
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Stack(
alignment: Alignment.topCenter,
overflow: Overflow.visible,
children: <Widget>[
_backgroundCover(),
//content inside header
Positioned(
top: 80,
left: 30,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
//crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Hello User',
style: TextStyle(
fontSize: 36,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
SizedBox(width: 10.0,),
// Padding(padding: EdgeInsets.only(right: 200.0)),
IconButton(
icon: Icon(
LineAwesomeIcons.power_off,
size: 40.0,
),
onPressed: () {
DialogHelper.exit(context);
// await _auth.signOut();
}),
],
),
),
CallCard(),
],
),
],
),
),
);
Did you try putting the print before launch? It could be that launch is getting stuck and then the print never gets reached (this has happened to me with certain packages).
I am not sure how launch works with phone numbers but you may want to look into if youre using it properly.
I'm ok with this code.
launch('tel:$yourPhoneNo');

Position widget anywhere without pushing other widgets

I've followed a Flutter youtube tutorial and ended up with a layout like this:
How can I move CircleAvatar widget far right and bring other widgets up? So it looks like this (I photoshoped this):
This is what some of my code looks like:
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.grey[900],
appBar: AppBar(
title: Text("User information"),
centerTitle: true,
backgroundColor: Colors.grey[850],
elevation: 0.0,
),
floatingActionButton: FloatingActionButton(
onPressed: () {
setState( () {
userLevel++;
});
},
backgroundColor: Colors.red[400],
child: Icon(Icons.add),
),
body: Padding(
padding: EdgeInsets.fromLTRB(30.0, 35.0, 30.0, 0.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Center(
child: CircleAvatar(
backgroundImage: AssetImage("assets/vayneAvatar.jpg"),
radius: 40.0,
),
),
Divider(height: 60.0, color: Colors.grey[700]),
Text(
"USERNAME",
style: TextStyle(
color: Colors.grey,
letterSpacing: 2.0,
),
),
SizedBox(height: 8.0),
Text(
"user1",
style: TextStyle(
color: Colors.red[400],
fontWeight: FontWeight.bold,
fontSize: 22.0,
letterSpacing: 2.0,
),
),
Thanks!
You need to use Stack widget which takes list of children, where you can easily position your widgets by Positioned widget.

Icons Won't Show Up Correctly Flutter

More often than not, the icons I select to display will not show up (or will show up incorrectly) throughout my entire application. I'm not importing any new icons, all of the ones I use are selected from Flutter's default library.
On Android devices it is pretty much hit-or-miss; either all of the icons show up correctly, or they all give the same error placeholder. Like I said its much more often that they do not show.
iOS is a different story, while they still usually don't work correctly, it sometimes gives random emojis instead of the correct icon or error boxes. As you can see in the second picture, it placed a forward arrow emoji in place of what should have been the list-like icon to open the Drawer. Previously, the Close icon inside the Drawer was displaying as the strong arm emoji.
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
leading: IconButton(
icon: Icon(Icons.format_align_center),
onPressed: () => _scaffoldKey.currentState.openDrawer(),
),
title: Text(
"INFORMATION",
style: TextStyle(
fontFamily: 'Titillium SemiBold',
fontSize: 37.0,
),
),
centerTitle: false,
backgroundColor: Colors.white,
elevation: 0.5,
),
drawer: Drawer(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Container(
height: 150.0,
color: Colors.white.withRed(191).withGreen(194).withBlue(200),
child: FittedBox(
alignment: Alignment.bottomCenter,
child: Padding(
padding: EdgeInsets.fromLTRB(20.0, 0.0, 20.0, 8.0),
child: Text(
"VITALITY PRO",
style: TextStyle(
color: Colors.white
),
),
)
)
),
SizedBox(height: 10.0),
ListTile(
title: Text(
"TERMS & CONDITIONS",
style: TextStyle(
fontSize: 18.0,
),
),
onTap: () => Navigator.pushNamed(context, '/terms'),
),
Divider(),
ListTile(
title: Text(
"PRIVACY POLICY",
style: TextStyle(
fontSize: 18.0
),
),
onTap: () => Navigator.pushNamed(context, '/privacy'),
),
Divider(),
SizedBox(height: 10.0),
ListTile(
title: Text(
"CLOSE",
style: TextStyle(
fontSize: 18.0
),
),
trailing: Icon(Icons.clear),
onTap: () => Navigator.pop(context),
),
SizedBox(height: 10.0),
Divider(),
Flexible(
fit: FlexFit.loose,
child: Align(
alignment: Alignment.bottomCenter,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlatButton(
child: Text(
"LOGOUT",
style: TextStyle(
color: Colors.black38,
),
),
onPressed: () => Navigator.pushNamed(context, '/origin'),
),
Text("#Copyright 2018, ISPA Technology, LLC"),
],
),
),
),
],
),
),
),
That's a known issue that was fixed since.
Run
flutter upgrade
to get a newer Flutter version where this fix is included.

Categories

Resources