I have a navigation menu which I created using a container, within my container there is a column which contains all my icons. When the user click's on certain icons or the login button at the bottom right corner I am suppose to be able to navigate/route to the next screen. I know that when we move to the next screen the menu on the left will disappear, is there a way to keep the menu bar persistent across all screens. I was assuming that I need to create a separate class/widget specifically for the menu bar and call it on each page that I route to. I am still new to flutter so I wasn't sure if there might be another approach to this problem. I also need to persist the row at the top onto all pages as well.
Widget build(BuildContext context) {
return Container(
width: 1280,
height: 800,
decoration: BoxDecoration(
color: Color.fromRGBO(227, 227, 227, 1),
),
child: Material(
child: Stack(
children: <Widget>[
Positioned(
top: 0,
left: 80,
child: Container(
width: 1200,
height: 70,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Topbarbackground.png'),
fit: BoxFit.fitWidth
),
)
)
), Positioned(
top: 652,
left: 0,
child: Container(
width: 1280,
height: 100,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/Rectangle112.png'),
fit: BoxFit.fitWidth
),
)
)
), Positioned(
top: 0,
left: 0,
child: Container(
child: ListView(
children: [
SizedBox(
height: 50.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Back.png'),
onPressed: () {},
),
),
SizedBox(
width: 0.0,
height: 150.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/tip_load.png'),
onPressed: () {},
),
),
SizedBox(
width: 0.0,
height: 50.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/tip_eject.png'),
onPressed: () {
},
),
),
SizedBox(
height: 125.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Light.png'),
onPressed: () {},
),
),
IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Utility.png'),
onPressed: () {},
),
SizedBox(
height: 125.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Help.png'),
onPressed: () {},
),
),
SizedBox(
height: 100.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/User.png'),
onPressed: () {},
),
),
IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Power.png'),
onPressed: () {},
),
],
),
It is possible to do that. You have to put the sidebar in a separate widegt and then make a widget that shows it in a Row. Then you will need to change the builder of the main file in a way that the widget with the row can be displayed. This isn't the best explanation so I recommend you to read through this article:
https://medium.com/geekculture/persistent-widget-across-all-screens-using-flutter-navigator-45e6b2e57cf7
It showcases everything and gives you a short tutorial. I hope this helped.
Related
I have a Widget to creat a circular container. I want to place an icon on the buttom right, so I tried to use Positioned to place it where I want but its not moving. Its fixed on the center on the container.
Widget buildImage() {
return Center(
child: Container(
child: Material(
child: InkWell(
customBorder: CircleBorder(),
onTap: (){},
child: Container(
width: 150.0,
height: 150.0,
child: Positioned(
bottom: 4,
right: 0,
child: Icon (Icons.account_circle_rounded),
),
),
),
color: Colors.transparent,
),
decoration: BoxDecoration(
color: Colors.orange,
shape: BoxShape.circle,
),
),
);
}
What am I doing wrong here?
Your answers are highly appreciated.
Positioned is used only in Stack widget. So if you want to position your icon inside Container, you can use Align widget, withPadding which will create desired behavior specified before in Positioned.
Somehow like this:
...
Container(
width: 150.0,
height: 150.0,
child: Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(right: 4.0),
child: Icon(
Icons.account_circle_rounded,
),
),
),
),
...
Container has align property you can use that or instead of Positined you can use Alignment Widget for Aligning your widget
For more control over postioning, just change the padding values.
Center(
child: Container(
child: Material(
child: InkWell(
customBorder: CircleBorder(),
onTap: () {},
child: Container(
width: 150.0,
height: 150.0,
child: Container(
padding: EdgeInsets.only(
right: 20, bottom: 10),
alignment: Alignment.bottomRight,
child: Icon(
Icons.account_circle_rounded),
),
),
),
color: Colors.transparent,
),
decoration: BoxDecoration(
color: Colors.orange,
shape: BoxShape.circle,
),
),
),
I've provide the code. So the dragable widget is in the drawer and the drag target is in the home screen. But when I drag the container to put it in the drag target(home screen) the drawer doesn't close
If anyone have the full code that's working just like I discribe plz feel free to share cuz I think there's a lot of people trying to do this as well
`Drawer(
child: Column(children: [
Padding(
padding: const EdgeInsets.only(top: 100.0),
child: Draggable(
child: Container(
color: Colors.red,
width: 250,
height: 100,
),
feedback: Container(
color: Colors.green,
width: 250,
height: 100,
),
childWhenDragging: Container(
color: Colors.grey,
width: 250,
height: 100,
),
),
),
]),
);
FloatingActionButton(
onPressed: () {
Scaffold.of(context).openDrawer();
},
child: const Icon(
Icons.add,
color: Colors.white,
size: 29,
),
backgroundColor: Colors.redAccent,
elevation: 0,
),`
when I create a drawer and put container and wrap with drag-able widget then I put a drag target inside the screen But when I try to drag it the drawer doesn’t close.So if you have any idea how to close the drawer when widget is drag plz answer down below
The Class Draggable provides a function called onDragStarted. If you place Navigator.pop in there it will close the drawer once the drag starts
Drawer(
child: Column(children: [
Padding(
padding: const EdgeInsets.only(top: 100.0),
child: Draggable(
//This function should close the drawer
onDragStarted: () {
Navigator.pop(context);
},
child: Container(
color: Colors.red,
width: 250,
height: 100,
),
feedback: Container(
color: Colors.green,
width: 250,
height: 100,
),
childWhenDragging: Container(
color: Colors.grey,
width: 250,
height: 100,
),
),
),
]),
);
FloatingActionButton(
onPressed: () {
Scaffold.of(context).openDrawer();
},
child: const Icon(
cons.add,
color: Colors.white,
size: 29,
),
backgroundColor: Colors.redAccent,
elevation: 0,
),
I am trying to find a better alternative to spacing my icons in Flutter, I am currently using the SizedBox(...) Widget. Although I am not sure if this is the best method to use, the sized box seems to mess up the spacing of other icons when I am adjusting the height/width. Are there any alternatives to spacing your icons inside a container. I added a picture of the UI to the post, the icons are in the menu on the left side. Login Screen Image
Widget build(BuildContext context) {
return Container(
width: 1280,
height: 800,
decoration: BoxDecoration(
color: Color.fromRGBO(227, 227, 227, 1),
),
child: Material(
child: Stack(
children: <Widget>[
Positioned(
top: 0,
left: 80,
child: Container(
width: 1200,
height: 70,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/Topbarbackground.png'),
fit: BoxFit.fitWidth
),
)
)
), Positioned(
top: 652,
left: 0,
child: Container(
width: 1280,
height: 100,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assets/images/Rectangle112.png'),
fit: BoxFit.fitWidth
),
)
)
), Positioned(
top: 0,
left: 0,
child: Container(
child: ListView(
children: [
SizedBox(
height: 50.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Back.png'),
onPressed: () {},
),
),
SizedBox(
width: 0.0,
height: 150.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/tip_load.png'),
onPressed: () {},
),
),
SizedBox(
width: 0.0,
height: 50.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/tip_eject.png'),
onPressed: () {
},
),
),
SizedBox(
height: 125.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Light.png'),
onPressed: () {},
),
),
IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Utility.png'),
onPressed: () {},
),
SizedBox(
height: 125.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Help.png'),
onPressed: () {},
),
),
SizedBox(
height: 100.0,
child: IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/User.png'),
onPressed: () {},
),
),
IconButton(
padding: EdgeInsets.all(0.0),
icon: Image.asset('assets/icons/Power.png'),
onPressed: () {},
),
],
),
You can put all the icons in a Column widget. The column widget has a parameter MainAxisAlignment, you can set this parameter to MainAxisAlignment.spaceEvenly.
See https://api.flutter.dev/flutter/widgets/Column-class.html for the Column widget
and see https://api.flutter.dev/flutter/rendering/MainAxisAlignment.html for the MainAxisAlignment
Put the Column widget inside a Container widget.
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly
children: [
Icon()
Icon()
],
),
),
you can try to use Padding. Something like that should do the trick:
Padding(
padding: EdgeInsets.only(left:10),
child: Icon(Icons.check)
),
When the sized box tapped, the ripple effect should happen on top of the widget. But it does not appear. The sized box appears, but ripple effect is not.
Stack(
alignment: Alignment.center,
children: <Widget>[
SizedBox(
width: widget.width,
height: widget.height,
child: Material(color: Colors.yellow, child: widget.icon
),
),
SizedBox(
width: widget.width,
height: widget.height,
child: InkWell(
borderRadius: BorderRadius.circular(25),
splashColor: Colors.purple,
onTap: () {}),
),
],
),
]);
EDIT: Wrapped the whole stack with the inkwell but still ripple does not appear.
InkWell(
borderRadius: BorderRadius.circular(25),
splashColor: Colors.purple,
child: Stack(
alignment: Alignment.center,
children: <Widget>[
SizedBox(
width: widget.width,
height: widget.height,
child: Material(color: Colors.yellow, child: widget.icon
),
Add InkWell above icon that will give a ripple effect
Stack(
alignment: Alignment.center,
children: <Widget>[
SizedBox(
height: 48,
width: 48,
child: Material(
color: Colors.yellow,
child: InkWell(
splashColor: Colors.purple,
onTap: () {},
child: const Icon(Icons.add),
),
),
),
],
),
OR
Material(
color: Colors.yellow,
child: InkWell(
splashColor: Colors.purple,
onTap: () {},
child: Container(
color: Colors.transparent,
height: 80,
width: 80,
child: Icon(Icons.add),
),
),
),
Output:
You must put the sized box as child of inkwell (or even move the complete stack into the inkwell child).
Inkwell is applied to its children.
InkWell(
borderRadius: BorderRadius.circular(25),
splashColor: Colors.purple,
onTap: () {
print('HEY');
},
child: SizedBox(
width: widget.width,
height: widget.height,
),
),
add onTap(){} to the inkWell, even if its not used. I think this fixes it, haven't tried it out tho. Also try wrapping the InkWell with a Material widget.
I would like to change the size of the button, by reducing the vertical size so it is a bit squished.
The current code that I have written is this:
Padding(
padding: const EdgeInsets.all(8),
child: Material(
color: Color(0xFF3E4685),
borderRadius: BorderRadius.circular(20),
elevation: 6,
child: MaterialButton(
height: 0,
onPressed: () {},
padding: EdgeInsets.symmetric(vertical: 0),
child: Icon(
Icons.arrow_right_alt_sharp,
size: 50,
color: Colors.white,
),
),
),
)
And the output is this:
Button
I would like for it to be a bit more squished so less vertical height, I have tried using the height property but it isn't working.
Try this one
SizedBox(
width: 150,
height: 150,
child: Material(
color: Color(0xFF3E4685),
borderRadius: BorderRadius.circular(20),
elevation: 6,
child: MaterialButton(
height: 0,
onPressed: () {},
padding: EdgeInsets.symmetric(vertical: 0),
child: Icon(
Icons.arrow_right_alt_sharp,
size: 50,
color: Colors.white,
),
),
),
or you can use ButtonTheme
ButtonTheme(
minWidth: 200.0,
height: 100.0,
child: YourButton
),