A RenderFlex overflowed by 86 pixels on the bottom in Flutter - flutter

I am creating an app in flutter and in the portrait mode everything looks fine but when it comes to landscape mode it will be triggered with an error saying A RenderFlex overflowed by 86 pixels on the bottom. Below is my all code that I have tried and also I have shared the images, please refer to the same for more clarification.
import 'dart:math';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
brightness: Brightness.dark
),
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
body: new Stack(
children: <Widget>[
Container(
decoration: ShapeDecoration(
gradient:LinearGradient(
begin: Alignment.bottomLeft,
end: Alignment.topRight,
colors: [Colors.yellow,Colors.yellow,Colors.orangeAccent,Colors.deepOrange,]
),
// color: Colors.deepOrangeAccent,
shape: CustomShapeBorder(),
),
),
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 200.0,left: 50.0),
child: Text(
"SET, MATCH AND CHALLENGE",
style: TextStyle(
fontSize: 40.0,
),
),
),
Padding(
padding: const EdgeInsets.only(left: 30.0,right: 30.0, top: 30.0),
child: Text(
"A simple, fun, and a creative way to "
"set the bespoke challenges with "
"either a friend or a group of "
"friends anywhere in the world",
textAlign: TextAlign.justify,
style: TextStyle(
color: Colors.white
),
),
),
Container(
width: 300.0,
height: 60.0,
margin: const EdgeInsets.only(top: 140.0),
child: RaisedButton(
textColor: Colors.white,
color: Colors.grey,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(18.0),
),
child: Text("Sign Up",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0,
),
),
),
),
],
),
Container(
margin: const EdgeInsets.only(bottom: 0.0, right: 0.0),
child: Align(
alignment: Alignment.bottomRight,
child: Transform.rotate(
angle: pi,
child: Container(
decoration: ShapeDecoration(
gradient:LinearGradient(
begin: Alignment.bottomLeft,
end: Alignment.topRight,
colors: [Colors.yellow,Colors.yellow,Colors.orangeAccent,Colors.deepOrange,]
),
//color: Colors.deepOrangeAccent,
shape: CustomShapeBorder(),
),
),
),
),
),
],
),
);
}
}
class CustomShapeBorder extends ShapeBorder {
final double distanceFromWall = 12;
final double controlPointDistanceFromWall = 5;
#override
// TODO: implement dimensions
EdgeInsetsGeometry get dimensions => null;
#override
Path getInnerPath(Rect rect, {TextDirection textDirection}) {
// TODO: implement getInnerPath
return null;
}
#override
Path getOuterPath(Rect rect, {TextDirection textDirection}) {
// TODO: implement getOuterPath
return getClip(Size(260.0,180.0));
}
#override
void paint(Canvas canvas, Rect rect, {TextDirection textDirection}) {
// TODO: implement paint
}
#override
ShapeBorder scale(double t) {
// TODO: implement scale
return null;
}
Path getClip(Size size) {
Path clippedPath = new Path();
clippedPath.lineTo(0, size.height);
clippedPath.quadraticBezierTo(30, size.height + 10, size.width * 0.20, size.height - 50);
clippedPath.quadraticBezierTo(70, size.height - 120, size.width * 0.40, size.height * 0.35);
clippedPath.quadraticBezierTo(180, (size.height - (size.height* 0.6)), size.width - 40 , 32 );
clippedPath.quadraticBezierTo(250, 0, size.width, 0);
clippedPath.lineTo(size.width, 0);
clippedPath.close();
return clippedPath;
}
}
Refer to below image for Portrait Mode
Refer to below image for Landscape Mode (Where error occurs):

The problem is that you are using hardcode margins in a Column widget, that will give you problems in small devices too. You can fix that changing you Column Widget for a ListView Widget, but that is going to give you a Scroll Effect, I think you don't want that. So you can refactor that Column using Expanded Widget and a Stack can help in the first part of the Column, try the next:
Column(
children: <Widget>[
Expanded(
flex: 1,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 50),
child: Stack(
children: <Widget>[
Center(
child: Text(
"SET, MATCH AND CHALLENGE",
style: TextStyle(
fontSize: 40.0,
),
),
),
Align(
alignment: Alignment.bottomCenter,
child: Text(
"A simple, fun, and a creative way to "
"set the bespoke challenges with "
"either a friend or a group of "
"friends anywhere in the world",
textAlign: TextAlign.justify,
style: TextStyle(
color: Colors.white
),
),
)
],
),
),
),
Expanded(
flex: 1,
child: Center(
child: Container(
width: 300.0,
height: 60.0,
child: RaisedButton(
textColor: Colors.white,
color: Colors.grey,
shape: RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(18.0),
),
child: Text("Sign Up",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20.0,
),
),
),
),
),
)
],
)

Related

Need help to build custom widget in flutter

Hey I try to create a custom widget like this, where I can change the text in the bottom part of the card.
I already create the shape but I have no idea on how to place Text('Aktif'), I tried using Stack or Column but none works, any Idea?
Here is my code:
#override
Widget build(BuildContext context) {
return Stack(
children: [
Card(
shape: CardShape(),
elevation: 18,
shadowColor: const Color.fromRGBO(51, 0, 0, 0.1),
color: CustomStyle.primaryRed,
child: Container(
decoration: BoxDecoration(
color: CustomStyle.white,
border: Border.all(color: CustomStyle.primaryRed),
borderRadius: BorderRadius.circular(8)),
padding: const EdgeInsets.symmetric(vertical: 8),
child: ListTile(
title: const Text('Rumah Tanggerang'),
subtitle: const Text('Primary - 1234567890'),
trailing: Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'DEFAULT',
),
myPopMenu()
],
),
),
),
),
Positioned(left: 10, bottom: 0, child: Text('Aktif'))
],
);
}
class CardShape extends ShapeBorder {
const CardShape();
final BorderSide _side = BorderSide.none;
final BorderRadiusGeometry _borderRadius = BorderRadius.zero;
#override
EdgeInsetsGeometry get dimensions => EdgeInsets.all(_side.width);
#override
Path getInnerPath(
Rect rect, {
TextDirection? textDirection,
}) {
final Path path = Path();
path.addRRect(
_borderRadius.resolve(textDirection).toRRect(rect).deflate(_side.width),
);
return path;
}
#override
Path getOuterPath(Rect rect, {TextDirection? textDirection}) {
final Path path = Path();
final RRect rrect = _borderRadius.resolve(textDirection).toRRect(rect);
path.moveTo(0, 10);
path.quadraticBezierTo(0, 0, 10, 0);
path.lineTo(rrect.width - 10, 0);
path.quadraticBezierTo(rrect.width, 0, rrect.width, 10);
path.lineTo(rrect.width, rrect.height - 10);
path.quadraticBezierTo(
rrect.width, rrect.height, rrect.width - 10, rrect.height);
path.lineTo(100, rrect.height);
path.lineTo(80, rrect.height + 20);
path.lineTo(10, rrect.height + 20);
path.quadraticBezierTo(0, rrect.height + 20, 0, rrect.height + 10);
return path;
}
#override
void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) {}
#override
ShapeBorder scale(double t) => RoundedRectangleBorder(
side: _side.scale(t),
borderRadius: _borderRadius * t,
);
}
Card widget can't used stack because the red container is already outside the Card element so to put the text you just can wrap Stack inside of a Column and put the Text widget without position this is the example that I've already did
class Test extends StatelessWidget {
const Test({super.key});
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
decoration: const BoxDecoration(color: Colors.blue),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
Card(
shape: const CardShape(),
elevation: 18,
shadowColor: const Color.fromRGBO(51, 0, 0, 0.1),
color: Colors.red,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: Colors.red),
borderRadius: BorderRadius.circular(8)),
padding: const EdgeInsets.symmetric(vertical: 8),
child: ListTile(
title: const Text('Rumah Tanggerang'),
subtitle: const Text('Primary - 1234567890'),
trailing: Row(
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: const <Widget>[
Text(
'DEFAULT',
),
],
),
),
),
),
],
),
const Padding(
padding: EdgeInsets.only(
left: 30,
),
child: Text(
'Aktif',
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.w700),
),
)
],
),
),
),
);
}
}
if you copy my code just made sure to change back the color you've used.

dynamic progress bar in flutter

I want to create a progress bar in flutter which is like this
I get the data of week from backend but I have to create it this way.
and the icon on weeks or survey should be touchable.
thanks in advance.
Still a lot of things to change, but i thing it should be enough for the beginning
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
#override
Widget build(BuildContext context) {
List<String> points = [
'Survey',
'Week 1',
'Week 2',
'Week 3',
'Week 4',
];
var lineWidth =
MediaQuery.of(context).size.width - 16.0; // screen width - 2 * padding
var space = lineWidth / points.length; //space between dots
var currentSteps = 3; // <---- change this one
return Scaffold(
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: SizedBox(
height: 60.0,
child: Stack(
children: [
//grey line
Positioned(
top: 15,
left: 0,
right: 0,
child: Container(
height: 2.0,
width: double.infinity,
color: Colors.grey,
),
),
//red line
Positioned(
top: 15,
left: 0,
child: Container(
height: 2.0,
width: space * (currentSteps - 1) + space / 2,
color: Colors.orange,
),
),
//circles
Row(
children: points
.asMap()
.map((i, point) => MapEntry(
i,
SizedBox(
width: space,
child: Column(
children: [
Stack(
children: [
Container(
height: 30.0,
width: 30.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 1.5,
color: i == currentSteps - 1
? Colors.orange
: Colors.transparent,
),
),
child: Center(
child: Container(
height: 20.0,
width: 20.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: i < currentSteps
? Colors.orange
: Colors.grey,
),
),
),
),
if (i < currentSteps - 1)
const SizedBox(
height: 30.0,
width: 30.0,
child: Center(
child: Icon(
Icons.check,
size: 16.0,
color: Colors.white,
),
),
),
],
),
const SizedBox(height: 4.0),
Text(
point,
textAlign: TextAlign.left,
style: TextStyle(
color: i < currentSteps
? Colors.orange
: Colors.grey,
),
),
],
),
),
))
.values
.toList(),
),
],
),
),
),
),
);
}
}
You can try basic Stepper widget with type: StepperType.horizontal. As for the UI you like im_stepper package. If it fails to satisfy you can create custom widget with Stack and Row.
Try basic Stepper widget of flutter. if its not working properly then you need to create custom widget.

How create an arrow-tab-like design in flutter

anyone who knows how to do a design like this when clicking the first arrow,
one screen appears and after completing that screen the tab color changes to green ,
then clicking on the second arrow second screen appears ,
then after clicking on third arrow third screen appears ,
just working like a tab screen , how can I achieve this in flutter?
class MainUiPage extends StatefulWidget {
const MainUiPage({Key? key}) : super(key: key);
#override
_MainUiPageState createState() => _MainUiPageState();
}
class _MainUiPageState extends State<MainUiPage> with SingleTickerProviderStateMixin{
TabController? _tabController;
#override
void initState() {
_tabController = TabController(length: 3, vsync: this);
super.initState();
}
#override
void dispose() {
super.dispose();
_tabController?.dispose();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: /*Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
// give the tab bar a height [can change hheight to preferred height]
Container(
height: 45,
decoration: BoxDecoration(
color: Colors.grey[300],
// borderRadius: BorderRadius.circular(
// 25.0,
// ),
),
child: TabBar(
controller: _tabController,
// give the indicator a decoration (color and border radius)
indicator: BoxDecoration(
borderRadius: BorderRadius.circular(
25.0,
),
color: Colors.green,
),
labelColor: Colors.white,
unselectedLabelColor: Colors.black,
tabs: [
// first tab [you can add an icon using the icon property]
Tab(
text: 'Place Bid',
),
// second tab [you can add an icon using the icon property]
Tab(
text: 'Buy Now',
),
Tab(
text: 'Buy Now',
),
],
),
),
// tab bar view here
Expanded(
child: TabBarView(
controller: _tabController,
children: [
// first tab bar view widget
Center(
child: Text(
'Place Bid',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.w600,
),
),
),
// second tab bar view widget
Center(
child: Text(
'Buy Now',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.w600,
),
),
),
// second tab bar view widget
Center(
child: Text(
'Buy Now',
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.w600,
),
),
),
],
),
),
],
),
),*/
Row(
children: [
SizedBox(width: 15.w,),
SizedBox(
height: 250.h,
width: 70.w,
child: CustomPaint (
painter: RPSCustomPainter1(),
child: Align(
alignment: Alignment(-.2, -0.1), //litle left
child: Text(
"machines",
style: TextStyle(
fontSize: 18.sp,
),
),
),
),
),
SizedBox(
height: 250.h,
width: 70.w,
child: CustomPaint(
painter: RPSCustomPainter2(),
child: Align(
alignment: const Alignment(-.2, -0.1), //litle left
child: Text(
"materials",
style: TextStyle(
fontSize: 18.sp,
),
),
),
),
),
SizedBox(
// Size(WIDTH,(WIDTH*0.58).toDouble())
// Size(WIDTH, (WIDTH*0.14901960784313725).toDouble()),
// Size(WIDTH,(WIDTH*0.8125).toDouble()),
height: 250.h,
width: 70.w,
child: CustomPaint(
painter: RPSCustomPainter3(),
child: Align(
alignment: const Alignment(-.2, -0.1), //litle left
child: Text(
"component",
style: TextStyle(
fontSize: 18.sp,
),
),
),
),
),
SizedBox(
// Size(WIDTH,(WIDTH*0.58).toDouble())
// Size(WIDTH, (WIDTH*0.14901960784313725).toDouble()),
// Size(WIDTH,(WIDTH*0.8125).toDouble()),
height: 250.h,
width: 70.w,
child: CustomPaint(
painter: RPSCustomPainter3(),
child: Align(
alignment: const Alignment(-.2, -0.1), //litle left
child: Text(
"component",
style: TextStyle(
fontSize: 18.sp,
),
),
),
),
),
],
),
),
);
}
}
here is the sample code I had done, but it doesn't work correctly , anyone how to do this please help , I'm new to this.
You need to do something like that.... wrap all your Container in a Stack and set Positioned of every Container.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Welcome to Flutter',
home: Scaffold(
appBar: AppBar(
title: const Text('Welcome to Flutter'),
),
body: Container(
width: double.infinity,
child: Stack(
children: [
Positioned(
left: 0,
child: ClipPath(
clipper: CustomClipPathTopContainerOne(),
child: Container(
height: 50,
width: 200,
color: Colors.green,
),
),
),
Positioned(
left: 175,
child: ClipPath(
clipper: CustomClipPathTopContainerSecond(),
child: Container(
height: 50,
width: 200,
color: Colors.red,
),
),
),
Positioned(
left: 350,
child: ClipPath(
clipper: CustomClipPathTopContainerSecond(),
child: Container(
height: 50,
width: 200,
color: Colors.pink,
),
),
),
],
)
),
),
);
}
}
class CustomClipPathTopContainerOne extends CustomClipper<Path> {
#override
Path getClip(Size size) {
double w = size.width;
double h = size.height;
Paint paint = Paint()
..style = PaintingStyle.stroke
..strokeWidth=10.0
..color = Colors.black;
Path path0 = Path();
path0.moveTo(0,size.height);
path0.lineTo(0,size.height*0.4890143);
path0.lineTo(0,0);
path0.lineTo(size.width*0.8545167,0);
path0.lineTo(size.width,size.height*0.4991714);
path0.lineTo(size.width*0.8551250,size.height);
path0.lineTo(0,size.height);
path0.lineTo(size.width*0.0013417,size.height);
path0.lineTo(0,size.height);
path0.close();
return path0;
}
#override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
class CustomClipPathTopContainerSecond extends CustomClipper<Path> {
#override
Path getClip(Size size) {
double w = size.width;
double h = size.height;
Paint paint = Paint()
..style = PaintingStyle.stroke
..strokeWidth=10.0
..color = Colors.black;
Path path0 = Path();
path0.moveTo(0,size.height);
path0.lineTo(size.width*0.1459833,size.height*0.5012000);
path0.lineTo(0,0);
path0.lineTo(size.width*0.8545167,0);
path0.lineTo(size.width,size.height*0.4991714);
path0.lineTo(size.width*0.8551250,size.height);
path0.lineTo(0,size.height);
path0.lineTo(size.width*0.0013417,size.height);
path0.lineTo(0,size.height);
path0.close();
return path0;
}
#override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}

Can't place text in the bottom of the screen when using column

I wrote a flutter app that uses a column widget with TextFormField and some title, and now I want to place another text widget on the bottom of the screen, I tried use the Align widget but it seems to work for me only when I use it without any other widgets, when I use it inside the column widget it not working and have no effect and place it right under the previous widget. (I tried to use the Expanded widget as well but it not working either.)
Someone know how can I fix it?
I also can't rounded the "create account" container borders so if someone know how can I also do that it will be much appreciated
this is my code:
// imports...
class CreateName extends StatefulWidget {
const CreateName({Key? key, this.phoneNumber, this.userId}) : super(key: key);
final phoneNumber;
final userId;
#override
_CreateNameState createState() => _CreateNameState(phoneNumber, userId);
}
class _CreateNameState extends State<CreateName> {
late final phone;
late final uid;
late double _formHeight;
late String username;
final _varKey = GlobalKey<FormState>();
Color buttonColorBack = const Color(0xDCDCDCDC);
Color buttonColorText = Colors.black;
Color saveButtonColorText = const Color(0xDCDCDCDC);
_CreateNameState(this.phone, this.uid);
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
if (size.height <= 736) {
_formHeight = (size.height * .05) + 6;
} else {
_formHeight = size.height * .048;
}
return Scaffold(
body: SafeArea(
child: GestureDetector(
onTap: () => FocusScope.of(context).requestFocus(
FocusNode(),
),
child: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: size.height - 90,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Stack(
alignment: Alignment.topLeft,
children: [
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Padding(
padding: EdgeInsets.only(
top: size.height * .006,
left: size.width * .03,
),
child: SvgPicture.asset(
"assets/arrow-back.svg",
),
),
),
],
),
Padding(
padding: EdgeInsets.only(
top: size.height * .18,
),
child: Center(
child: Text(
"Create a Username",
style: TextStyle(
fontSize: size.width * .066,
letterSpacing: size.width * .015,
fontWeight: FontWeight.w300,
),
),
),
),
Padding(
padding: EdgeInsets.only(
top: size.height * .015,
),
child: Center(
child: Container(
margin: EdgeInsets.symmetric(
horizontal: size.width * .045,
),
height: _formHeight,
child: Form(
key: _varKey,
child: TextFormField(
style: TextStyle(
fontSize: size.width * .035,
),
decoration: InputDecoration(
contentPadding: const EdgeInsets.fromLTRB(
0,
10,
0,
0,
),
hintText: 'Username',
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(7.0),
borderSide: const BorderSide(
color: Colors.black,
width: 1.25,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(7.0),
borderSide: const BorderSide(
color: Colors.black,
width: 1.5,
),
),
),
autofocus: false,
cursorColor: Colors.black,
textAlign: TextAlign.center,
onChanged: (input) {
setState(() {
if (input.length > 1) {
buttonColorBack = Colors.black;
buttonColorText = Colors.white;
} else if (input.length < 1) {
buttonColorBack = saveButtonColorText;
buttonColorText = Colors.black;
}
});
},
onSaved: (input) async {
username = input!;
},
),
),
),
),
),
GestureDetector(
child: Padding(
padding: EdgeInsets.symmetric(
vertical: size.height * .01,
horizontal: size.width * .02,
),
child: Container(
height: _formHeight,
color: buttonColorBack,
child: Center(
child: Text(
"Create account",
style: TextStyle(
fontSize: size.width * .035,
color: buttonColorText,
),
),
),
),
),
onTap: () {
_varKey.currentState!.save();
if (username.length > 1) {
loginUser(uid, phone, username);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const ClientHomePage(),
),
);
} else {
print("enter username");
}
},
),
Align( // here is the widget that I want to place in the bottom of the screen
alignment: Alignment.bottomCenter,
child: Text("test"),
),
],
),
),
),
),
),
);
}
}
the reason is that Column's height is not fullscreen. It just has enough height to show all widgets in it, so alignment will not help in this situation.
But you can use Spacer widget which will take all available space on screen in Column.
For example:
Column(
children: [
widgets
...
const Spacer(),
Text('Hello world!'), //widget which you want to be at the bottom of screen
],
),
If you want to add rounded borders to container add decoration. Notice that you can't use decoration and color parameters at the same time, but you can specify color in decoration!
Container(
decoration: BoxDecoration(
color: Colors.black, //or any other color
borderRadius: BorderRadius.circular(16.0) //this value changes borderRadius,
boxShape: BoxShape.circle //if you need a circle container use this instead of border radius
),
)
Attention! You can't use Spacer() if Column is in ScrollView. If there is not lots of content in Column, and every screen you need can handle it do not use ScrollView.

how to overlap items on Appbar flutter

I want to achieve have a round icon for the profile image like in this example:
But is not working for me, this is what I achieved so far:
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
ClipPath(
clipper: _AppBarProfileClipper(childHeight),
child: Container(
padding: const EdgeInsets.only(top: 48.0),
color: TheBaseColors.lightBlue,
height: height,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
leading,
FlatButton(
onPressed: null,
child: Text(
title,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18.0,
color: Colors.white,
),
),
),
trailing,
],
),
),
),
Positioned(
bottom: childHeight / 2, //50
left: 0,
right: 0,
child: Align(
alignment: Alignment.bottomCenter,
child: child,
),
),
],
);
}
}
All the parameters are represented in the constructor and used in the code. But I cant figure out how to make that nice effect with the rounded icon.
Someone knows why is not working?
You can achieve given example like this:
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final double appBarHeight = 100.0;
final double spaceAroundRoundButton = 4.0;
final double roundedButtonSize = 64.0;
#override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
return SafeArea(
child: Stack(
children: <Widget>[
Scaffold(
backgroundColor: Colors.white,
appBar: PreferredSize(
preferredSize:
Size(MediaQuery.of(context).size.width, appBarHeight),
child: ClipPath(
clipper: BottomClipper(),
child: Container(
alignment: Alignment.topLeft,
height: appBarHeight,
color: Colors.black,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
icon: Icon(
Icons.menu,
color: Colors.white,
),
onPressed: () {}),
Text(
'User Profile',
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
IconButton(
icon: Icon(
Icons.settings,
color: Colors.white,
),
onPressed: () {})
],
),
),
)),
body: Container(
alignment: Alignment.topCenter,
margin: EdgeInsets.only(
top:
roundedButtonSize * 0.75 + spaceAroundRoundButton + 16.0),
child: Text('Body'),
),
),
Positioned(
child: Container(
padding: EdgeInsets.all(spaceAroundRoundButton),
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
child: RawMaterialButton(
elevation: 0,
constraints: BoxConstraints.tightFor(
width: roundedButtonSize, height: roundedButtonSize),
shape: StadiumBorder(
side: BorderSide(width: 4, color: Colors.grey)),
child: Icon(Icons.person),
onPressed: () {},
fillColor: Colors.white,
),
),
left: (size.width / 2) -
(roundedButtonSize / 2) -
spaceAroundRoundButton,
top: appBarHeight -
(roundedButtonSize * 0.25) -
spaceAroundRoundButton,
)
],
),
);
}
}
class BottomClipper extends CustomClipper<Path> {
#override
Path getClip(Size size) {
var path = Path();
path.lineTo(0.0, size.height * 0.75);
var firstControlPoint = Offset(size.width * 0.25, size.height);
var firstEndPoint = Offset(size.width * 0.5, size.height);
path.quadraticBezierTo(firstControlPoint.dx, firstControlPoint.dy,
firstEndPoint.dx, firstEndPoint.dy);
var secondControlPoint = Offset(size.width * 0.75, size.height);
var secondEndPoint = Offset(size.width, size.height * 0.75);
path.quadraticBezierTo(secondControlPoint.dx, secondControlPoint.dy,
secondEndPoint.dx, secondEndPoint.dy);
path.lineTo(size.width, 0.0);
path.close();
return path;
}
#override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
Screenshot: