Edit: This error only happen in Xioami Redmi Note 7 (Android version 10), work perfectly on other device like samsaung (Android version 13).
Edit: I reproduced again. I found this happen when pop back to drawer from drawer navigation.
(Eg: Go to notification screen from drawer navigation stack and pop back).
I found an issue with the flutter drawer while implementing UI.
Please see below image. Drawer header exceed a white margin that I except. But that exceed margin not always happen every time although I reproduce by opening drawer again and again. It only happen in usual when not expected. What is happen and how to fix?
I test this with only in debug mode.
DrawerHeader(
decoration: BoxDecoration(
color: primaryColor,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const FlutterLogo(
size: largeIconSize,
),
const SizedBox(
width: 70,
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'LA PYAE TEST',
style: Theme.of(context).textTheme.headline5,
),
Text(
'09500007958',
style: Theme.of(context).textTheme.headline5?.copyWith(
fontSize: textRegular2X,
),
),
Text(
'Balance: 0 MMK',
style: Theme.of(context).textTheme.headline5?.copyWith(
fontSize: textRegular,
),
),
],
),
],
),
),
Edit
here is my Drawer body completely ,
Drawer(
child: ListView(
children: [
/// TODO Bind data
DrawerHeader(
decoration: BoxDecoration(
color: primaryColor,
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const FlutterLogo(
size: largeIconSize,
),
const SizedBox(
width: 70,
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'LA PYAE TEST',
style: Theme.of(context).textTheme.headline5,
),
Text(
'09500007958',
style: Theme.of(context).textTheme.headline5?.copyWith(
fontSize: textRegular2X,
),
),
Text(
'Balance: 0 MMK',
style: Theme.of(context).textTheme.headline5?.copyWith(
fontSize: textRegular,
),
),
],
),
],
),
),
ListTile(
onTap: () {
Navigator.pushNamed(context, notificationRoute);
},
leading: const Icon(
Icons.notifications_none_outlined,
size: 30,
),
title: const Text(NOTIFICATION),
),
const ListTile(
leading: Icon(
Icons.settings_outlined,
size: 30,
),
title: Text(APP_SETTING),
),
const ListTile(
leading: Icon(
Icons.location_on_outlined,
size: 30,
),
title: Text(LOCATIONS),
),
const ListTile(
leading: Icon(
Icons.question_mark_outlined,
size: 30,
),
title: Text(ABOUT),
),
const ListTile(
leading: Icon(
Icons.logout_outlined,
size: 30,
),
title: Text(LOG_OUT),
),
const ListTile(
leading: Icon(
Icons.share,
size: 30,
),
title: Text(SHARE_APP),
),
],
),
);
add
padding: EdgeInsets.zero,
to drawer header widget
Related
the question is exactly same as this post
but I did not find an answer from the post.
my goal is to set the title widget in the center
and other two buttons on the right side.
the solutions in the link all put the title widget slightly on the left side.
does anyone know how to do this without using Stack? I'm afraid of the title widget being over the button widgets when the title gets too long.
the code:
SizedBox(
height: 40,
width: MediaQuery.of(context).size.width,
child: Row(
children: [
const SizedBox(width: 17),
Text(
'TITLE',
style: const TextStyle(
color: Colors.white, fontSize: 30, fontWeight: FontWeight.w500),
),
Spacer(),
Row(
children: [
GestureDetector(
onTap: (){null;},
child: SizedBox(
child: Icon(Icons.wallet_membership, color: Colors.white),
),
),
const SizedBox(width: 17),
GestureDetector(
onTap: (){Get.toNamed('/wallet_setting');},
child: const SizedBox(
child: Icon(Icons.settings, color: Colors.white),
),
),
]
)
]
),
)
Try this One
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Expanded(
child: Container(
child: Center(
child: Text(
'TITLE',
style: const TextStyle(color: Colors.white, fontSize: 30, fontWeight: FontWeight.w500),
),
)
)
),
Align(
alignment: Alignment.centerRight,
child: Row(
children: [
GestureDetector(
onTap: (){null;},
child: SizedBox(
child: Icon(Icons.wallet_membership, color: Colors.white),
),
),
const SizedBox(width: 17),
GestureDetector(
onTap: (){Get.toNamed('/wallet_setting');},
child: const SizedBox(
child: Icon(Icons.settings, color: Colors.white),
),
),
]
)
)
],
)
OutPut:
i think you should wrap it with centre
Try this approach:
first make widget from your right widgets:
Widget _rightIcons() {
return Row(children: [
GestureDetector(
onTap: () {
null;
},
child: SizedBox(
child: Icon(Icons.wallet_membership, color: Colors.white),
),
),
const SizedBox(width: 17),
GestureDetector(
onTap: () {
Get.toNamed('/wallet_setting');
},
child: const SizedBox(
child: Icon(Icons.settings, color: Colors.white),
),
),
]);
}
then build your header like this:
Row(
children: [
_rightIcons(),
Expanded(
child: Center(
child: Text(
'TITLE',
style: const TextStyle(
color: Colors.white,
fontSize: 30,
fontWeight: FontWeight.w500),
),
),
),
Opacity(
opacity: 0,
child: _rightIcons(),
)
],
),
You can use centerTitle:true on Appbar
appBar: AppBar(
centerTitle: true,
title: Text("title"),
actions: [
Another way
Container(
color: Colors.purple,
height: 40 * 2,
width: MediaQuery.of(context).size.width,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
IconButton(onPressed: () {}, icon: Icon(Icons.navigate_before)),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expanded(
flex: 1,
child: SizedBox(),
),
Expanded(
flex: 4,
child: Text(
'TITLE',
textAlign: TextAlign.center,
style: const TextStyle(
color: Colors.white,
fontSize: 30,
fontWeight: FontWeight.w500),
),
),
Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
GestureDetector(
child: Icon(Icons.wallet_membership,
color: Colors.white),
),
const SizedBox(width: 17),
GestureDetector(
onTap: () {},
child: const SizedBox(
child:
Icon(Icons.settings, color: Colors.white),
),
),
]),
),
)
],
),
],
),
)
Preferable solution:
You can implements PreferredSizeWidget to create custom Appbar. Play with color and other decoration.
class MyAppBar extends StatelessWidget implements PreferredSizeWidget {
const MyAppBar({super.key});
#override
Widget build(BuildContext context) {
return Stack(
children: [
Align(
alignment: Alignment.bottomCenter,
child: Text("title"),
),
Align(
alignment: Alignment.bottomRight,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
//you can use callback method to get onpressed
onPressed: () {},
icon: Icon(Icons.settings),
),
IconButton(
onPressed: () {},
icon: Icon(Icons.settings),
),
],
),
)
],
);
}
#override
Size get preferredSize => const Size.fromHeight(kToolbarHeight * 2);
}
And use like appBar: MyAppBar(),
Facing some difficulties in flutter as I am new to it, how to centerInParent for imageView for flutter? The image is not center, I had use Align but still not working. And how to construct the image and text like this photo ?
appBar: PreferredSize(
preferredSize: Size.fromHeight(45.0),
child: AppBar(
leading: Row(
children: [
Container(
child: GestureDetector(
onTap: () {/* open left menu */},
child: Image.asset("assets/images/ic_title_menu.png", width: 18.0, height: 18.0,)),
padding: EdgeInsets.fromLTRB(14.0, 14.0, 14.0, 14.0),
),
],
),
title: Container(
child: GestureDetector(
onTap: () {/* open search */},
child: Image.asset("assets/images/ic_title_search.png", width: 18.0, height: 18.0,)),
),
actions: <Widget>[
Center(
child: Container(
child: Stack(children: <Widget>[
Align(
alignment: Alignment.center,
child: Image.network(""),)
],),
),
)
],
titleSpacing: 0.0,
automaticallyImplyLeading: false,
),
),
I hope this is something you wanted!
import 'package:flutter/material.dart';
const Color kRed = Colors.red;
class Test extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Icon(
Icons.menu,
color: kRed,
size: 30,
),
SizedBox(width: 10),
Icon(
Icons.search,
color: kRed,
size: 30,
)
],
),
Text(
'Test Text',
style: TextStyle(color: kRed, fontSize: 30),
),
Row(
children: <Widget>[
Column(
children: <Widget>[
Text(
'Test Text',
style: TextStyle(color: kRed, fontSize: 15),
),
Text(
'Test Text',
style: TextStyle(color: kRed, fontSize: 15),
),
],
),
SizedBox(width: 10),
Icon(
Icons.person,
color: kRed,
size: 30,
)
],
)
],
),
),
);
}
}
Just replace the Text Widget in the middle with Image Widget. And tweak with your colors.
App Bar has a property called centerTitle, it will add title on the Appbar center.
centerTitle: true,
Try This
flexibleSpace: Container(
margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
child: Center(
child: Image(
image: AssetImage('assets/img/icon_1.png'),
))),
EDIT: Added a screenshot of the desired output
Goal: Placing a group of widgets (RoundButtons and Text widgets) at the edge of their parent widget
Problem: The widgets that need to move are still close to their nearby widgets
Here is a screenshot showing the problem:
Here's the desired output:
The following code snippet shows the widgets that I need to move to the end of the parent:
Widgets to be moved: inner Row and its widgets.
Row(//parent widget
children: <Widget>[
Row(//To be moved to the end of the parent
children: <Widget>[
RoundIconButton(
icon: FontAwesomeIcons.minus, onPressed: () {}),
Text('$_counter'),
RoundIconButton(
icon: FontAwesomeIcons.plus, onPressed: () {}),
],
),
Text('10000', style: GoogleFonts.cairo(fontSize: 15)),
],
),
Here is the current implementation that corresponds to the screenshot above:
Container(
width: deviceWidth,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: EdgeInsets.only(right: 10),
child: Column(
textDirection: TextDirection.rtl,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Product',
style: GoogleFonts.cairo(
fontSize: 15,
),
),
Text(
'subtitle',
style: GoogleFonts.cairo(
fontSize: 15,
fontWeight: FontWeight.w200,
),
),
StrikeThroughWidget(
child: Text(
'5000',
style: GoogleFonts.cairo(
fontSize: 10,
fontWeight: FontWeight.w200,
),
),
),
Row(
children: <Widget>[
Row(
children: <Widget>[
RoundIconButton(
icon: FontAwesomeIcons.minus, onPressed: () {}),
Text('$_counter'),
RoundIconButton(
icon: FontAwesomeIcons.plus, onPressed: () {}),
],
),
Text('10000', style: GoogleFonts.cairo(fontSize: 15)),
],
),
],
),
),
Container(
padding: const EdgeInsets.all(3.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.grey[350])),
width: 90,
height: 90,
child: FlutterLogo(),
),
],
),
),
Already-tried Solutions:
Changing mainAxisAlignment of the Row with multiple values but didn't get the desired output
Placing the Row inside of a Flex Widget
You can separate the Widgets in multiple layers using Stack and use Position to place the layers exactly where you want.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Material(
child: Center(
child: Stack(
children: <Widget>[
Container(
width: 500,
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: EdgeInsets.only(right: 10),
child: Column(
textDirection: TextDirection.rtl,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Product'),
Text('subtitle'),
Text('5000'),
Text('10000'),
],
),
),
Container(
padding: const EdgeInsets.all(3.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.grey[350])),
width: 90,
height: 90,
child: FlutterLogo(),
),
],
),
),
Positioned(
bottom: 0,
left: 0,
child: Row(
children: <Widget>[
CircleAvatar(
backgroundColor: Colors.blue,
radius: 20,
child: IconButton(
padding: EdgeInsets.zero,
icon: Icon(Icons.add),
color: Colors.white,
onPressed: () {},
),
),
Text('1'),
CircleAvatar(
backgroundColor: Colors.blue,
radius: 20,
child: IconButton(
padding: EdgeInsets.zero,
icon: Icon(Icons.remove),
color: Colors.white,
onPressed: () {},
),
),
],
),
)
],
),
),
),
);
}
Hope this helps.
You could use a Stack and Positioned:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Material(child: Center(
child:
Container(
color: Colors.grey,
width: 400,
height: 100,
child: Stack(children: <Widget>[
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: EdgeInsets.only(right: 10),
child: Column(
textDirection: TextDirection.rtl,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Product',
style: TextStyle(
fontSize: 15,
),
),
Text(
'subtitle',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w200,
),
),
Text(
'5000',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w200,
),
),
],
),
),
Container(
padding: const EdgeInsets.all(3.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.grey[350])),
width: 90,
height: 90,
child: FlutterLogo(),
),
],
),
Positioned(
bottom: 0,
left: 0,
child: Row(
children: <Widget>[
Row(
children: <Widget>[
RawMaterialButton(
child: Text("-"), onPressed: () {}),
Text('6'),
RawMaterialButton(
child: Text("+"), onPressed: () {}),
],
),
Text('10000', style: TextStyle(fontSize: 15)),
],
),),
]
),),),),
);
}
}
Try adding a Spacer
Row(//parent widget
children: <Widget>[
Row(//To be moved to the end of the parent
children: <Widget>[
RoundIconButton(
icon: FontAwesomeIcons.minus, onPressed: () {}),
Text('$_counter'),
RoundIconButton(
icon: FontAwesomeIcons.plus, onPressed: () {}),
],
),
Spacer(),//Where I added the spacer
Text('10000', style: GoogleFonts.cairo(fontSize: 15)),
],
),
This is the design of appbar that I want to create using flutter and that should be responsive for all types of mobile devices and Tablets. Please let me know what to do to achieve this.
Widget _buildHeader() {
return Container(
height: MediaQuery.of(context).size.height* .22,
width: MediaQuery.of(context).size.width * 1,
color: Color(0xFF0A182E),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 10, top: 40),
child: FlatButton(
onPressed: () {
print("homebtn clicked..!!"); //Home button
},
child: Text(
"Home",
style: TextStyle(
color: Colors.white,
fontSize: 30,
fontWeight: FontWeight.bold),
),
),
),
SizedBox(width: MediaQuery.of(context).size.width *.47,),
FlatButton(
onPressed: () {
print("profilebtn clicked");
},
shape: CircleBorder(),
child: Container(
margin: EdgeInsets.only(top: 20),
height: MediaQuery.of(context).size.height*.07,
width: MediaQuery.of(context).size.width*.14,
child: CircleAvatar(
backgroundImage: AssetImage("images/profilebtn.png"),
),
),
),
],
),
SizedBox(height: MediaQuery.of(context).size.height * .04,),
Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 10),
child: FlatButton(
onPressed: () {
print("Roomsbtn clicked.!");
},
child: Container(
child: Text(
"ROOMS",
style: TextStyle(
fontSize: 20,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
),
),
FlatButton(
onPressed: () {
print("Devicesbtn clicked.!");
},
child: Container(
child: Text(
"DEVICES",
style: TextStyle(
fontSize: 20,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
),
SizedBox(width: MediaQuery.of(context).size.width *.27,),
Transform.scale( //add Button
scale: .65,
child: FloatingActionButton(
onPressed: () {
print("Redplusbtn clicked.!");
_onButtonPressed();
},
child: Icon(
Icons.add,
size: 45,
),
backgroundColor: Colors.red,
),
),
],
),
],
),
);
}
This is what I have tried but I find this approach is lengthy and not responsive.I have tried in other devices and appbar is not responsive so I want to make this appbar in a Standard way.
I think this is way better solution. First of all there is no need to call media query to find a width and height. Another thing is that you can use AppBar widget and rework it to the way you like. Look at this example and amend it to your needs..
Scaffold(
appBar: AppBar(
title: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[Text('Hello'), Icon(Icons.email)],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Row(
children: <Widget>[
Text('Option1'),
Text('Option2'),
],
),
Icon(Icons.language)
],
)
],
),
),
body: Container())
I would try putting the higher elements (title and picture) on the AppBar and the lower elements (Room, devices and plus icon) on a TabBar.
AppBar: https://api.flutter.dev/flutter/material/AppBar-class.html
TabBar: https://api.flutter.dev/flutter/material/TabBar-class.html
You can identify the customer device first using this plugin https://pub.dev/packages/device_info
the next steps, you can set the condition of the appbar in each device.
for more details you can check this link https://iiro.dev/2018/01/28/implementing-adaptive-master-detail-layouts/
I'm trying to implement 2 Icons in a Row and under each Icon some text
My current implementation:
ButtonBar(
alignment: MainAxisAlignment.spaceAround,
children: <Widget>[
IconButton(
icon: Icon(
Icons.directions_car,
size: 55.0,
),
onPressed: () {},
),
IconButton(
icon: Icon(
Icons.streetview,
size: 55.0,
),
onPressed: () {},
),
],
),
Padding(
padding: const EdgeInsets.fromLTRB(18.0, 10.0, 0, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Text('some text',
style: TextStyle(
fontSize: 16.0
),
),
Text('some text'),
],
),
),
My problem is that my text should be dynamic, So every time the text changed, the location of my text changes and sometimes it look really ugly.
How can in place the text in a better way that is posted here?
try this.. so what I have done is I added both Icon and Text inside a Column so they will behave as a group
ButtonBar(
alignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Column(
children: <Widget>[
IconButton(
padding: EdgeInsets.zero,
icon: Icon(
Icons.directions_car,
size: 55.0,
),
onPressed: () {},
),
SizedBox(
height: 10,
),
Text('some text'),
],
),
Column(
children: <Widget>[
IconButton(
padding: EdgeInsets.zero,
icon: Icon(
Icons.streetview,
size: 55.0,
),
onPressed: () {},
),
SizedBox(
height: 10,
),
Text('some text'),
],
),
],
),