Related
I have a close button on right corner. But When i scroll down its scrolling too of course. But i want to it stick to top corner always even if i scroll down. How can i do it ?
My Codes:
Container(
height: MediaQuery.of(context).size.height * 0.95,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(12),
topRight: Radius.circular(12),
),
),
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildCloseButton(context),
SizedBox(
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
CircleAvatar(
radius: 48,
backgroundImage: NetworkImage(therapist.image ?? ""),
)....,
_buildCloseButton
Padding _buildCloseButton(context) {
return Padding(
padding: const EdgeInsets.all(16),
child: Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
children: [
ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
style: ButtonStyle(
shape: MaterialStateProperty.all<CircleBorder>(
const CircleBorder(side: BorderSide(color: Colors.white)),
),
backgroundColor: MaterialStateProperty.all<Color>(Colors.white),
),
child: const Icon(Icons.close, color: Color.fromARGB(255, 48, 58, 87)),
),
],
),
);
}
I tried make it more clear with images . But you can always feel free to ask questions. I tried with Positioned widget too but its same too.Its not sticking to top right corner.
Use Stack Widget and position your button with Positioned Widget like this:
Container(
height: MediaQuery.of(context).size.height * 0.95,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(12),
topRight: Radius.circular(12),
),
),
child: SingleChildScrollView(
physics: const BouncingScrollPhysics(),
child: Stack(
children: [
SizedBox(
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
CircleAvatar(
radius: 48,
// backgroundImage: NetworkImage(therapist.image ?? ""),
)
],
),
),
// your close button
Positioned(
right: 10,
top: 10,
child: ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
style: ButtonStyle(
shape: MaterialStateProperty.all<CircleBorder>(
const CircleBorder(side: BorderSide(color: Colors.white)),
),
backgroundColor:
MaterialStateProperty.all<Color>(Colors.white),
),
child: const Icon(Icons.close,
color: Color.fromARGB(255, 48, 58, 87)),
),
)
],
),
),
)
I made an application like this:
I want to add a little info text on top of this gridView structure. How can I do it? I'm a beginner and I just couldn't do it.
Codes:
body: Container(
padding: EdgeInsets.all(7),
child: GridView.builder(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
itemCount: subjects.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(2.0),
child: Container(
child: InkWell(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.black),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(subjects[index].subjectImage, fit: BoxFit.cover, height: 50, width: 50,),
SizedBox(height: 15,),
Text(subjects[index].subjectName, style: TextStyle(fontSize: 20, fontWeight: FontWeight.w500),),
],
),
),
onTap: () {},
),
),
);
},
),
How can I do it? Thanks in advance.
Try below code. I have added text like Text("1234567890")
body: Container(
padding: EdgeInsets.all(7),
child: Column(
children: [
Text("1234567890"), //<------------
Expanded(
child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10,
),
itemCount: subjects.length,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(2.0),
child: Container(
child: InkWell(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.black),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
subjects[index].subjectImage,
fit: BoxFit.cover,
height: 50,
width: 50,
),
SizedBox(
height: 15,
),
Text(
subjects[index].subjectName,
style: TextStyle(
fontSize: 20, fontWeight: FontWeight.w500),
),
],
),
),
onTap: () {},
),
),
);
},
),
),
],
),
);
You can use #DholaHardik's answer. Just need to wrap the Grid View Builder to a Sized Box and give it a height let's say height = MediaQuery.of(context).size.height and if the error says Overyflow by say 45 pixels.. You can change height to MediaQuery.of(context).size.height - 45;
I want scroll view in flutter but it doesn't work.
I put the SingleChildScrollView inside Align and the Align inside Stack then i put inside SingleChildScrollView Column ,
Is this the reason the list does not work???
Sorry for the unclear explanation😅
this is the code:
Align(
alignment: Alignment.topCenter,
child: Container(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
decoration : BoxDecoration(
//color: Colors.pink
),
child: Padding(
padding: const EdgeInsets.only(right : 12.0),
child: Text('رقمك السري',
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
color : const Color(0xFF193853),
),
),
),
),
Padding(
padding: const EdgeInsets.only(top: 120.0),
child: Container(
width: 250.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(50.0),
topRight: const Radius.circular(50.0),
bottomLeft: const Radius.circular(50.0),
bottomRight: const Radius.circular(50.0),
),
),
child: Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
children:[
Padding(
padding: const EdgeInsets.all(20.0),
child: Center(
child: Text(
'404040',
style: TextStyle(
color: Colors.grey,
fontWeight: FontWeight.bold,
fontSize: 30.0
),
),
),
)
],
),
)
),
Padding(
padding: EdgeInsets.only(top: 10.0),
child: Text(
'شارك الرقم السري',
style: TextStyle(
fontSize: 15.0,
color: const Color(0xFF193853),
fontWeight: FontWeight.bold,
),
),
),
Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 5.0),
child: GestureDetector(
onTap: (){
print("taped");
},
child: Container(
decoration: BoxDecoration(
color: Color(0xFF193853),
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(50.0),
topRight: const Radius.circular(50.0),
bottomLeft: const Radius.circular(50.0),
bottomRight: const Radius.circular(50.0),
),
),
child: Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(5.0, 2.0, 0.0, 2.0),
child: Icon(
Icons.content_copy,
color: Colors.white,
size: 15.0,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(5.0, 0.0, 5.0, 0.0),
child: Text(
'نسخ',
style: TextStyle(
color: Colors.white,
),
),
),
],
),
),
),
),
Padding(
padding: EdgeInsets.only(top: 5.0,left: 10.0),
child: GestureDetector(
onTap: (){
print("Taped2");
},
child: Container(
decoration: BoxDecoration(
color: Color(0xFF193853),
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(50.0),
topRight: const Radius.circular(50.0),
bottomLeft: const Radius.circular(50.0),
bottomRight: const Radius.circular(50.0),
),
),
child: Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(5.0, 2.0, 0.0, 2.0),
child: Icon(
Icons.share,
color: Colors.white,
size: 15.0,
),
),
Padding(
padding: const EdgeInsets.fromLTRB(5.0, 0.0, 5.0, 0.0),
child: Text(
'شارك',
style: TextStyle(
color: Colors.white,
),
),
),
],
),
),
),
)
],
),
),
Padding(
padding: EdgeInsets.only(top: 40.0),
child: Text(
'في إنتظار باقي اللاعبين',
style: TextStyle(
color: Colors.grey[600],
fontSize: 20.0
),
),
),
Padding(
padding: EdgeInsets.only(top: 0.0 , right: 30.0 , left: 30.0),
child: Center(
child: Container(
height: 200.0,
child:ListView.builder(
itemCount: items.length,
itemBuilder: (context,index){
return Align(
child: Container(
padding: EdgeInsets.only(top: 20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
child: Padding(
padding: EdgeInsets.only(right: 5,top: 0),
child: Image.asset(
items[index].img,
width: 60.0,
height: 60.0,
),
),
),
Padding(
padding: const EdgeInsets.only(top: 0.0),
child: Container(
width: 200.0,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: const Radius.circular(50.0),
topRight: const Radius.circular(50.0),
bottomLeft: const Radius.circular(50.0),
bottomRight: const Radius.circular(50.0),
),
),
child: Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
children:[
Padding(
padding: const EdgeInsets.all(20.0),
child: Center(
child: Text(
items[index].name,
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
fontSize: 25.0
),
),
),
)
],
),
)
),
],
),
),
);
},),
),
),
),
],
),
),
),
)
Add this to your ListView.builder
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
I want to create a layout like this,
Image
I want to create a flutter app which can scroll vertically and also some content of the app should scroll horizontally as describe in the picture. I used ListView with scroll horizontal inside the SingleChildScrollView but it not work. It hide the content Horizontal listView content and the content below the ListView.
So How to make this layout
Code I used,
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 10),
child: CustomizedAppBar(),
),
SizedBox(
height: 30.0,
),
Padding(
padding: const EdgeInsets.only(left: 10,bottom: 5),
child: Text(
'Hello Jessica.',
style: kArtistNamePlayScreen,
),
),
Padding(
padding: const EdgeInsets.only(left: 10,bottom: 40),
child: Text(
'Recommendeddd',
style: kSongNamePlayScreen,
),
),
//TODO Insert Carousel Here
ListView(
children: <Widget>[
Container(
height: 150,
width: 230,
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(20.0),
image: DecorationImage(
image: AssetImage('images/Panini_l.jpg'),
fit: BoxFit.cover,
),
boxShadow: [
new BoxShadow(
color: Colors.grey,
offset: Offset(1.5,1.5),
blurRadius: 3,
),
],
),
),
],
),
Text(
'Popular artists',
style: kSongNamePlayScreen,
),
Container(
child: Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(20.0),
child: Container(
width: 60,
height: 75,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8)),
image: DecorationImage(
image: AssetImage('images/Panini_l.jpg'),
fit: BoxFit.cover,
)
),
),
)
],
),
),
SongList(
songListSongName: 'Beautiful People',
songListArtistName: 'Ed Sheeran',
songListAvatarImage: AssetImage('images/beautiful_people_l.jpg'),
heartClick: (){},
),
SongList(
songListSongName: 'Panini',
songListArtistName: 'Lil Nas X',
songListAvatarImage: AssetImage('images/Panini_l.jpg'),
heartClick: (){},
),
SongList(
songListSongName: 'Do You Sleep',
songListArtistName: 'Sam Samith',
songListAvatarImage: AssetImage('images/Do_you_sleep_l.jpg'),
heartClick: (){},
),
SongList(
songListSongName: 'Bad Guys',
songListArtistName: 'Billie Eilish',
songListAvatarImage: AssetImage('images/Bad_guys_l.jpg'),
heartClick: (){},
)
],
),
)
Instead of ListView, you can use SingleChildScrollView with Row as child. Then give the SingleChildScrollView the scrollDirection: Axis.horizontal Code:
//TODO Insert Carousel Here
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
Container(
height: 150,
width: 230,
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(20.0),
image: DecorationImage(
image: AssetImage('images/Panini_l.jpg'),
fit: BoxFit.cover,
),
boxShadow: [
new BoxShadow(
color: Colors.grey,
offset: Offset(1.5, 1.5),
blurRadius: 3,
),
],
),
),
],
),
),
You could use a ListView with horizontal scroll, it has to be wrapped inside a Container or SizedBox with a specific height.
Using ListView.builder could be more efficient, here is a quick example:
final _items = List.generate(20, (e) => e);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Text("A"),
SizedBox(
height: 100.0,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: _items.length,
itemBuilder: (context, index) {
print('$index');
return SizedBox(
width: 150.0,
child: Center(child: Text('${_items[index]}')),
);
}),
),
Text("B"),
],
),
),
);
}
You could see the prints in the console, indicating the items are created only when they're scrolled onto the screen.
I was trying to recreate a design concept from this guy(https://dribbble.com/shots/3812962-iPhone-X-Todo-Concept) but I'm getting some troubles with the ListView alignment or so I think.
What I'm trying to do is moving the List to the right without cutting the edges of the cards when I swipe.
I already tried with margin and padding but none of this applied to the container produces the results I want to obtain.Edges are cutted off when I swipe.
I leave here the Container with the ListView inside it.
Screenshoots of the actual app:
https://imgur.com/a/hJ96sEv
Container(
height: 350.0,
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
itemCount: 3,
controller: scrollController,
scrollDirection: Axis.horizontal,
itemBuilder: (context, position) {
return GestureDetector(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
child: Container(
width: 250.0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Icon(
cardsList[position].icon,
color: appColors[position],
),
Icon(
Icons.more_vert,
color: Colors.grey,
)
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 8.0, vertical: 4.0),
child: Text(
"${cardsList[position].tasksRemaining} Tasks",
style:
TextStyle(color: Colors.grey),
),
),
Padding(
padding:
const EdgeInsets.symmetric(
horizontal: 8.0,
vertical: 4.0),
child: Text(
"${cardsList[position].cardTitle}",
style:
TextStyle(fontSize: 28.0),
)),
Padding(
padding: const EdgeInsets.all(8.0),
child: LinearProgressIndicator(
value: cardsList[position]
.taskCompletion,
),
)
],
),
),
],
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
),
),
onHorizontalDragEnd: (details) {
animationController = AnimationController(
vsync: this,
duration: Duration(milliseconds: 450));
curvedAnimation = CurvedAnimation(
parent: animationController,
curve: Curves.fastOutSlowIn);
animationController.addListener(() {
setState(() {
currentColor =
colorTween.evaluate(curvedAnimation);
});
});
if (details.velocity.pixelsPerSecond.dx > 0) {
if (cardIndex > 0) {
cardIndex--;
colorTween = ColorTween(
begin: currentColor,
end: appColors[cardIndex]);
}
} else {
if (cardIndex < 2) {
cardIndex++;
colorTween = ColorTween(
begin: currentColor,
end: appColors[cardIndex]);
}
}
setState(() {
scrollController.animateTo((cardIndex) * 256.0,
duration: Duration(milliseconds: 450),
curve: Curves.fastOutSlowIn);
});
colorTween.animate(curvedAnimation);
animationController.forward();
});
},
),
),
What I'm trying to do is moving the List to the right without cutting the edges of the cards when I swipe.
To achieve that goal you need a PageView instead of a ListView, that way you can swipe and "snap" the views when you reach and specific position:
PageView.builder(
itemCount: tasks.length,
controller: PageController(initialPage: 0, viewportFraction: 0.8),
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 10),
child: Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Color(0x40000000),
blurRadius: 10,
offset: Offset(0, 12),
),
],
),
child: Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10),
),
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(15),
child: Column(
children: <Widget>[
IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Icon(tasks[index].icon),
Expanded(
child: Container(
child: Align(
alignment: Alignment.topRight,
child: Icon(Icons.menu),
),
),
),
],
),
),
Expanded(
child: Container(
width: double.infinity,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Text(
"${tasks[index].tasks} tasks",
style: TextStyle(
color: Color(0xD0000000),
fontSize: 15,
),
),
SizedBox(height: 10),
Text(
"${tasks[index].title}",
style: TextStyle(
color: Color(0xD0000000),
fontSize: 24,
),
),
SizedBox(height: 10),
LinearProgressIndicator(
value: tasks[index].percentage,
backgroundColor: Color(0x300000FF),
)
],
),
),
),
],
),
),
),
),
);
},
)
The result of this implementation is something like this:
If you want to change the offset of the cards, you need to modify the value viewportFraction: 0.8 to anything you'd like. 1.0 is the value without offset.
You can find my full implementation over this Gist Github