Getting rid of small line in-between 2 containers - Flutter/Dart - flutter

There's a small but very noticeable line in between 2 containers whenever I try developing a unique design for the UI. Here's the screenshot:
The goal would be to get rid of this small line while achieving the same UI design. Any help is appreciated!
And here's the code:
Widget build(BuildContext context) {
var safePadding = MediaQuery.of(context).padding.top;
return WillPopScope(
onWillPop: () async => false,
child: Container(
color: Colors.white,
child: SafeArea(
child: Scaffold(
appBar: AppBar(
toolbarHeight: 56,
elevation: 0,
automaticallyImplyLeading: false,
backgroundColor: Colors.white,
actions: [
SizedBox(
width: MediaQuery.of(context).size.width * 1,
child: Row(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
child: SizedBox(
width: 40,
height: 40,
child: Material(
shape: const CircleBorder(),
color: Colors.white,
child: InkWell(
customBorder: const CircleBorder(),
splashColor: Colors.grey.withOpacity(0.5),
child: const Icon(Icons.keyboard_arrow_left,
color: Color.fromARGB(255, 25, 61, 94)),
onTap: () {
Future.delayed(
const Duration(milliseconds: 50),
() {
Navigator.of(context).pop();
},
);
},
),
),
),
),
const Text(
'App Bar',
style: TextStyle(
color: Color.fromARGB(255, 25, 61, 94),
fontSize: 20,
fontWeight: FontWeight.w500),
),
],
),
),
],
),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height:
(MediaQuery.of(context).size.height - 56 - safePadding) *
0.4,
color: const Color.fromARGB(255, 25, 61, 94),
child: Container(
padding: const EdgeInsets.only(bottom: 15),
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(75),
topRight: Radius.circular(0),
),
color: Colors.white,
),
),
),
Container(
color: Colors.white,
height:
(MediaQuery.of(context).size.height - 56 - safePadding) *
0.6,
child: Container(
padding: const EdgeInsets.only(right: 30, left: 30),
decoration: const BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(75),
),
color: Color.fromARGB(255, 25, 61, 94)),
),
),
],
),
),
),
),
);
}

I've managed to achieve what I've wanted so I'll answer my question here. For some reason flutter always leaves a small space in between Containers and if this small space ruins your UI design, you'll need to change the color of the containers' borders. For my scenario, it was a bit more complex since there were multiple containers stacked on top of each other and the solution can be different depending on the code/scenario.
Here's the new code with the issue fixed:
Widget build(BuildContext context) {
var safePadding = MediaQuery.of(context).padding.top;
return WillPopScope(
onWillPop: () async => false,
child: Container(
color: Colors.white,
child: SafeArea(
child: Scaffold(
appBar: AppBar(
toolbarHeight: 56,
elevation: 0,
automaticallyImplyLeading: false,
backgroundColor: Colors.white,
actions: [
SizedBox(
width: MediaQuery.of(context).size.width,
child: Row(
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
child: SizedBox(
width: 40,
height: 40,
child: Material(
shape: const CircleBorder(),
color: Colors.white,
child: InkWell(
customBorder: const CircleBorder(),
splashColor: Colors.grey.withOpacity(0.5),
child: const Icon(Icons.keyboard_arrow_left,
color: Color.fromARGB(255, 25, 61, 94)),
onTap: () {
Future.delayed(
const Duration(milliseconds: 50),
() {
Navigator.of(context).pop();
},
);
},
),
),
),
),
const Text(
'App Bar',
style: TextStyle(
color: Color.fromARGB(255, 25, 61, 94),
fontSize: 20,
fontWeight: FontWeight.w500),
),
],
),
),
],
),
body: Column(
children: [
Container(
decoration: BoxDecoration(
color: Colors.blue,
border: Border(
bottom: BorderSide(color: Colors.blue, width: 0)),
),
child: Container(
width: MediaQuery.of(context).size.width * 1,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(75),
),
),
height: (MediaQuery.of(context).size.height -
56 -
safePadding) *
0.4,
),
),
Stack(
children: [
Row(
children: [
Container(
width: MediaQuery.of(context).size.width * 0.5,
decoration: BoxDecoration(
color: Colors.blue,
),
height: (MediaQuery.of(context).size.height -
56 -
safePadding) *
0.6,
),
Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border(
top: BorderSide(
color: Colors.white, width: 0)),
),
child: Container(
width: MediaQuery.of(context).size.width * 0.5,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.only(
topRight: Radius.circular(75),
),
),
height: (MediaQuery.of(context).size.height -
56 -
safePadding) *
0.6,
),
),
],
),
Positioned(
child: Center(
child: Container(
padding: EdgeInsets.only(top: 30),
width: MediaQuery.of(context).size.width,
height: (MediaQuery.of(context).size.height -
56 -
safePadding) *
0.6,
child: Text('This is a test',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
)),
),
)),
],
),
],
),
),
),
),
);
}
Result:

Related

Make Container take content size of child

I'm new in Flutter,
I have a Container which child is Stack that using Positioned inside.
My problem is Container just taking Non-Positioned widget size.
Here is my problem:
I want something like this:
Here is my Widget code:
class CheckUpItem extends StatelessWidget {
const CheckUpItem({
Key? key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return SizedBox(
width: 100,
child: Container(
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
color: Colors.white,
border: Border.fromBorderSide(
BorderSide(
width: 1,
color: Color(0xFFBAD9F8),
),
),
boxShadow: [
BoxShadow(
color: Color(0x00000029),
offset: Offset(2, 3),
blurRadius: 2,
),
],
),
child: Column(
children: [
ClipRRect(
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(4),
topRight: Radius.circular(4),
),
child: Container(
decoration: const BoxDecoration(
color: Color(0xFFE6F6FF),
border: Border(
bottom: BorderSide(
width: 1,
color: Color(0xFFBAD9F8),
),
),
),
child: Consumer(
builder: (context, ref, child) {
return Center(
child: Text(
'BMI',
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
height: 1.43,
color: Color(0xFF6B6B6B),
),
),
);
},
),
),
),
Container(
padding: const EdgeInsets.only(top: 5.5, bottom: 4),
child: Column(
children: [
Stack(
clipBehavior: Clip.none,
children: [
Container(
width: 36,
height: 36,
decoration: const BoxDecoration(
shape: BoxShape.circle,
border: Border.fromBorderSide(
BorderSide(
width: 2,
color: Color(0xFFBF3D3D),
),
),
color: Color(0xFFF86060),
),
child: const Center(
child: Text(
'B',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
height: 1,
fontSize: 20,
),
),
),
),
Positioned(
bottom: -6,
left: 26,
child: Container(
width: 22,
height: 22,
padding: const EdgeInsets.fromLTRB(1, 0, 3, 2),
decoration: const BoxDecoration(
border: Border.fromBorderSide(
BorderSide(
width: 1,
color: Color(0xFF6A8FD4),
),
),
color: Color(0xFFE0EEFC),
shape: BoxShape.circle,
),
child: SvgPicture.asset(ImageAssets.speaker),
),
),
],
),
const SizedBox(height: 6),
],
),
),
],
),
),
);
}
}
I'm stucking all day with this, I'm tempary using Column and const SizedBox(height: 6) for fake height.
How to make it right way?
P/s: Sorry, my English is not good!
Because every thing is static hear and you know how much the svg container going down, you can calculate it and add it to padding bottom, like this:
Container(
padding: const EdgeInsets.only(top: 5.5, bottom: 10), // 4 + 6(Positioned bottom)
child: Stack(
clipBehavior: Clip.none,
children: [
Container(
width: 36,
height: 36,
decoration: const BoxDecoration(
shape: BoxShape.circle,
border: Border.fromBorderSide(
BorderSide(
width: 2,
color: Color(0xFFBF3D3D),
),
),
color: Color(0xFFF86060),
),
child: const Center(
child: Text(
'B',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
height: 1,
fontSize: 20,
),
),
),
),
Positioned(
bottom: -6,
left: 26,
child: Container(
height: 22,
width: 22,
decoration: const BoxDecoration(
border: Border.fromBorderSide(
BorderSide(
width: 1,
color: Color(0xFF6A8FD4),
),
),
color: Color(0xFFE0EEFC),
shape: BoxShape.circle,
),
child: SvgPicture.asset(
'assets/images/tes.svg',
),
),
),
],
),
),

Positioned Widget is not scrolling even with all positional arguments

I would like to make some information of a Profile Page scrollable. For the layout I used a stack as a parent widget and filled it with Positioned Widgets. I filled the Positioned Widget with all positional arguments, which allowed me to scroll it when I placed it in the middle of the screen. It seems like the further down I push the widget, the smaller the area to scroll gets. Until the area kind of disappears.
The last Positioned Widget is the one I want to make scrollable. I also used it with fix numbers, which didn't help.
I am new to programming, so I hopefully could make my problem clear. Thanks in advance for helping me out.
Here is my code:
return Scaffold(
appBar: AppBar(
elevation: 2,
leading: BackButton(onPressed: () {
Navigator.pop(context,
MaterialPageRoute(builder: (context) => eventHomeScreen()));
}),
backgroundColor: Colors.teal,
title: Text('Leute', style: TextStyle(fontSize: 28)),
actions: [
IconButton(
iconSize: 26,
icon: Icon(Icons.chat),
tooltip: 'Chat-Anfrage schicken',
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => chatRequestSentScreen.withUser(user)));
},
)
],
),
body: Stack(
alignment: Alignment.bottomCenter,
clipBehavior: Clip.none,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width * 1,
height: MediaQuery.of(context).size.height * .35,
decoration: BoxDecoration(
image: DecorationImage(
image: user.getProfilePicture(),
fit: BoxFit.cover,
),
),
),
Positioned(
bottom: -MediaQuery.of(context).size.height * 0.19,
child: Card(
color: Colors.teal.shade50,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40),
topRight: Radius.circular(40),
)),
elevation: 0,
child: Container(
width: MediaQuery.of(context).size.width * 1,
height: MediaQuery.of(context).size.height * 0.26,
child: Column(
children: [
Text(
user.getFullName(),
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 24,
),
),
Text(user.getCurrentAge().toString() + " Jahre",
style: TextStyle(
fontSize: 22,
)),
Text('Zuletzt aktiv: Heute',
style: TextStyle(
color: Colors.grey,
fontSize: 16,
)),
SizedBox(
height: 10,
),
Container(
margin: EdgeInsets.symmetric(horizontal: 20),
padding:
EdgeInsets.symmetric(horizontal: 30, vertical: 5),
child: Text(user.getBio(),
maxLines: 3,
overflow: TextOverflow.ellipsis,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
)),
),
SizedBox(
height: 50,
),
],
),
),
),
),
Positioned(
top: MediaQuery.of(context).size.height * 0.45,
left: 0.0,
right: 0.0,
bottom: -MediaQuery.of(context).size.height * 0.55,
child: Container(
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40),
topRight: Radius.circular(40),
)),
width: MediaQuery.of(context).size.width * 1,
height: MediaQuery.of(context).size.height * 0.4,
child:
Container(
margin: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
padding:
EdgeInsets.symmetric(horizontal: 30, vertical: 5),
child: SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: Column(
children: SharedScreenFeatures.getSports(
user.getSports()),
),
),
),
),
),
],
),
);
}
}```
You will be fine if you just wrap your container inside a SingleChildScrollView
The child widget inherits constraints from the parent. I added a parent container with height: double.infinity. Also the segment_two container I set a minimum height of 150 otherwise you will give pixel overflow. Be careful with your ratios on sizing.
class TestPositioned extends StatefulWidget {
TestPositioned({Key? key}) : super(key: key);
#override
State<TestPositioned> createState() => _TestPositionedState();
}
class _TestPositionedState extends State<TestPositioned> {
segment_one(BuildContext context)
{
return Container(
width: MediaQuery.of(context).size.width * 1,
height: MediaQuery.of(context).size.height * .35,
decoration: BoxDecoration(
border:Border.all(color:Colors.grey)),
child:FittedBox(
fit:BoxFit.fitHeight,
child:SizedBox(
width:200,
height:200,
child: Image.asset("assets/images/apple.jpg"),
),
),
);
}
segment_two(BuildContext context)
{
return
Positioned(
bottom: -MediaQuery.of(context).size.height * 0.01,
child:
Container(
width: MediaQuery.of(context).size.width * 1,
height: MediaQuery.of(context).size.height * 0.26>150?MediaQuery.of(context).size.height * 0.26:150,
child:Card(
color: Colors.teal.shade50,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40),
topRight: Radius.circular(40),
)),
elevation: 0,
child: Column(
children: [
Expanded(child:Text("full Name", style: TextStyle( fontWeight: FontWeight.bold, fontSize: 24, ),)),
Expanded(child:Text("current age" + " name",style: TextStyle(fontSize: 22,))),
Expanded(child:Text('abcdefg: hijklmn',style: TextStyle(color: Colors.grey,fontSize: 16,))),
SizedBox(height: 10,),
Container(margin: EdgeInsets.symmetric(horizontal: 10),
padding:EdgeInsets.symmetric(horizontal: 10, vertical: 5),
child:
Expanded(child:Text("bio",maxLines: 3,overflow: TextOverflow.ellipsis,textAlign: TextAlign.center,
style: TextStyle( fontSize: 20,)))
)
,
SizedBox(height: 10,),
],
),
)));
}
#override
Widget build(BuildContext context) {
return Scaffold(appBar: AppBar(title: Text("Stacked Position")),body:
Container(
height: double.infinity,child:Stack(
children: [
segment_one(context),
segment_two(context),
],)));
}
}
I solved it, which took me quite a while but now it is working perfectly for my purposes. I am still using the stack but to push the content down to where it is needed, I used a transparent container. Now the MediaQuery isn't negative anymore. Might not be the perfect answer, but it works.
return Scaffold(
backgroundColor: Colors.teal.shade50,
appBar: AppBar(
elevation: 2,
leading: BackButton(onPressed: () {
Navigator.pop(context,
MaterialPageRoute(builder: (context) => eventHomeScreen()));
}),
backgroundColor: Colors.teal,
title: Text('Leute', style: TextStyle(fontSize: 28)),
actions: [
IconButton(
iconSize: 26,
icon: Icon(Icons.chat),
tooltip: 'Chat-Anfrage schicken',
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (context) => chatRequestSentScreen.withUser(user)));
},
)
],
),
body: Stack(
children: [
Column(children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * .33,
decoration: BoxDecoration(
image: DecorationImage(
image: user.getProfilePicture(),
fit: BoxFit.cover,
),
),
),
]),
Positioned(
top: MediaQuery.of(context).size.height * .27,
child: Container(
decoration: BoxDecoration(
color: Colors.teal.shade50,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40),
topRight: Radius.circular(40),
)),
width: MediaQuery.of(context).size.width * 1,
child: Column(
children: [
Text(
user.getFullName(),
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 24,
),
),
Text(user.getCurrentAge().toString() + " Jahre",
style: TextStyle(
fontSize: 22,
)),
Text('Zuletzt aktiv: Heute',
style: TextStyle(
color: Colors.grey,
fontSize: 16,
)),
],
),
),
),
SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: Column(
children: [
Container(
height: MediaQuery.of(context).size.height * .39,
color: Colors.transparent,
),
Container(
height: MediaQuery.of(context).size.height * .15,
width: MediaQuery.of(context).size.width * 1,
color: Colors.teal.shade50,
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 0),
child: SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: Text(
user.getBio(),
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 20,
),
),
),
),
Container(
height: MediaQuery.of(context).size.height * .4,
width: MediaQuery.of(context).size.width *1 ,
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40),
topRight: Radius.circular(40),
)),
child: Container(
margin: EdgeInsets.symmetric(horizontal: 20, vertical: 0),
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 20),
child: SingleChildScrollView(
physics: AlwaysScrollableScrollPhysics(),
child: Column(
children:
SharedScreenFeatures.getSports(user.getSports()),
),
),
),
),
],
),
),
],
),
);

I want to design grid like this in flutter:

I want to design a Grid like the below output in flutter.
Please help with this.
The Code I have tried is this:
Container(
height: 100,
width: 170,
margin: const EdgeInsets.symmetric(horizontal: 30),
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white,
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.black
),
margin: const EdgeInsets.all(1.5),
child: const Center(
child: Text(
"data",
style: TextStyle(color: Colors.white),
),
),
),
),
),
And the output I get is this:
Thanks in advance for your help.
What you can do to maintain a grid is use Wrap.
Not very efficient for long list of items but for short it will suffice.
Take a look at the code below :
( You can run this code using Dartpad )
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark(),
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(),
body: Padding(
padding: const EdgeInsets.all(16),
child: LayoutBuilder(builder: (c, box) {
var crossCount = 2;
var spacing = 15.0;
var maxWidth = (box.maxWidth - ((crossCount - 1) * spacing)) / 2;
return Wrap(
spacing: spacing,
runSpacing: spacing,
children: List.generate(
10,
(i) => Stack(
children: [
Container(
width: maxWidth,
height: maxWidth * 0.55 * 0.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(topLeft: Radius.circular(16)),
gradient : LinearGradient(
end: Alignment.topLeft,
begin: Alignment.bottomRight,
colors: [
Colors.black,
Colors.black,
Colors.amber,
],
),
// color: Colors.white,
// boxShadow: [BoxShadow(color: Colors.black, blurRadius: 4)],
),
),
Container(
width: maxWidth,
height: maxWidth * 0.55,
margin: const EdgeInsets.all(2),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16),
color: Colors.black,
),
)
],
),
),
);
}),
),
),
);
}
}
Note : Replace the Container's child with your own UI logic for implementing the design you like.
I tried it by myself and manage to built the same.
This is the Code:
Padding(
padding: const EdgeInsets.all(10),
child: GridTile(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
"Gate 2",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
color: Colors.white),
),
const Text(
"Unlocked",
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w500,
color: Colors.grey),
),
const SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Icon(
Icons.lock,
color: Colors.white,
size: 30,
),
const SizedBox(width: 5),
Image.asset("assets/swipe.png",height: 30,width: 30,),
const SizedBox(width: 5),
// const Icon(Icons.lock, color: Colors.white,size: 30,),
Draggable(
axis: Axis.horizontal,
maxSimultaneousDrags: 3,
rootOverlay: false,
child: Container(
padding: const EdgeInsets.all(5),
decoration: const BoxDecoration(
color: Colors.white12,
borderRadius: BorderRadius.all(Radius.circular(100),),
),
child: const Icon(
Icons.lock_open,
color: Colors.orangeAccent,
size: 30,
),
),
feedback: Container(
decoration: const BoxDecoration(
color: Colors.white12,
borderRadius: BorderRadius.all(Radius.circular(100),),
),
child: const Icon(
Icons.lock_open,
color: Colors.transparent,
size: 40,
),
),
),
],
),
],
),
),
),
Here is the Output.

How to create a DraggableScrollableSheet with showModelBottomSheet?

I created with showModelBottomSheet with DraggableScrollableSheet(), But the problem is the there is no appBar for show some text while dragging, ie, the SingleChildsSrollView() will move up and down while dragging.
*bottomsheet(context) {
Size size = MediaQuery.of(context).size;
return showModalBottomSheet(
backgroundColor: Colors.white,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(top: Radius.circular(13)),
),
context: context,
builder: (BuildContext context) {
return Padding(
padding: const EdgeInsets.all(5),
child: Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
foregroundColor: Colors.green,
backgroundColor: Colors.white,
elevation: 1,
shadowColor: Colors.grey.shade100,
automaticallyImplyLeading: false,
title: const Text('Connect with Reconnect'),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(
25,
),
child: Container(
padding: const EdgeInsets.only(
left: 15,
right: 15,
top: 15,
),
height: size.height,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(13),
boxShadow: const [
BoxShadow(blurRadius: 2, color: Colors.grey),
],
),
child: Column(children: [
TextField(
cursorColor: Colors.green,
decoration: InputDecoration(
label: const Text('Name'),
labelStyle: TextStyle(color: Colors.grey.shade500),
icon: const Icon(
FontAwesomeIcons.user,
color: Color(0xff453e3d),
size: 22,
),
border: InputBorder.none,
),
),
Container(
width: 315,
height: 1,
margin: const EdgeInsets.only(top: 3, bottom: 3),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
TextField(
cursorColor: Colors.green,
decoration: InputDecoration(
label: const Text('Email'),
labelStyle: TextStyle(color: Colors.grey.shade500),
icon: const Icon(
FontAwesomeIcons.envelope,
color: Color(0xff453e3d),
size: 22,
),
border: InputBorder.none,
),
),
Container(
width: 315,
height: 1,
margin: const EdgeInsets.only(top: 3, bottom: 3),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
TextField(
cursorColor: Colors.green,
decoration: InputDecoration(
label: const Text('Phone Number'),
labelStyle: TextStyle(color: Colors.grey.shade500),
icon: const Icon(
FontAwesomeIcons.mobileAlt,
color: Color(0xff453e3d),
size: 22,
),
border: InputBorder.none,
),
),
Container(
width: 315,
height: 1,
margin: const EdgeInsets.only(top: 3, bottom: 3),
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.circular(100),
),
),
Container(
margin: const EdgeInsets.only(top: 10),
height: 25,
alignment: Alignment.bottomLeft,
child: Row(
children: [
const Icon(
FontAwesomeIcons.car,
color: Color(0xff453e3d),
),
const SizedBox(
width: 15,
),
Text(
'Services',
style: TextStyle(
color: Colors.grey.shade500, fontSize: 16),
),
],
),
),
]),
),
),
),
),
);
});
}*
I need a bar on top of the singlechildscrollview, I tried with column instead, but no result.
The Problem will solve by the following code!
body: Center(
child: Column(
children: [
const SizedBox(
height: 400,
),
ElevatedButton(
onPressed: () =>
//The showModelBottomSheet Will push a sheet to our page for show widgets and actions
showModalBottomSheet(
context: context,
isScrollControlled: true,
backgroundColor: Colors.transparent,
builder: (context) =>
//The DraggableScrollableSeet will drag top to bottom or vise versa with respect to user interaction.
DraggableScrollableSheet(
initialChildSize: .6,
maxChildSize: .9,
minChildSize: .2,
builder: (context, controller) =>
//The customsheet method will return a widget with a child CustoomScrollView to Drag our DraggableScrollableSheet.
customSheet(context, controller),
),
),
child: const Text('clickme'),
),
],
),
),
//customSheet body
Widget customSheet(BuildContext context, ScrollController controller) {
return Container(
alignment: Alignment.bottomLeft,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
),
),
// While use the CustomScrollView have an SliverAppBar for set our bar to constant, ie, the appBar will not move while dragging
child: CustomScrollView(
controller: controller,
slivers: [
SliverAppBar(
shadowColor: Colors.grey.shade100,
elevation: 1,
pinned: true,
backgroundColor: Colors.white,
automaticallyImplyLeading: false,
title: Container(
margin: const EdgeInsets.only(bottom: 45),
width: 60,
height: 4,
color: Colors.grey.shade300),
shape: RoundedRectangleBorder(
side: BorderSide(color: Colors.grey.shade200),
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(30),
topRight: Radius.circular(30),
),
),
),
SliverFillRemaining(
hasScrollBody: false,
child: Column(
children: [
for (int i = 0; i < 10; i++)
Container(
width: 100,
height: 100,
color: Colors.green[i * 100],
),
],
),
)
],
),
);
}
Problem: The above code has a problem with an exit from the DraggableScrollableSheet(),
this is because if we use a GestureDetecter instead of DraggableScrollableSheet(), the child will pop by the following code
GestureDetector(onTap: ()=>Navigator.of(context).pop(),behavior: HitTestBehavior.opaque,
child: DraggableScrollableSheet(
initialChildSize: .6,
maxChildSize: .9,
minChildSize: .2,
builder: (context, controller) =>
customSheet(context, controller),
),
),
But we cannot pop the sheet with tapped by outside of the DraggableScrollabelSheet().
Note: the HitTestBehaviour.opaque will pop the sheet but if we tap anywhere in the Scaffold.
Thank You for following me up and If you have the solution, Please ping me #sureshm2suresh#gmail.com

Adjust size Container?

I'm new to flutter, I'm trying to change size of a container, but it not change even i change height:150 and width=150, I just want green screen show about 1/5 screen, but i really don't know how to fix this. I don't understand why, when changing the height and width of the Container, nothing will change
here is code
return Container(
decoration: new BoxDecoration(color: Colors.white),
child: new MaterialApp(
title: "Sample",
debugShowCheckedModeBanner: false,
home: Container(
height: 150.0,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30),
)),
child: Stack(
children: [
Positioned(
top: 150,
left: 0,
child: Row(
children: <Widget>[
SvgPicture.asset(
user,
width: 60,
height: 60,
),
SizedBox(
width: 10,
),
Text(
"Welcome back, $username",
style: TextStyle(
fontSize: 20,
fontFamily: fontRegular,
decoration: TextDecoration.none,
color: Colors.white,
),
),
SizedBox(
width: 10,
),
Container(
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
border: Border.all(width: 1.5, color: Colors.black),
color: Color.fromRGBO(230, 230, 230, 1),
borderRadius: BorderRadius.circular(30),
),
child: Row(
children: [
SvgPicture.asset(
"assert\\dollar.svg",
height: 25,
width: 25,
),
Text(
'$coinValue',
style: TextStyle(
fontSize: 18,
color: Colors.black,
decoration: TextDecoration.none),
),
],
),
),
SizedBox(
width: 13,
),
],
),
),
],
),
),
),
);
}
Here is result
i just want something like this
hope this helps you:
Add Scaffold around the inner container (the one with height 150 )... and you don't need the stack and positioned(the content won't show up if you don't remove them):
MaterialApp(
title: "Sample",
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Container(
height: 150.0,
decoration: ...
Rewrite your code as below:
home: Scaffold(
body: SafeArea(
child: Container(
height: 150.0,
decoration: BoxDecoration(
color: Colors.green,
),
child: Row(
children: <Widget>[
SizedBox(
width: 10,
),
Text(
"Welcome back",
style: TextStyle(
fontSize: 20,
//fontFamily: fontRegular,
decoration: TextDecoration.none,
color: Colors.white,
),
),
SizedBox(
width: 10,
),
Container(
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
border: Border.all(width: 1.5, color: Colors.black),
color: Color.fromRGBO(230, 230, 230, 1),
borderRadius: BorderRadius.circular(30),
),
child: Row(
children: [
Text(
'dsfsfsf',
style: TextStyle(
fontSize: 18,
color: Colors.black,
decoration: TextDecoration.none),
),
],
),
),
SizedBox(
width: 13,
),
],
),
),
),
),
You have the Stack widget inside your Container widget. That is why it is taking the whole screen. Try removing the Stack widget.
return Container(
decoration: new BoxDecoration(color: Colors.white),
child: new MaterialApp(
title: "Sample",
debugShowCheckedModeBanner: false,
home: Container(
height: 150.0,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30),
)),
child: Positioned(
top: 150,
left: 0,
child: Row(
children: <Widget>[
SvgPicture.asset(
user,
width: 60,
height: 60,
),
SizedBox(
width: 10,
),
Text(
"Welcome back, $username",
style: TextStyle(
fontSize: 20,
fontFamily: fontRegular,
decoration: TextDecoration.none,
color: Colors.white,
),
),
SizedBox(
width: 10,
),
Container(
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
border: Border.all(width: 1.5, color: Colors.black),
color: Color.fromRGBO(230, 230, 230, 1),
borderRadius: BorderRadius.circular(30),
),
child: Row(
children: [
SvgPicture.asset(
"assert\\dollar.svg",
height: 25,
width: 25,
),
Text(
'$coinValue',
style: TextStyle(
fontSize: 18,
color: Colors.black,
decoration: TextDecoration.none),
),
],
),
),
SizedBox(
width: 13,
),
),
],
),
),
),
);
Do as follows
Container(
height: 150,
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(20),
bottomLeft: Radius.circular(20))),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
CircleAvatar(
radius: 30.0,
backgroundImage: NetworkImage('https://via.placeholder.com/150'),
backgroundColor: Colors.transparent,
),
Expanded(child:Text("Hey there, Welcome back LQK!")),
Container(
width:100,
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
border: Border.all(width: 1.5, color: Colors.black),
color: Color.fromRGBO(230, 230, 230, 1),
borderRadius: BorderRadius.circular(30),
),
child: Row(
children: [
Icon(Icons.search) //put your desired icon here
],
),
),
],
)