Nowadays there are many devices having different types of shaps, their screen is no more rectangular shape. some devices have a camera inside the screen area like a water drop from the middle of the plain surface.
Now how we can manage our app bar widget which has a center widget. SafeArea widget can only give useful when devices have corner edges.
AppBar(
elevation: 0,
title: Padding(
padding: const EdgeInsets.all(20),
child: isbgVisible
? Image.asset(
'assets/logosmal_.png',
scale: 1.5,
)
: Container(),
),
centerTitle: true,
actions: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: CircleAvatar(
child: Image.asset(
'assets/man.png',
scale: 1.5,
),
),
)
],
backgroundColor: isbgVisible ? Constants.whiteColor : Colors.transparent,
leading: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
width: 30,
height: 30,
child: IconButton(icon: Icon(Icons.menu), onPressed: () {}),
decoration:
BoxDecoration(shape: BoxShape.circle, color: Constants.darkYello),
),
),
);
SafeArea will be useful in that case:
How to use
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: TonsOfOtherWidgets();
),
),
}
For more information. visit here
Related
I imported [sliding up panel][2] from pub.dev and everything is good except for one issue. I'm looking for a way to center the 'blue circle' vertically. (in between 'red appbar' and 'buttom slider') I tried wraping the code with 'center' or using mainaxisalignment but it doesn't work. Other things I tried which I found on google just gave me an errors. Please help.
Thanks in advance
return Scaffold(
appBar: PreferredSize(
preferredSize: Size.fromHeight(200),
child: AppBar(
backgroundColor: Colors.pinkAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(bottom: Radius.circular(100))
),
flexibleSpace: Container(
alignment: Alignment.center,
child: Text(
'Red AppBar',
style: TextStyle(
color: Colors.white,
fontSize: 50.0,
fontWeight: FontWeight.bold
),
),
),
),
),
body: SlidingUpPanel(
renderPanelSheet: false,
panel: _floatingPanel(),
collapsed: _floatingCollapsed(),
body: ElevatedButton(
onPressed: () {},
child: Text('Blue Circle'),
style: ElevatedButton.styleFrom(
shape: CircleBorder(),
padding: EdgeInsets.all(20),
),
)
),
);
Widget _floatingCollapsed() {
return Container(
decoration: BoxDecoration(
color: Colors.blueGrey,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(24.0), topRight: Radius.circular(24.0)),
),
margin: const EdgeInsets.fromLTRB(24.0, 24.0, 24.0, 0.0),
child: Center(
child: Text(
"buttom slider",
style: TextStyle(color: Colors.white),
),
),
);
}
Widget _floatingPanel() {
return Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(24.0)),
boxShadow: [
BoxShadow(
blurRadius: 20.0,
color: Colors.grey,
),
]
),
margin: const EdgeInsets.all(24.0),
child: Center(
child: Text("LEVEL INFO"),
),
);
}
Also, what could be the best way to give margin to the 'blue circle' so it won't touch the far left and far right side of the screen?
The SlidingUpPanel's body is using Stack, also getting full screen size. You can check
#override
Widget build(BuildContext context) {
return Stack(
alignment: widget.slideDirection == SlideDirection.UP
? Alignment.bottomCenter
: Alignment.topCenter,
children: <Widget>[
//make the back widget take up the entire back side
widget.body != null
? AnimatedBuilder(
animation: _ac,
builder: (context, child) {
return Positioned(
top: widget.parallaxEnabled ? _getParallax() : 0.0,
child: child ?? SizedBox(),
);
},
child: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: widget.body,
),
)
You can play with Align on body and wrapping with SizedBox. You can use LayoutBuilder or MediaQuery to provide size.
body: SlidingUpPanel(
renderPanelSheet: false,
panel: _floatingPanel(),
collapsed: _floatingCollapsed(),
body: Align(
alignment: Alignment(0.0, -.3), //play with it
child: SizedBox(
width: 200,
height: 200,
child: ElevatedButton(
As per the documentation of sliding_up_panel, the body represents the widget that lies underneath the sliding panel and it automatically sizes itself to fill the screen. So it occupies full screen. Since you expanded AppBar to 200 unit, the body Widget was pushed down, hence you are seeing the centre point also pushed down by 200 unit. If you change the body height to occupy full screen from the start, by setting the Scaffold property extendBodyBehindAppBar with true, you will place the widget in the correct centre point.
if you add the below line immediately after the Scaffold. You will get desired result.
return Scaffold(
extendBodyBehindAppBar:true,
I would like to horizontally center the trailing icon of my expansionTile,
Here is my expansionTile with the trailing on the bottom right :
I already tried to encapsulate the Icon in a Align and a Container but doesn't work, I also tried Padding but it's not stable if you change the size of the screen.
Code with Align :
trailing : Align(
alignment: Alignment.center,
child: Icon(
BeoticIcons.clock,
color: BeoColors.lightGreyBlue
)
),
With Container :
trailing: Container(
alignment: Alignment.center,
child: Icon(
BeoticIcons.clock,
color: BeoColors.lightGreyBlue
)
),
Thanks for your help.
This will work for you. Use LayoutBuilder to get parent widget width, and set relative padding using constraints. For example, use constraints.maxWidth * 0.5, to center across width. Your padding will be stable if you change the size of the screen:)
trailing: LayoutBuilder(builder: (ctx, constraints) {
return Padding(
padding: EdgeInsets.only(
right: constraints.maxWidth * 0.5,
),
child: Icon(
Icons.menu,
),
);
}),
you can use column and align your icon like this way hope this code will help you, thank you
import 'package:flutter/material.dart';
class Hello extends StatelessWidget {
const Hello({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 140,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
color: Colors.deepPurple[200],
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
Center(child: Text("Hello")),
Text("Hello"),
SizedBox(height: 50,),
Align(
alignment: Alignment.center,
child: Icon(Icons.lock_clock))
],
),
),
),
),
),
);
}
}
Ok, I found how to do it.
Simply put the icon in the title attribute of the ExpansionTile :
return ExpansionTile(
title: Icon(
BeoticIcons.simply_down,
color: BeoColors.lightGreyBlue,
),
CODE:
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.blue,
body: SafeArea(
child: SingleChildScrollView(
physics: ClampingScrollPhysics(),
child: Align(
alignment: Alignment.center,
child: Container(
width: Get.width,
height: Get.width * 16 / 9,
child: Stack(
children: [
Positioned(top: 16, left: 16, child: BackButton()),
Positioned(
left: 0,
bottom: 0,
child: IconButton(
padding: EdgeInsets.symmetric(vertical: 0, horizontal: 0),
icon: Icon(
Icons.delete_forever,
color: Colors.greenAccent,
size: 32,
),
onPressed: () {
},
),
),
],
),
),
),
),
),
);
}
There is some margin on IconButton.
I think IconButton should be tight on bottom left.
How to remove margin IconButton and screen side?
Actually it's the default padding of the Icon Button only...
That is, the stack is placing the button at bottom left but icon in the button is padded by default.
You can try using Gesture detector with that icon as a child...
You will get different result...
Please correct me if i am wrong..
I'm trying to create a Container with a curve on the middle top and put a Round Button inside the curve. It should look similar to the Curved Navigation Bar package from Flutter, however, just without the animation.
I've tried to work with Stack and Positioned, however, Flutter doesn't convert it how I imagine it to be.
class CurvedContainerWithButtonAtTopCenter extends StatelessWidget{
#override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
body: Container(
height: 200.0,
child: Stack(
children: <Widget>[
Positioned(
top: 30.0,
right: 0.0,
left: 0.0,
child: Container(
height: 170.0,
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(horizontal: 20.0, vertical:
40.0),
color: Colors.blue,
)),
Container(
height: 60.0,
width: 60.0,
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle),
alignment: FractionalOffset.center,
child: Container(
margin: EdgeInsets.all(10.0),
child: FloatingActionButton(),
)
)
],
)
)
);
}
}
I would expect the Container to take the full width and be positioned a little bit lower. The Circle should be in the Center at the Top Border of the Container. The Circle should also contain a FloatingActionButton.
I hope you've found the answer by now, but just in case... bellow you can find a potential solution:
build function
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Text('Hello'),
),
bottomNavigationBar: _navigationDrawer,
floatingActionButton: FloatingActionButton(
backgroundColor: Colors.orange,
child: Icon(Icons.add),
onPressed: () {}),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerDocked);
}
getter for bottom navigation
Widget get _navigationDrawer {
return Container(
height: 80.0,
child: BottomAppBar(
shape: CircularNotchedRectangle(),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
IconButton(
icon: Icon(Icons.home),
onPressed: () {},
),
Padding(
padding: const EdgeInsets.only(right: 50),
child: IconButton(
icon: Icon(Icons.search),
onPressed: () {},
),
),
Padding(
padding: const EdgeInsets.only(left: 50),
child: IconButton(
icon: Icon(Icons.note_add),
onPressed: () {},
),
),
IconButton(
icon: Icon(Icons.portrait),
onPressed: () {},
),
],
)),
);
}
And the result
Hope this helps :) Happy coding !!!
Where am I supposed to place the material as the parent of the Raw material button so that it can respond to clicks and show splash color.
The widget tree looks like below.
Widget build(BuildContext context) {
return new Container(
child: new Center(
child: new Stack(
alignment: Alignment.center,
children: <Widget>[
new Container(
child: new Padding(
padding: const EdgeInsets.all(5.0),
child: new Container(
child: new AudioComponent(
updateMe: [WatchableAudioProperties.audioPlayerState],
playerBuilder: (BuildContext context, AudioPlayer
player,
Widget child) {
IconData icon = Icons.play_arrow;
return new RawMaterialButton(
shape: new CircleBorder(),
fillColor: Colors.white,
splashColor: lightAccentColor,
highlightColor: lightAccentColor.withOpacity(0.5),
elevation: 10.0,
highlightElevation: 5.0,
onPressed: (){},
child: new Padding(
padding: const EdgeInsets.all(8.0),
child: new Icon(
icon,
color: accentColor,
size: 50.0,
),
),
);
},
),
),
),
),
new Container(
height: 151.0,
width: 151.0,
child: waves,
),
],
),
),
);
}
If I add another container onto the stack and put a similar RawMaterial button, it responds as required even without adding a material widget anywhere. What I don't understand why the RawButton in the first container in the stack is not working
How do you expect to have your RawMaterialButton react when you have the following code in it's definition?
onPressed: (){},