Related
What I have at the moment is a Column which has two children: a Stack representing the header of the page and a Container meaning the body of the page ( let's call it that way ). What I'm trying to achieve is, when scrolling down on the screen, make the Stack component disappear and fix the Container at the top of the page and make its content scrollable.
I tried using:
NestedScrollView but I could manage to find a way to use a different type of widgets for the headerSliverBuilder except SliverAppBar or something like that
CustomSilverDelegate which extends SilverPersistentHeaderDelegate, but as well it didn't meet my needs
SingleChildScrollView but it doesn't meet my needs
I'm pretty new to Flutter and still can't figure out which widget works best, also I couldn't find a widget to meet my needs regarding this issue.
Here is my code:
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
border: Border.all(
color: Theme.of(context).colorScheme.primary, width: 5),
),
child: SingleChildScrollView(
child: Column(
children: [
Stack(
children: [
Container(
height: 220,
width: MediaQuery.of(context).size.width,
decoration: const BoxDecoration(
boxShadow: [
BoxShadow(
color: Color.fromRGBO(55, 0, 60, 0.3),
spreadRadius: 1,
blurRadius: 4,
offset: Offset(3, 6), // changes position of shadow
),
],
color: Color.fromRGBO(55, 0, 60, 1),
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(30),
bottomLeft: Radius.circular(30))),
child: ShaderMask(
shaderCallback: (rect) {
return const LinearGradient(
tileMode: TileMode.clamp,
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [
Color.fromRGBO(55, 0, 60, 0),
Color.fromRGBO(55, 0, 60, 1)
],
).createShader(
Rect.fromLTRB(0, 0, rect.width, rect.height));
},
blendMode: BlendMode.dstIn,
child: Image.asset(
'assets/images/serie-a.png',
color: const Color.fromRGBO(84, 6, 87, 1),
fit: BoxFit.fitHeight,
alignment: Alignment.topRight,
),
),
),
Container(
height: 220,
alignment: Alignment.topCenter,
child: Padding(
padding:
const EdgeInsets.only(top: 40, right: 20, left: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
height: 40,
width: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Theme.of(context).colorScheme.primary),
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Icon(
Icons.arrow_back,
color: Theme.of(context).colorScheme.tertiary,
),
),
),
const Text(
"Premier League",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20,
color: Colors.white),
),
Container(
height: 40,
width: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Theme.of(context).colorScheme.primary),
child: Padding(
padding: const EdgeInsets.all(3.0),
child: Icon(
Icons.search,
color: Theme.of(context).colorScheme.tertiary,
),
),
),
],
),
),
),
Padding(
padding:
const EdgeInsets.only(top: 110, right: 20, left: 20),
child: ClipRRect(
borderRadius: BorderRadius.circular(20),
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 30, sigmaY: 30),
child: Container(
width: MediaQuery.of(context).size.width,
height: 220,
alignment: Alignment.topCenter,
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
color: Colors.white.withOpacity(0.5),
borderRadius:
const BorderRadius.all(Radius.circular(20))),
child: Container(
padding: const EdgeInsets.only(left: 15, right: 15),
height: 200,
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 18.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Premier League",
style: TextStyle(
color: Colors.grey.shade800,
fontSize: 15,
fontWeight: FontWeight.bold),
)
],
),
),
Padding(
padding: const EdgeInsets.only(top: 5.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Week 10",
style: TextStyle(
color: Colors.grey.shade600,
fontSize: 13),
)
],
),
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
SizedBox(
width: MediaQuery.of(context).size.width /
2 -
74,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(
top: 8, left: 20, right: 20),
child: SizedBox(
height: 75,
width: 70,
child: Image.asset(
"assets/images/newcastle.png"),
),
),
Text(
"Newcastle asdsadas",
style: TextStyle(
fontSize: 18,
color: Colors.grey.shade700),
textAlign: TextAlign.center,
),
const Padding(
padding: EdgeInsets.only(top: 5.0),
child: Text(
"Home",
style: TextStyle(
color: Colors.grey,
fontSize: 11),
),
),
],
),
),
SizedBox(
width: 60,
child: Padding(
padding:
const EdgeInsets.only(top: 20.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Text(
"0 : 9",
style: TextStyle(
color: Colors.grey.shade900,
fontSize: 31,
fontWeight: FontWeight.bold),
),
Padding(
padding: const EdgeInsets.only(
top: 13.0),
child: Container(
alignment: Alignment.center,
height: 30,
width: 40,
decoration: BoxDecoration(
color: const Color.fromRGBO(
255, 40, 130, 1)
.withOpacity(0.2),
border: Border.all(
color:
const Color.fromRGBO(
255, 40, 130, 1),
width: 1),
borderRadius:
BorderRadius.circular(25),
),
child: const Text(
"113'",
style: TextStyle(
color: Color.fromRGBO(
255, 40, 130, 1),
fontSize: 11),
),
),
),
],
),
),
),
SizedBox(
width: MediaQuery.of(context).size.width /
2 -
74,
child: Column(
crossAxisAlignment:
CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(
top: 8, left: 20, right: 20),
child: SizedBox(
height: 75,
width: 55,
child: Image.asset(
"assets/images/chelsea.png"),
),
),
Text(
"Newcastle asdfddd",
style: TextStyle(
fontSize: 18,
color: Colors.grey.shade700),
textAlign: TextAlign.center,
),
const Padding(
padding: EdgeInsets.only(top: 5.0),
child: Text(
"Away",
style: TextStyle(
color: Colors.grey,
fontSize: 11),
),
),
],
),
)
],
),
],
),
),
),
),
),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 30, right: 20, left: 20),
child: Container(
height: 400,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
color: Colors.white,
borderRadius: const BorderRadius.all(Radius.circular(10)),
),
child: Padding(
padding: const EdgeInsets.only(left: 10, right: 10),
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 15, bottom: 20),
child: SizedBox(
child: TabBar(
labelPadding:
const EdgeInsets.symmetric(horizontal: 10),
isScrollable: true,
indicatorWeight: 0,
labelStyle: const TextStyle(fontSize: 13),
unselectedLabelColor: Colors.grey.shade700,
labelColor: Colors.white,
indicator: const ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(15))),
color: Colors.pink),
tabs: const [
Tab(
text: "Summary",
),
Tab(
text: "Info",
),
Tab(
text: "Line-up",
),
Tab(
text: "H2H",
),
Tab(
text: "Table",
),
Tab(
text: "News",
),
Tab(
text: "Info",
),
Tab(
text: "Info",
),
Tab(
text: "Info",
),
Tab(
text: "Info",
),
],
controller: _tabController,
indicatorSize: TabBarIndicatorSize.tab,
),
),
),
Expanded(
flex: 1,
child: TabBarView(
controller: _tabController,
children: const [
Text("abcd"),
Text("abcd"),
Text("abcd"),
Text("abcd"),
Text("abcd"),
Text("abcd"),
Text("abcd"),
Text("abcd"),
Text("abcd"),
Text("abcd"),
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
Text("2"),
Text("Shots on goal"),
Text("3")
],
),
const SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
width: MediaQuery.of(context).size.width / 2 - 36,
child: LinearPercentIndicator(
lineHeight: 7,
percent: 0.7,
padding: const EdgeInsets.only(right: 2),
backgroundColor:
const Color.fromRGBO(255, 40, 130, 1)
.withOpacity(0.1),
progressColor:
const Color.fromRGBO(255, 40, 130, 1),
animation: true,
animationDuration: 1000,
barRadius: const Radius.circular(20),
isRTL: true,
),
),
SizedBox(
width: MediaQuery.of(context).size.width / 2 - 36,
child: LinearPercentIndicator(
padding: const EdgeInsets.only(left: 2),
lineHeight: 7,
percent: 0.3,
backgroundColor:
const Color.fromRGBO(255, 40, 130, 1)
.withOpacity(0.1),
progressColor:
const Color.fromRGBO(55, 0, 60, 1),
animation: true,
animationDuration: 500,
barRadius: const Radius.circular(20),
),
),
],
),
],
),
),
),
),
],
),
),
),
);
}
Screenshots with my view and what I want to achieve:
Normal Screen:
https://ibb.co/GxCG0m1
What I'm trying to achieve when scrolling:
https://ibb.co/F0b37s9
Thanks in advance for any help !
Scaffold(
resizeToAvoidBottomInset: false,
body: Container(
height: 100,
width: MediaQuery.of(context).size.width * 1,
color: const Color(0xFF722a8c),
child: ListView(
children: [
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.only(top: 10),
child: Text(
"COLORS ",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
),
const SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.only(left: 28),
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(left: 0),
child: Container(
height: 40,
width: 40,
decoration: BoxDecoration(
color: Colors.black,
borderRadius: BorderRadius.circular(20),
),
child: const Icon(
Icons.check,
color: Colors.white,
),
),
),
const SizedBox(
width: 5,
),
Container(
height: 40,
width: 40,
decoration: BoxDecoration(
color: const Color(0xFFf44136),
borderRadius: BorderRadius.circular(20),
),
),
const SizedBox(
width: 5,
),
Container(
height: 40,
width: 40,
decoration: BoxDecoration(
color: const Color(0xFF2295f6),
borderRadius: BorderRadius.circular(20),
),
),
const SizedBox(
width: 5,
),
Container(
height: 40,
width: 40,
decoration: BoxDecoration(
color: Color(0xFF4daf52),
borderRadius: BorderRadius.circular(20),
),
),
],
),
)
],
),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.only(top: 20),
child: Text(
"CLEAR ALL ",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
),
const SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.only(right: 50),
child: Row(
children: [
Padding(
padding: EdgeInsets.only(left: 50),
child: Container(
height: 40,
width: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border:
Border.all(color: Colors.white, width: 3),
),
child: const Icon(
Icons.clear,
color: Colors.white,
),
),
),
],
),
),
]),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.only(top: 20),
child: Text(
"ERASER",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
),
const SizedBox(
height: 5,
),
Padding(
padding: const EdgeInsets.only(right: 50),
child: Row(children: [
Padding(
padding: const EdgeInsets.only(left: 60),
child: Container(
height: 40,
width: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
),
child: Image.asset(
'assets/icon.png',
color: Colors.white,
),
),
),
]),
)
]),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.only(top: 20),
child: Text(
"UNDO ",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
),
Padding(
padding: const EdgeInsets.only(right: 10),
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(left: 20),
child: Container(
height: 40,
width: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
),
child: const Icon(
Icons.undo,
color: Colors.white,
size: 45,
),
),
),
],
),
),
]),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.only(top: 20),
child: Text(
"REDO ",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
),
Padding(
padding: const EdgeInsets.only(right: 100),
child: Row(children: [
Padding(
padding: const EdgeInsets.only(left: 0),
child: Container(
height: 40,
width: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
),
child: const Padding(
padding: EdgeInsets.only(left: 50),
child: Icon(
Icons.redo,
color: Colors.white,
size: 50,
),
),
),
),
]),
)
]),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.only(top: 20),
child: Text(
"SAVE",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
),
Padding(
padding: const EdgeInsets.only(right: 0),
child: Row(
children: [
Padding(
padding: const EdgeInsets.only(left: 0),
child: Container(
height: 40,
width: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
border:
Border.all(color: Colors.white, width: 3),
),
child: const Icon(
Icons.check,
color: Colors.white,
),
),
),
],
),
),
]),
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const Padding(
padding: EdgeInsets.only(top: 30),
child: Text(
"DO NOT SAVE",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold),
),
),
Padding(
padding: const EdgeInsets.only(
left: 28,
),
child: Row(children: [
Padding(
padding: const EdgeInsets.only(
right: 10,
),
child: Container(
child: const Text(
"Cancel",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
)),
),
]),
)
]),
]),
],
)),
);
As for inner row's children, there will different screen-size devices. While you've used Row you can make it horizontal scrollable by wrapping Row with a scrollable widget like ListView. For theses few buttons, we can use SingleChildScrollView
body: Container(
height: 100,
width: MediaQuery.of(context).size.width,
color: const Color(0xFF722a8c),
child: ListView(
children: [
SingleChildScrollView(
scrollDirection: Axis.horizontal, ///make sure to use horizontal
child: Row(children: [
Column(
Also you can try Wrap, or ListView (+with builder) widgets.
I use standard tabs after a few of my blocks. The content in the tabs is styled using a container. The main parent element is Column in which I build all my blocks. I have tried various options using Expanded.
The error sometimes changes to "RenderFlex children have non-zero flex but incoming height constraints are unbounded." This only happens when i try to add tabs, any other block is displayed correctly in my main Column.
body: SafeArea(
child: SingleChildScrollView(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/background.png"),
fit: BoxFit.fill,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: < Widget > [
SizedBox(height: 20),
Container(
margin: EdgeInsets.symmetric(horizontal: 15),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(32),
),
child: TextField(
decoration: InputDecoration(
hintStyle: TextStyle(fontSize: 14),
hintText: 'Найти услугу...',
suffixIcon: Icon(Icons.search),
border: InputBorder.none,
contentPadding:
EdgeInsets.symmetric(horizontal: 20, vertical: 15),
),
),
),
SizedBox(height: 20),
Container(
height: 450,
padding: EdgeInsets.only(top: 35),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/ps-bg.png"),
fit: BoxFit.cover,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: < Widget > [
SvgPicture.asset(
'assets/ps-logo.svg',
),
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 0.35,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromRGBO(6, 85, 152, 0),
Color(0xFF084A82),
],
)
),
child: CarouselSlider(
options: CarouselOptions(
autoPlay: false,
aspectRatio: 16 / 10,
enlargeCenterPage: true,
viewportFraction: 0.6,
),
items: imgList.map((item) => LayoutBuilder(builder: (context, constraints) {
return ClipRRect(
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
child: Stack(
children: < Widget > [
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: < Widget > [
Image.asset(
'assets/psplus-1month.png',
fit: BoxFit.cover,
width: constraints.maxWidth,
height: constraints.maxHeight / 2,
),
SizedBox(height: 23),
Text(
'Playstation Plus',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF4F4F4F),
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 5),
Text(
'1 месяц',
style: TextStyle(
color: const Color(0xFFA5ABC8),
fontSize: 12,
),
),
SizedBox(height: 5),
Text(
'1 500 рублей',
style: TextStyle(
color: const Color(0xFF789EEB),
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 5),
],
),
),
Positioned(
bottom: constraints.maxHeight / 2 - 18,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: < Widget > [
Container(
decoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
blurRadius: 7,
color: Colors.black.withOpacity(0.10),
spreadRadius: 2)
],
),
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 18,
child: Icon(Icons.add),
),
)
],
),
),
],
),
);
}, ), ).toList()
)
),
]
),
),
SizedBox(height: 20),
DefaultTabController(
length: 3,
child: Column(
children: [
Container(
margin: EdgeInsets.symmetric(horizontal: 15.0),
child: TabBar(
indicator: BoxDecoration(
borderRadius: BorderRadius.circular(50), // Creates border
color: const Color(0xFF62A6E9)
),
labelColor: Colors.white,
unselectedLabelColor: Colors.grey,
labelStyle: TextStyle(fontSize: 13.0),
tabs: [
Tab(text: 'Инструкция'),
Tab(text: 'Оплаты'),
Tab(text: 'Информация'),
],
),
),
TabBarView(
children: [
Container(
margin: EdgeInsets.all(15.0),
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(30))
),
child: Text(
'Text',
textAlign: TextAlign.left,
style: TextStyle(
color: const Color(0xFF4F4F4F),
height: 1.5,
fontSize: 15,
fontFamily: 'Montserrat',
fontWeight: FontWeight.w500,
),
),
),
Container(
margin: EdgeInsets.all(15.0),
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(30))
),
child: Text(
'Text',
textAlign: TextAlign.left,
style: TextStyle(
color: const Color(0xFF4F4F4F),
height: 1.5,
fontSize: 15,
fontFamily: 'Montserrat',
fontWeight: FontWeight.w500,
),
),
),
Container(
margin: EdgeInsets.all(15.0),
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(30))
),
child: Text(
'Text',
textAlign: TextAlign.left,
style: TextStyle(
color: const Color(0xFF4F4F4F),
height: 1.5,
fontSize: 15,
fontFamily: 'Montserrat',
fontWeight: FontWeight.w500,
),
),
),
],
),
]
)
),
GridView.count(
crossAxisCount: 2,
shrinkWrap: true,
physics: ScrollPhysics(),
scrollDirection: Axis.vertical,
children: List.generate(10, (index) {
return Container(
child: Container(
margin: EdgeInsets.all(15.0),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(30.0)),
child: Stack(
children: < Widget > [
Image.network(
'https://images.unsplash.com/photo-1519125323398-675f0ddb6308?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=94a1e718d89ca60a6337a6008341ca50&auto=format&fit=crop&w=1950&q=80',
fit: BoxFit.cover,
width: 1000.0),
Positioned(
bottom: 0.0,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: < Widget > [
Container(
decoration:
BoxDecoration(color: Colors.white),
padding: EdgeInsets.only(
top: 15.0,
bottom: 15.0
),
child: Text(
'PUBG',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF4F4F4F),
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
Positioned(
bottom: 40.0,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment:
CrossAxisAlignment.stretch,
children: < Widget > [
CircleAvatar(
backgroundColor: Colors.white,
radius: 15,
child: Icon(Icons.add),
),
],
),
),
],
)),
),
);
}),
),
]
)
)
))
Ok i found solution, TabBarView need height, Expanded not help.
Container(
height: MediaQuery.of(context).size.height,
child: TabBarView(
children: [
Icon(Icons.directions_car),
Icon(Icons.directions_car),
Icon(Icons.directions_car)
],
),
)
Wrap in LayoutBuilder:
LayoutBuilder(
builder: (_, BoxConstraints viewportConstraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: viewportConstraints.maxHeight,
),
child: Column(),
);
},
),
How can I create this design I found in pinterest
I just wanted to create the user circle half of the container I tried many ways but failed.
Thanks.
To let that half circle get out of the box you need to add some padding on top of the Container to make room for what you desire. Here's a sample code. first define the size of the circle container. here I named it "circleRadius" :
final double circleRadius = 120.0;
Container(
height: double.infinity,
width: double.infinity,
color: Color(0xffE0E0E0),
child: Stack(children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Stack(
alignment: Alignment.topCenter,
children: <Widget>[
Padding(
padding:
EdgeInsets.only(top: circleRadius / 2.0, ), ///here we create space for the circle avatar to get ut of the box
child: Container(
height: 300.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15.0),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 8.0,
offset: Offset(0.0, 5.0),
),
],
),
width: double.infinity,
child: Padding(
padding: const EdgeInsets.only(top: 15.0, bottom: 15.0),
child: Column(
children: <Widget>[
SizedBox(height: circleRadius/2,),
Text('Maria Elliot', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 34.0),),
Text('Albany, NewYork', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16.0, color: Colors.lightBlueAccent),),
SizedBox(
height: 30.0,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Column(
children: <Widget>[
Text('Likes', style: TextStyle( fontSize: 20.0, color: Colors.black54,),),
Text('12K', style: TextStyle( fontSize: 34.0, color: Colors.black87, fontFamily: ''),),
],
),
Column(
children: <Widget>[
Text('Wished', style: TextStyle( fontSize: 20.0, color: Colors.black54),),
Text('12K', style: TextStyle( fontSize: 34.0, color: Colors.black87, fontFamily: ''),),
],
),
Column(
children: <Widget>[
Text('Purchased', style: TextStyle( fontSize: 20.0, color: Colors.black54),),
Text('12K', style: TextStyle( fontSize: 34.0, color: Colors.black87, fontFamily: ''),),
],
),
],
),
)
],
)
),
),
),
///Image Avatar
Container(
width: circleRadius,
height: circleRadius,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 8.0,
offset: Offset(0.0, 5.0),
),
],
),
child: Padding(
padding: EdgeInsets.all(4.0),
child: Center(
child: Container(
child: Icon(Icons.person), /// replace your image with the Icon
),
),
),
),
],
),
),
]),
),
and the output:
You can use a ClipOval with the Image for the Circle
Then to get it in the half of the container use the Stack widget combined with the Positioned Widget
Example:
Stack(
children: <Widget>[
Container(
width: 250,
height: 250,
color: Colors.red,
),
Positioned(
top:50 ,//change this as needed
child:ClipOval(
child: Image.network(
'https://picsum.photos/250?image=9',
),
),
),
],
),
References
Network Image
ClipOval
Great Tutorial
Stack
Positioned
child: Stack(
//alignment: Alignment.center,
children: <Widget>[
Container(
alignment: Alignment.center,
width: MediaQuery.of(mContext).size.width / 1.7,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
gradient: LinearGradient(
colors: gradient,
begin: Alignment.topLeft,
end: Alignment.bottomRight),
),
child: Text(title,
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w500)),
padding: EdgeInsets.only(top: 16, bottom: 16),
),
Visibility(
visible: isEndIconVisible,
child: Padding(
padding: EdgeInsets.only(right: 10),
child: ImageIcon(
AssetImage("assets/ic_forward.png"),
size: 30,
color: Colors.white,
)),
),
],
),
I have a button which should be at the center of the screen. A text which is at the centre of the button and a right arrow. Since I want the button at the center i put alignment centre and so the right arrow coming as centre. Can anyone help me to solve this? I also want to know where we put click for this button.
You can use simple row Widget to achieve you expected ui.
Look at following code which help you may be.
Stack(
alignment: Alignment.center,
children: <Widget>[
Container(
alignment: Alignment.center,
width: MediaQuery.of(context).size.width / 1.7,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
color: Colors.red
,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text("vdsv",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w500)),
Visibility(
visible: true,
child: Padding(
padding: EdgeInsets.only(right: 10),
child: ImageIcon(
AssetImage("assets/images/logo.png"),
size: 30,
color: Colors.white,
)),
),
],
),
padding: EdgeInsets.only(top: 16, bottom: 16),
),
],
)
Add align before Visibility
child: Stack(
//alignment: Alignment.center,
children: <Widget>[
Container(
alignment: Alignment.center,
width: MediaQuery.of(mContext).size.width / 1.7,
decoration: ShapeDecoration(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0)),
gradient: LinearGradient(
colors: gradient,
begin: Alignment.topLeft,
end: Alignment.bottomRight),
),
child: Text(title,
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.w500)),
padding: EdgeInsets.only(top: 16, bottom: 16),
),
Align(alignment: Alignment.topRight,
child: Visibility(
visible: isEndIconVisible,
child: Padding(
padding: EdgeInsets.only(right: 10),
child: ImageIcon(
AssetImage("assets/ic_forward.png"),
size: 30,
color: Colors.white,
)),
),)
],
),