how can I achieve something like this with flutter sliver app bar? - flutter

I want to achieve the design provided below.
The design is scrollable with a tab bar. The scroll functionality has been achieved but the card between tab bar and sliver app bar is something I could not achieve.
The code I have tried
CustomScrollView(
slivers: <Widget>[
SliverAppBar(
pinned: true,
backgroundColor: Colors.deepPurple,
leading: IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: const Icon(Icons.arrow_back_ios_new_sharp)),
actions: [
Container(
height: 46,
width: 46,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(width: .5, color: Colors.white),
color: Colors.transparent,
),
child: const Icon(
Icons.share_outlined,
color: Colors.white,
),
alignment: Alignment.center,
),
const SizedBox(
width: 10,
),
Container(
height: 46,
width: 46,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(width: .5, color: Colors.white),
color: Colors.transparent,
),
child: const Icon(
Icons.favorite_border,
color: Colors.white,
),
alignment: Alignment.center,
),
const SizedBox(
width: 5,
)
],
expandedHeight: MediaQuery.of(context).size.height * .35,
flexibleSpace: FlexibleSpaceBar(
title: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text('Good food'),
RatingBar.builder(
unratedColor: Colors.black,
initialRating: 5,
ignoreGestures: true,
itemSize: 18,
direction: Axis.horizontal,
allowHalfRating: true,
itemCount: 5,
itemPadding: EdgeInsets.symmetric(horizontal: 4.0),
itemBuilder: (context, _) => Icon(
Icons.star,
color: Colors.amber,
),
onRatingUpdate: (_) {},
)
],
),
centerTitle: true,
background: Image(
image: AssetImage(
'assets/images/food.jpg',
),
fit: BoxFit.cover,
),
),
),
SliverToBoxAdapter(
child: Center(
child: SizedBox(
height: 100,
width: MediaQuery.of(context).size.width * .9,
child: Card(
elevation: 5,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
child: Image(image: AssetImage('assets/images/book1.png')),
),
)),
),
],
),

Related

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

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:

Flutter how to create circular border around icon and align an image top of the circular border

I am trying to use the below code to create a circular border around an image and align an icon on top of the circular border. What I am looking at is as the image below:
And my code is as below but it didn't work out perfectly:
Stack(
children: [
CircleAvatar(
radius: 60,
backgroundColor: Colors.white,
child: Container(
padding: EdgeInsets.all(2),
child: CircleAvatar(
radius: 70,
backgroundImage: AssetImage('assets/person_icon.png'),
backgroundColor: Colors.white,
//
)),
),
Positioned(
bottom: 100,
right: 50,
child: InkWell(
onTap: () {},
child: Container(
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Icon(Icons.add_a_photo, color: colorBlue),
),
decoration: BoxDecoration(
border: Border.all(
width: 3,
color: Colors.white,
),
borderRadius: BorderRadius.all(
Radius.circular(
50,
),
),
color: Colors.white,
boxShadow: [
BoxShadow(
offset: Offset(2, 4),
color: Colors.black.withOpacity(
0.3,
),
blurRadius: 3,
),
]),
),
)),
],
),
As you can above I am trying to use stack to lay each widget on top of each other but couldn't achieve that. I don't if anyone can help out where I missed it or give me a good idea of how to come about this.
Thanks in advance.
Default clipBehavior on Stack is hardEdge.
Use clipBehavior: Clip.none on Stack.
And to have circle shape
use customBorder: CircleBorder(), on InkWell.
use shape: BoxShape.circle instead of circular radius on container.
For better alignment use
Positioned(
top: -12,//half of icon size
left: 0,
right: 0,
Also better providing size on Stack like here.
/// fixing top widget size
SizedBox.square(
dimension: squareSize,
child: Stack(
clipBehavior: Clip.none,
children: [
Positioned.fill(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
clipBehavior: Clip.hardEdge,
decoration: const ShapeDecoration(
shape: CircleBorder(),
),
child: Image.asset(
'assets/images/image01.png',
fit: BoxFit.cover,
),
),
),
),
///background circle, you also do it on image widget
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(width: 5, color: Colors.green),
),
),
Positioned(
top: -12, // half of icon size
left: 0,
right: 0,
child: InkWell(
onTap: () {},
customBorder: const CircleBorder(),
child: Container(
width: 24 + 12, //icon size+padding
height: 24 + 12,
alignment: Alignment.center,
decoration: const ShapeDecoration(
shape: CircleBorder(),
color: Colors.green,
),
child: Icon(
Icons.add_a_photo,
color: Colors.white,
),
),
),
),
],
),
)
Play with sizes and decoration
Just add to the Stack Widget the Property clipBehavior: Clip.none,.
The clipBehavior will befine how to handle the Clip of the Stack Widget. Standard is hardEdge and cuts your icon off.
So your finished working Code is
import 'package:flutter/material.dart';
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Stack(
clipBehavior: Clip.none,
children: [
CircleAvatar(
radius: 60,
backgroundColor: Colors.white,
child: Container(
padding: EdgeInsets.all(2),
child: CircleAvatar(
radius: 70,
backgroundImage: AssetImage('assets/person_icon.png'),
backgroundColor: Colors.white,
//
),
),
),
Positioned(
bottom: 100,
right: 50,
child: InkWell(
onTap: () {},
child: Container(
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Icon(Icons.add_a_photo, color: Colors.blue),
),
decoration: BoxDecoration(
border: Border.all(
width: 3,
color: Colors.white,
),
borderRadius: BorderRadius.all(
Radius.circular(
50,
),
),
color: Colors.white,
boxShadow: [
BoxShadow(
offset: Offset(2, 4),
color: Colors.black.withOpacity(
0.3,
),
blurRadius: 3,
),
],
),
),
),
),
],
),
),
);
}
}
void main() {
runApp(
const MaterialApp(
home: MyApp(),
),
);
}
Try below code
Stack(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 25),
child: Container(
padding: EdgeInsets.all(8),
height: 270,
width: 270,
decoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
child: Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
child: ClipOval(
child: Container(
height: 250,
width: 250,
child: Image.network(
'https://miro.medium.com/max/1400/1*-6WdIcd88w3pfphHOYln3Q.png',
fit: BoxFit.cover,
),
),
),
),
),
),
Positioned(
top: 0,
left: .0,
right: .0,
child: Center(
child: CircleAvatar(
backgroundColor: Colors.green,
radius: 30.0,
child: Icon(
Icons.check,
color: Colors.white,
size: 40,
),
),
),
)
],
),
Result Screen->
user this below code to achieve
Center(
child: Stack(
children: [
Container(
height: 200,
child: CircleAvatar(
radius: 75,
backgroundColor: Colors.green,
child: CircleAvatar(
radius: 70,
backgroundColor: Colors.white,
child: Container(
padding: EdgeInsets.all(2),
child: const CircleAvatar(
radius: 60,
backgroundImage: NetworkImage("https://helostatus.com/wp-content/uploads/2021/09/pic-for-WhatsApp-HD.jpg"),
backgroundColor: Colors.white,
//
)),
),
),
),
Positioned(
left: 16,
right: 16,
top: 8,
child: InkWell(
onTap: () {},
child: const CircleAvatar(
backgroundColor: Colors.green,
radius: 16,
child: Icon(
Icons.check,
color: Colors.white,
),
)),
),
],
),
)[enter image description here][1]
Thanks all for the contribution but here is what works perfectly for what I'm looking at. I added clipBehavior and set Clip to noneclipBehavior: Clip.none, added ClipOval in a Container and set it margin and padding respectively to give the space between the green circular border and the profile image. I also, added another Container inside my ClipOval so as to add my image as a child to it. Find below my final code:
Center(
child: Stack(
clipBehavior: Clip.none,
children: [
CircleAvatar(
radius: 60,
backgroundColor: colorGreen,
child:Container(
padding: EdgeInsets.all(4),
margin: EdgeInsets.all(3),
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
),
child: ClipOval(
child: Container(
height: 250,
width: 250,
child: Image.network(
'my image link',
fit: BoxFit.cover,
),
),
)
)),
Positioned(
bottom: 100,
right: 45,
child: InkWell(
onTap: () {},
child: Center(
child: CircleAvatar(
backgroundColor: colorGreen,
radius: 15.0,
child: Icon(
Icons.check,
color: Colors.white,
size: 25,
),
),
),
),
),
],
),
),

How to set logged in username inside a top navigationBar?

How can I get the username from Firebase in this code?
I have followed a guide on youtube for the design.
I have a top navigation bar that has a CustomText with the username.
But in this there is no class (stless/stfull). So how can I get my username and put in in my CustomText?
When I have a normal Statefull class I manage to do it, but when there is noe class I don't know how.
Here is the code:
AppBar(
leading: !ResponsiveWidget.isSmallScreen(context) ? Row(
children: [
Padding(
padding: const EdgeInsets.only(left: 16),
child: Image.asset("assets/icons/logo.png", width: 28,),
),
],
) : IconButton(icon: Icon(Icons.menu), onPressed: (){
key.currentState.openDrawer();
}),
title: Container(
child: Row(
children: [
Visibility(
visible: !ResponsiveWidget.isSmallScreen(context),
child: CustomText(text: "Dash", color: lightGrey, size: 20, weight: FontWeight.bold,)),
Expanded(child: Container()),
IconButton(icon: Icon(Icons.settings, color: dark,), onPressed: (){}),
Stack(
children: [
IconButton(icon: Icon(Icons.notifications, color: dark.withOpacity(.7),), onPressed: (){}),
Positioned(
top: 7,
right: 7,
child: Container(
width: 12,
height: 12,
padding: EdgeInsets.all(4),
decoration: BoxDecoration(
color: active,
borderRadius: BorderRadius.circular(30),
border: Border.all(color: light, width: 2)
),
),
)
],
),
Container(
width: 1,
height: 22,
color: lightGrey,
),
SizedBox(width: 24,),
CustomText(text: 'username', color: lightGrey,),
SizedBox(width: 16,),
Container(
decoration: BoxDecoration(
color: active.withOpacity(.5),
borderRadius: BorderRadius.circular(30)
),
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(30)
),
padding: EdgeInsets.all(2),
margin: EdgeInsets.all(2),
child: CircleAvatar(
backgroundColor: light,
child: Icon(Icons.person_outline, color: dark,),
),
),
)
],
),
),
iconTheme: IconThemeData(color: dark),
elevation: 0,
backgroundColor: Colors.transparent,
);

Flutter: How to implement State Management onPressed

I have no idea how to change the state of my grid view when a button is clicked can someone help me with this?
So, I have this textButton that should change the state of my grid view when clicked but I have no idea how to implement it. Below is my code.
From the image attached, when water, food, school etc are clicked the gridview should only provide specific organizations..
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(20.0),
child: ListView(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: Container(
padding: const EdgeInsets.only(left: 20, right: 20),
height: SizeConfig.screenHeight / 6.5,
color: kPrimaryColor,
child: Row(
children: [
const CircleAvatar(
radius: 40,
backgroundImage: AssetImage(
'assets/images/SDG Wheel_Transparent_WEB.png'),
),
const SizedBox(
width: 10,
),
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Donate Today!",
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontFamily: "Quicksand",
decoration: TextDecoration.none),
),
SizedBox(
height: 5,
),
Text(
"Small contributions quickly\nadd up if enough people\ntake up the cause.",
style: TextStyle(
color: Colors.white,
fontSize: 12,
decoration: TextDecoration.none),
),
],
),
Expanded(child: Container()),
Container(
width: 70,
height: 70,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Color(0xFFf3fafc)),
child: Center(
child: IconButton(
icon: SvgPicture.asset("assets/icons/give.svg"),
onPressed: () {},
color: Color(0xFF69c5df),
//size: 30,
),
),
),
],
),
),
),
SizedBox(
height: 30,
),
const Align(
alignment: Alignment.centerLeft,
child: Text(
"Select your desired organisation to donate.",
style: TextStyle(
color: Color(0xFF1f2326),
fontSize: 15,
decoration: TextDecoration.none),
),
),
const Divider(color: Colors.black38),
//here is the textButton
Container(
height: 50,
width: double.infinity,
color: Colors.white,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
for (int i = 0; i < categories.length; i++)
Container(
width: 90,
padding: const EdgeInsets.only(left: 4.0, right: 4.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: kPrimaryColor,
),
child: TextButton(
onPressed: () {}, //here i need a way to change the state of
the grid view
child: Text(categories[i],
style: TextStyle(color: Colors.white)),
),
),
),
],
),
),
),
const Divider(color: Colors.black38),
const SizedBox(
height: 30,
),
GridView.count(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
crossAxisCount: 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
children: _listItem
.map((item) => Card(
color: Colors.transparent,
elevation: 0,
child: GestureDetector(
onTap: () => Navigator.pushNamed(context, item.route),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: DecorationImage(
image: AssetImage(item.image),
fit: BoxFit.cover)),
)),
))
.toList(),
)
],
),
);
}
}
Thanks very much.
The simplest things to do is to Filter your items based on selection by using the .where of Iterable https://api.flutter.dev/flutter/dart-core/Iterable/where.html
Basically when you push your Text button you store the type in a variable (you need a StatefulWidget for that)
then you can use where to filter your _listItem
GridView.count(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
crossAxisCount: 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
children: _listItem
.where((element) {
//if your element is included return true else false
return true;
})
.map((item) => Card(
color: Colors.transparent,
elevation: 0,
child: GestureDetector(
onTap: () => Navigator.pushNamed(context, item.route),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
image: DecorationImage(
image: AssetImage(item.image),
fit: BoxFit.cover)),
)),
))
.toList(),
)
You can check a sample here for the behavior on the button:
https://dartpad.dev/49f2e4818d933c75a0e6ed1d47a836d2

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