How can a container always be visible when scrolling - flutter

I have a question whether it is feasible what I am planning. When I scroll down my page, the red-framed container shouldn't disappear but instead stay in the place of the red frame. I have no idea how to do it right now. Here is the relevant part of the code.
thank you in advance for any idea.
R.Eleven
Screenshot normal
Screenshot where the container should be
it should look like that
Here the Code
body: SingleChildScrollView(
child: Container(
// Main Container
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/bg.jpg"),
fit: BoxFit.cover,
),
),
child: Column(
children: <Widget>[
Container(
// Bild Container
height: 300,
child: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Container(
decoration: BoxDecoration(
boxShadow: [
//background color of box
BoxShadow(
color: Color.fromRGBO(
33,
33,
33,
1,
),
blurRadius: 4, // soften the shadow
spreadRadius: 2, //extend the shadow
offset: Offset(
0.0, // Move to right 10 horizontally
0.0, // Move to bottom 10 Vertically
),
)
],
image: DecorationImage(
fit: BoxFit.cover,
image:
CachedNetworkImageProvider(data['imgUrl'])),
color: Color.fromRGBO(255, 255, 255, 100),
),
),
),
), // Bild
Container(
height: 60,
width: MediaQuery.of(context).size.width,
// Titel Container
child: Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Container(
decoration: BoxDecoration(
boxShadow: [
//background color of box
BoxShadow(
color: Color.fromRGBO(
33,
33,
33,
1,
),
blurRadius: 4, // soften the shadow
spreadRadius: 2, //extend the shadow
offset: Offset(
0.0, // Move to right 10 horizontally
0.0, // Move to bottom 10 Vertically
),
)
],
color: Color.fromRGBO(255, 255, 255, 1),
),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Text(data['title'],
style: Theme.of(context).textTheme.headline),
)),
),
), // Titel
Container(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Expanded(
// Left
flex: 4,
child: Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Container(
decoration: BoxDecoration(
boxShadow: [
//background color of box
BoxShadow(
color: Color.fromRGBO(
33,
33,
33,
1,
),
blurRadius: 4, // soften the shadow
spreadRadius: 2, //extend the shadow
offset: Offset(
0.0, // Move to right 10 horizontally
0.0, // Move to bottom 10 Vertically
),
)
],
color: Color.fromRGBO(255, 255, 255, 1),
),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Row(
children: <Widget>[
Text("Portionen: ",
style: Theme.of(context)
.textTheme
.body1),
Text(data['portions'],
style: Theme.of(context)
.textTheme
.body1),
],
),
Text("Zutaten",
style: Theme.of(context)
.textTheme
.title),
Text(data['ingredients'],
style: Theme.of(context)
.textTheme
.body1),
],
),
),
),
),
),
Expanded(
// Right
flex: 6,
child: Padding(
padding:
const EdgeInsets.only(top: 10.0, left: 10),
child: Container(
decoration: BoxDecoration(
boxShadow: [
//background color of box
BoxShadow(
color: Color.fromRGBO(
33,
33,
33,
1,
),
blurRadius: 4, // soften the shadow
spreadRadius: 2, //extend the shadow
offset: Offset(
0.0, // Move to right 10 horizontally
0.0, // Move to bottom 10 Vertically
),
)
],
color: Color.fromRGBO(255, 255, 255, 1),
),
child: Padding(
padding: const EdgeInsets.all(10.0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text("Zubereitung",
style: Theme.of(context)
.textTheme
.body1),
ItemsList(myid: widget.value),
],
),
),
),
),
),
],
),
),
],
),
),
),

I think what you are looking for is Sticky Side Header, try this flutter_sticky_header sample:
import 'package:flutter/material.dart';
import 'package:flutter_sticky_header/flutter_sticky_header.dart';
import '../common.dart';
class SideHeaderExample extends StatelessWidget {
const SideHeaderExample({
Key key,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return AppScaffold(
title: 'Side Header Example',
slivers: [
_StickyHeaderGrid(index: 0),
_StickyHeaderGrid(index: 1),
_StickyHeaderGrid(index: 2),
_StickyHeaderGrid(index: 3),
],
);
}
}
class _StickyHeaderGrid extends StatelessWidget {
const _StickyHeaderGrid({
Key key,
this.index,
}) : super(key: key);
final int index;
#override
Widget build(BuildContext context) {
return SliverStickyHeader(
overlapsContent: true,
header: _SideHeader(index: index),
sliver: SliverPadding(
padding: const EdgeInsets.only(left: 60),
sliver: SliverGrid(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 3, crossAxisSpacing: 4.0, mainAxisSpacing: 4.0),
delegate: SliverChildBuilderDelegate(
(context, i) => GridTile(
child: Card(
child: Container(
color: Colors.green,
),
),
footer: Container(
color: Colors.white.withOpacity(0.5),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'Grid tile #$i',
style: const TextStyle(color: Colors.black),
),
),
),
),
childCount: 9,
),
),
),
);
}
}
class _SideHeader extends StatelessWidget {
const _SideHeader({
Key key,
this.index,
}) : super(key: key);
final int index;
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4.0),
child: Align(
alignment: Alignment.centerLeft,
child: SizedBox(
height: 44.0,
width: 44.0,
child: CircleAvatar(
backgroundColor: Colors.orangeAccent,
foregroundColor: Colors.white,
child: Text('$index'),
),
),
),
);
}
}

Related

I want to Hide some widgets from SliverAppbar On Scroll Flutter

enter image description here
Hello, I want to keep and hide few things on scroll from SliverAppBar bottom section. For example, when I scroll the list from top to bottom, the logo , branch, distance, etc should hide. The leading, title, actions, and restaurant title will be shown. Below is my code, Can anyone please help?
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:urmenuz/constants/styles.dart';
import 'package:urmenuz/widgets/hidable/hidable.dart';
import '../../constants/colors.dart';
import '../../constants/configs.dart';
import '../../utils/rating_bar.dart';
import 'package:flutter/rendering.dart';
class MenuHeader extends SliverAppBar {
final expandedHeight;
final collapsedHeight;
final bool dineIn;
final Function backFunction;
final Function menuFunction;
final Function infoFunction;
final Function serviceIconFunction;
final Widget tblTextField;
final ScrollController scrollController;
MenuHeader({
this.expandedHeight = 350,
this.collapsedHeight = 160,
this.dineIn = true,
required this.backFunction,
required this.menuFunction,
required this.infoFunction,
required this.serviceIconFunction,
required this.scrollController,
required this.tblTextField,
}) : super(
elevation: 0.0,
pinned: true,
floating: false,
snap: false,
forceElevated: true);
Color? get backgroundColor => AppColors.lightGrey;
// #override
// Widget? get background => Image.asset(IMAGE_ASSET_DIR + 'background2.png',
// fit: BoxFit.cover,
// );
#override
Widget? get leading {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
child: GestureDetector(
onTap: () => backFunction(),
child: Container(
height: 36,
width: 36,
decoration: BoxDecoration(
color: AppColors.lightRed,
borderRadius: BorderRadius.circular(10)),
child: Center(
child: Icon(
Icons.arrow_back_ios_new,
color: Colors.black,
)),
),
),
);
}
#override
Widget? get title {
return Text(
'urMenu',
style: TextStyle(
color: AppColors.lightGrey,
fontWeight: FontWeight.w600,
fontSize: 20),
);
}
#override
List<Widget>? get actions {
return [
Row(
children: [
GestureDetector(
onTap: () => serviceIconFunction(),
child: Image.asset(
IMAGE_ASSET_DIR + "${dineIn ? "dine_in" : "pick_up"}.png",
height: 40,
width: 40,
),
),
SizedBox(
width: 20,
),
Container(
height: 36,
width: 36,
margin: EdgeInsets.only(right: 20),
decoration: BoxDecoration(
color: AppColors.lightRed,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: AppColors.grey.withOpacity(0.1),
offset: Offset(0.0, 0.0), //(x,y)
blurRadius: 4.0,
),
],
),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: GestureDetector(
onTap: () => menuFunction(),
child: Image.asset(
IMAGE_ASSET_DIR + 'menu.png',
color: Colors.black,
)),
)),
],
),
];
}
#override
PreferredSizeWidget? get bottom {
return PreferredSize(
preferredSize: const Size.fromHeight(70),
child: Container(
color: Colors.transparent,
height: 160,
child: Padding(
padding: const EdgeInsets.only(bottom: 50),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Stack(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(left: 20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
// color: Colors.yellow,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
offset: Offset(0.0, 1.0), //(x,y)
blurRadius: 6.0,
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Image.network(
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR7-G-E4aXWzIoakYj-4VpNF8tp5hiaUC5K7yZGDaEjaNddIRMWcvV9lJU1_3F1q_RVqIM&usqp=CAU",
height: 75,
width: 75,
),
),
),
],
),
),
const SizedBox(
width: 12,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
// SizedBox(
// height: 3,
// ),
const Text(
"Branch",
style: TextStyle(
color: AppColors.lightGrey,
fontSize: 14,
fontWeight: FontWeight.w500),
),
const SizedBox(
height: 3,
),
Text(
"The Butcher Shop & Grill",
maxLines: 1,
softWrap: true,
// .toUpperCase(),
style: const TextStyle(
color: AppColors.lightGrey,
fontSize: 20,
fontWeight: FontWeight.bold),
),
const SizedBox(
height: 6,
),
buildRatebar(12, 6, gap: .9),
]),
],
),
// Positioned(
// right: 20,
// child: GestureDetector(
// onTap: () => infoFunction(),
// child: Container(
// decoration: BoxDecoration(
// color: AppColors.lightGrey,
// borderRadius: BorderRadius.circular(20)),
// child: Padding(
// padding: EdgeInsets.all(3),
// child: Image.asset(
// IMAGE_ASSET_DIR + 'info_icon_single.png',
// height: 12,
// width: 12,
// color: dineIn ? AppColors.red : AppColors.orange,
// ),
// )),
// ),
// )
],
),
Padding(
padding: const EdgeInsets.only(right: 20, left: 20, top: 10),
child: Row(
children: [
if (dineIn) tblTextField,
// Text(
// '+ Enter Table #',
// style: TextStyle(
// color: AppColors.lightGrey,
// fontWeight: FontWeight.w500,
// fontSize: 14),
// ),
Spacer(),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Styles.iconButtonWithShape(
Image.asset(
IMAGE_ASSET_DIR + 'location_icon.png',
height: 9,
color: dineIn ? AppColors.red : AppColors.orange,
),
// FaIcon(
// FontAwesomeIcons.locationArrow,
// color: dineIn ? AppColors.red : AppColors.orange,
// size: 12,
// ),
height: 22,
width: 22,
isCircle: true,
showShadow: false,
backgroundColor: dineIn
? AppColors.lightRed
: AppColors.lightOrange,
handler: () {}),
const SizedBox(
width: 6,
),
Text(
"5 KM",
style: TextStyle(
color: AppColors.lightGrey, fontSize: 12),
),
],
),
],
),
)
],
),
),
), // Add this code
);
}
#override
Widget? get flexibleSpace {
return ShaderMask(
// gradient layer ----------------------------
shaderCallback: (bound) {
return LinearGradient(
end: FractionalOffset.topCenter,
begin: FractionalOffset.bottomCenter,
colors: [
Colors.black.withOpacity(0.76),
Colors.black.withOpacity(0.66),
Colors.black26,
],
stops: [
0.0,
0.3,
0.45
]).createShader(bound);
},
blendMode: BlendMode.srcOver,
// your widget ------------------------
child: Container(
// constraints: const BoxConstraints(
// minWidth: 350,
// maxHeight: 350,
// ),
padding: EdgeInsets.all(10),
height: 350,
width: double.infinity,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://media-cdn.tripadvisor.com/media/photo-s/1b/67/cc/f8/chestnut-restaurant.jpg'),
fit: BoxFit.cover),
)),
);
}
}

How do i pass data around between 2 widget methods within the same file and rebuild a section instead of push/pushreplacement in flutter

so im working on an app and come across a situation which I need to work around and cant really seem to find how to. Ive seperated my widgets into seperate build classes/methods and added them in my main Material build element within my MainFoster_screen.dart. petOptions.dart is a scroll list with different avaialable animal types. I need to pass the index of the chosen animal category to petView.dart and display pets available based on the selected category. 1. How do i send the selected category to the petView function. 2. Without sending a push to replace the page (as i want to just rebuild the lower section and update the available pets).
MainFoster_screen.dart
import 'package:flutter/material.dart';
import '../widgets/petOptions.dart';
import '../widgets/petView.dart';
import '../models/animals.dart';
import '../dummy_data.dart';
class Main_Foster extends StatefulWidget {
int PetIconIndex = 0;
static const routeName = "/mainFoster";
#override
State<Main_Foster> createState() => _Main_FosterState();
}
class _Main_FosterState extends State<Main_Foster> {
bool isFavorite = false;
void _Favorite() {
setState(() {
isFavorite = !isFavorite;
});
}
Color greyColor = Color.fromRGBO(245, 245, 245, 1);
//**********Main UI ****/
#override
Widget build(BuildContext context) {
return Material(
color: Color.fromRGBO(245, 245, 245, 1),
child: Padding(
padding: const EdgeInsets.only(
top: 60.0,
),
child: Column(
children: <Widget>[
//Appbar Widget
appBar(),
Expanded(
//main background Widget
child: Padding(
padding: const EdgeInsets.only(top: 30.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Color.fromRGBO(255, 255, 255, 1),
),
child: Column(
children: <Widget>[
//Search Bar
Padding(
padding: const EdgeInsets.symmetric(
vertical: 20, horizontal: 18),
child: Container(
decoration: BoxDecoration(
color: Color.fromRGBO(245, 245, 245, 1),
borderRadius: BorderRadius.circular(14)),
padding: EdgeInsets.only(left: 12),
child: Row(
children: [
Icon(
FontAwesomeIcons.search,
color: Colors.grey,
size: 18,
),
Expanded(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: const EdgeInsets.only(
left: 8,
bottom: 11,
top: 12,
right: 15),
hintText: "Search for a new companion"),
style: TextStyle(
fontSize: 14,
color: Color.fromRGBO(182, 182, 182, 1)),
),
),
],
),
),
),
//Icon Buttons
petOptions(),
//Available pets widget
petView(),
],
),
),
),
)
],
),
),
);
}
}
petView.dart
class petView extends StatelessWidget {
static const routeName = '/petViewW';
#override
Widget build(BuildContext context) {
return Expanded(
child: ListView.builder(
scrollDirection: Axis.vertical,
itemCount: animals.length,
itemBuilder: (context, index) {
return InkWell(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Container(
height: 330,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
Color.fromRGBO(188, 233, 255, 1),
Color.fromRGBO(160, 160, 255, 1),
]),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(182, 182, 182, 0.5),
offset: Offset(0, 0),
blurRadius: 3,
spreadRadius: 1,
)
],
borderRadius: BorderRadius.circular(15)),
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Row(
children: [
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
animals[index].name,
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.w700),
),
SizedBox(
height: 1,
),
Text(animals[index].animal_Breed),
SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
InkWell(
onTap: () => {},
child: Icon(
FontAwesomeIcons.heart,
size: 14,
color: Colors.red,
),
),
],
),
],
),
),
Expanded(
flex: 1,
child: Padding(
padding: const EdgeInsets.only(top: 10.0),
child: Align(
alignment: Alignment.centerRight,
child: Image(
height: 250,
width: 240,
fit: BoxFit.cover,
image: AssetImage(animals[index].Image),
),
),
),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 0.0),
child: Row(
children: [
Expanded(
flex: 1, // 60%
child: ClipRRect(
borderRadius: BorderRadius.only(
bottomRight: Radius.circular(15),
bottomLeft: Radius.circular(15)),
child: Container(
height: 65,
color: Colors.white,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: [
Row(
children: [
Icon(
animals[index].isMale
? FontAwesomeIcons.mars
: FontAwesomeIcons.venus,
size: 23,
color: Colors.grey,
),
SizedBox(
width: 5,
),
Text(
animals[index].isMale
? "Male"
: "Female",
style: TextStyle(fontSize: 14),
),
],
),
Row(
children: [
Icon(
FontAwesomeIcons.clock,
size: 20,
color: Colors.grey,
),
SizedBox(
width: 6,
),
Text(
"${animals[index].age}" + " Years",
style: TextStyle(fontSize: 14),
),
],
)
],
),
),
),
)
],
),
)
],
),
),
),
);
}),
);
}
}
petOptions.dart
class petOptions extends StatefulWidget {
#override
_petOptions createState() => _petOptions();
}
class _petOptions extends State<petOptions> {
var selectedPetIcon = 0;
var selectedAnimalCategory = '0';
void selectAnimal(BuildContext context, int index) {
selectedPetIcon = index;
}
//Pet icon button creation
Widget createPetIcons(
BuildContext context, int index, String id, String name, String image) {
return Padding(
padding: const EdgeInsets.only(
right: 30.0,
),
child: Column(
children: <Widget>[
//Change Selected on tap
InkWell(
onTap: () => setState(() {
selectAnimal(context, index);
}),
//Icon main box
child: Container(
decoration: BoxDecoration(
color: selectedPetIcon == index
? Color.fromRGBO(255, 211, 211, 1)
: Color.fromRGBO(255, 255, 255, 1),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(182, 182, 182, 0.5),
offset: Offset(0, 1),
blurRadius: 3,
spreadRadius: 1,
)
],
borderRadius: BorderRadius.circular(15)),
//Icon
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Center(
child: ImageIcon(
AssetImage(image),
color: selectedPetIcon == index
? Colors.black
: Color.fromRGBO(182, 182, 182, 1),
size: 35,
),
),
),
),
),
SizedBox(
height: 12,
),
//Icon Text
Text(
name,
style: TextStyle(
color: selectedPetIcon == index
? Colors.black
: Color.fromRGBO(182, 182, 182, 1),
fontSize: 14,
fontWeight: FontWeight.w700),
),
],
),
);
}
#override
Widget build(BuildContext context) {
return Column(
children: [
Container(
height: 110,
child: ListView.builder(
padding: EdgeInsets.only(left: 18, top: 4),
scrollDirection: Axis.horizontal,
itemCount: animalCategories.length,
itemBuilder: (context, index) {
return createPetIcons(
context,
index,
animalCategories[index].id,
animalCategories[index].name,
animalCategories[index].Image);
}),
),
],
);
}
}
animals.dart (Holds Animals available)
//Creating new class to assign and initiate values to new animals
import 'package:flutter/material.dart';
class Animal {
final String id;
final String category;
String name;
String animal_Breed;
String Scientific_Name;
double age;
bool isMale;
String Image;
Animal(
{required this.id,
required this.category,
required this.name,
required this.animal_Breed,
required this.Scientific_Name,
required this.age,
required this.Image,
required this.isMale});
}
animalCategories.dart (Holds categories)
//Creating new class to assign and initiate values to new animals
import 'package:flutter/material.dart';
class AnimalCategories {
final String id;
String name;
String Image;
AnimalCategories({
required this.id,
required this.name,
required this.Image,
});
}

How to push down the listview without making the draggablescrollablesheet unscrollable?

I am running into issues pushing down the listview out of view of the draggablescrollablesheet (sheet) while still being able to scroll the sheet. So in simpler words I do not want the blue container to show up when the sheet is at the bottom.
I have tried to edit the height of the listview container and that makes it go offscreen therefore unscrollable.
I have also tried wrapping the sheet in a singlechildscrollview with no luck. I am trying to avoid using a button at all possible costs!
import 'package:flutter/material.dart';
import 'package:photosgroup2/chat/message_model.dart';
import 'package:photosgroup2/chat/user_model.dart';
class FeedTest extends StatefulWidget {
FeedTest({Key key}) : super(key: key);
#override
_FeedTest createState() => _FeedTest();
}
class _FeedTest extends State<FeedTest> {
_buildMessage(
Message message,
User user,
) {
//Reply reply){
String time= message.time;
return Container(
// color: Colors.yellow,
child: Padding(
padding: EdgeInsets.only(left: 0), //5
child: Column(
children: [
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: EdgeInsets.only(left: 5 ,top: 3.5), //10
child: new CircleAvatar(
radius: (17.5),
backgroundImage: AssetImage(
user.profilePic,
),
),
),
SizedBox(
width: 5,
),
Container(
//width: MediaQuery.of(context).size.width,
// width: 300,
child: Material(
color:Color(0x00000000) , //TRANSPARENT
//color: const Color(0xf2ffffff),
///Color(0xe6ffffff) // ! REVISIT Change color of boxes???
/*borderRadius: BorderRadius.only(
topRight: Radius.circular(16.0),
bottomRight: Radius.circular(16.0),
bottomLeft: Radius.circular(16.0),
),*/
child: Padding(
padding: EdgeInsets.only(
left: 10.0), //Revisit
child: Column(
//mainAxisSize: MainAxisSize.min,
mainAxisSize: MainAxisSize.min,
//crossAxis
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 5,
),
Text(
user.name,
style: TextStyle(
fontFamily: 'Lato-Bold',
fontSize: 13 ,
color: const Color(0xd9343f4b),
),
textAlign: TextAlign.left,
),
SizedBox(width: 8),
Padding(
padding: const EdgeInsets.only(left:8.0),
child: Text(
'$time hours ago',
style: TextStyle(
fontFamily: 'Lato',
fontSize: 12 ,
color: const Color(0xff5a6978),
),
textAlign: TextAlign.left,
),
),
SizedBox(
height: 5,
),
//SizedBox(height: 10,),//if(message.imageUrl!='') {
//hasReplies(message, user, reply)
//},
//}
],
),
),
),
),
],
),
SizedBox(height:5),
Container(
//color:Colors.blue,
//: EdgeInsets.only(right:10
//right: 10 * SizeConfig.widthRatio,
//),
child: Container(
//color: Colors.green,
margin: EdgeInsets.only(left:5,right:15),
child: Text(
message.text,
style: TextStyle(
fontFamily: 'Lato',
fontSize: 13 ,
color: const Color(0xff5a6978),
height: 1.5384615384615385
),
textAlign: TextAlign.left,
),
),
),
SizedBox(//color:Colors.amber,
height:15),
Transform.translate(
offset: Offset(-6,0),
child: Container(
width: 350.0,
height: 0.5,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(1.0),
color: const Color(0x40343f4b),
),
),
),
SizedBox(//color:Colors.amber,
height:5),
],
),
),
);
}
#override
Widget build(BuildContext context) {
// visibility of reply button in top right corner
return Scaffold(
backgroundColor: const Color(0xfffafafa),
body: SafeArea(
bottom: false,
top: false,
child: //Column(
//mainAxisAlignment: MainAxisAlignment.spaceAround,
//children: <Widget>[
Stack(
children: <Widget>[
DraggableScrollableSheet(
initialChildSize: 0.068,
minChildSize: 0.068,
maxChildSize: 0.71,
builder: (context, scrollController) {
return Container(
//padding: EdgeInsets.symmetric(horizontal: 20),
child: Stack(
children: [
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(32),
topRight: Radius.circular(32),
),
child: Container(
width: 375, //screen width
height: 812 * 0.71, //screen height *
color: Color(0xffdfdfdf),
),
),
),
Stack(
children: [
Padding(
padding: const EdgeInsets.only(left: 10, top: 20.0),
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(27.5),
topRight: Radius.circular(27.5),
),
child: Container(
//margin: EdgeInsets.only(),
width:340,
//height: 515,
color: Colors.yellow,
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(27.5),
topRight: Radius.circular(27.5),),
child: Container(
// padding: EdgeInsets.only(top:40),
color: Colors.blue,
child: ListView.builder(
//reverse: true,
controller: scrollController,
itemCount: comments.length,
itemBuilder: (BuildContext context, int index) {
final User messenger = comments[index].sender;
final Message message = comments[index];
//final Reply reply = replies[index];
return Column(children: <Widget>[
_buildMessage(
message,
messenger,
), //reply),
SizedBox(
height: 8,
) // !COME BACK TO SPACE BETWEEN
]);
},
),
),
),
),),
),
],
),
Stack(
children: <Widget>[
//67
Padding(
padding: EdgeInsets.only(left: 141, top: 6),
child: SizedBox(
width: 93.0,
height: 29.0,
child: Stack(
children: <Widget>[
SizedBox(
width: 93.0,
height: 29.0,
child: Stack(
children: <Widget>[
// Adobe XD layer: 'Rectangle' (shape)
Container(
width: 93,
height: 29.0,
child: Padding(
padding: EdgeInsets.only(
left: 1, top: 6),
child: Text(
'Place Holder',
style: TextStyle(
fontFamily: 'Lato',
fontSize: 12,
color: const Color(0xffffffff),
),
textAlign: TextAlign.center,
),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(27.5),
color: const Color(0xf2343f4b),
),
),
],
),
),
],
),
),
),
],
),
],
),
);
},
),
],
),
// ],
//),
),
);
}
}

How to stack items on top of each other?

i'm trying make a widget like image below.
Mindset of me is stack item into listview. The items are stacked. But when nesting a stack into listview, the stack needs to be wrapped in a fixed widget. If you remove the listview, you cannot make it into the list as in the picture. First time there is nothing wrong to expect people to ignore.
I hope to get the answer. Thanks.
body: Container(
color: Colors.white,
width: double.infinity,
child: SingleChildScrollView(
child: Stack(
children: <Widget>[
Positioned(top: 10,child: card1(),),
Positioned(bottom: 10,child: card1(),),
],
),
),
),
Item
static Widget card1() {
return Card(
elevation: 0,
child: Container(
margin: EdgeInsets.only(top: 100),
width: double.infinity,
padding: EdgeInsets.only(top: 18, left: 18),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(offset: Offset(0, 8), blurRadius: 8, spreadRadius: 0),
],
),
child: Stack(
children: <Widget>[
Container(
width: 343,
height: 196,
child: SvgPicture.asset(
"assets/bg.svg",
),
),
Container(
padding: EdgeInsets.only(
top: 24,
left: 24,
),
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 10),
child: Text("Vietcombank"),
),
],
),
),
],
),
),
);
}
I created StackedListTile, you can try it (Demo here DartPad)
import 'package:flutter/material.dart';
class StackedListTile extends StatelessWidget {
final Color color;
final String title;
final ImageProvider iconImage;
const StackedListTile({
Key key,
#required this.color,
#required this.title,
#required this.iconImage,
}) : assert(color != null),
super(key: key);
#override
Widget build(BuildContext context) {
return SizedBox(
height: 90.0,
child: Stack(
children: <Widget>[
Container(
margin: const EdgeInsets.only(
left: 18.0,
top: 18.0,
right: 18.0,
),
padding: const EdgeInsets.only(
left: 25.0,
top: 25.0,
right: 25.0,
bottom: 10.0,
),
decoration: BoxDecoration(
color: color,
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(8.0),
topRight: Radius.circular(8.0),
),
),
child: Row(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.circular(5.0),
child: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.white,
child: Image(
image: iconImage,
fit: BoxFit.cover,
),
),
),
),
const SizedBox(width: 5.0),
Expanded(
child: Text(
title,
style: const TextStyle(
color: Colors.white,
letterSpacing: 1.0,
),
),
),
//TODO: Add other stuff here
const Icon(
Icons.arrow_forward_ios,
color: Colors.white,
size: 20.0,
),
],
),
),
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 4.0,
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Colors.transparent, Colors.black12],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
),
),
],
),
);
}
}
Usage:
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: MainPage(),
debugShowCheckedModeBanner: false,
),
);
}
class MainPage extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Demo")),
body: ListView(
children: <Widget>[
StackedListTile(
title: "Techcombank1",
color: Colors.blue[600],
//iconImage: AssetImage("assets/images/1.png"), //TODO: Use this for asset images
iconImage: NetworkImage(
"https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQfo2BL_di4IK1AuHOS4y_16BatmqdkOlcB1JBjJK2zK9sUvZ2FUg&s",
),
),
StackedListTile(
title: "Techcombank2",
color: Colors.red[600],
iconImage: NetworkImage("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQNvzXsqFidC5YqNrKHEJGt1kyC99dJ_EWt_Bcc5dyy4rNGzFk8yQ&s"),
),
StackedListTile(
title: "Techcombank3",
color: Colors.green[600],
iconImage: NetworkImage("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQNvzXsqFidC5YqNrKHEJGt1kyC99dJ_EWt_Bcc5dyy4rNGzFk8yQ&s"),
),
for(int i =0; i<100; i++)
StackedListTile(
title: "Item_$i",
color: Colors.amber.withOpacity(1-(i%10)/10),
iconImage: NetworkImage("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQNvzXsqFidC5YqNrKHEJGt1kyC99dJ_EWt_Bcc5dyy4rNGzFk8yQ&s"),
),
],
),
);
}
}
Try to use SliverToBoxAdapter
body: return Container(
color: Colors.white,
width: double.infinity,
child: SingleChildScrollView(
child: SliverToBoxAdapter(
child: Stack(
children: <Widget>[
Positioned(
top: 10,
child: card1(),
),
Positioned(
bottom: 10,
child: card1(),
),
],
),
),
),
),

Off-screen flutter_swiper slide layout, Stack / Positioned widget

I am trying to achieve this layout and content using Flutter:
https://i.imgur.com/oqiZqHb.png
If I try to offset by -20 using a Positioned widget to have the sticky scroller feature of the flutter_swiper package hide on part of the screen and have the side headers on top of that to cover it I get:
I/flutter ( 6060): Another exception was thrown: A RenderFlex overflowed by Infinity pixels on the bottom.
Removing the Positioned Widget gets the part of the layout working, I might need an additional card in this example but I am struggling to get the slider to offset and have the correct swipable item proportions 141x118 on the Stack with 12 padding right and the third one slightly showing on the right but the widget starting point clips the first one as well.
https://i.imgur.com/AfjqIag.jpg
This is my code for the horizontal slider widget:
import 'package:flutter/cupertino.dart';
import '../../../theme/styles.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'dart:math';
class HorizontalIndicator extends StatefulWidget {
const HorizontalIndicator({
Key key,
}) : super(key: key);
#override
_HorizontalIndicatorState createState() => _HorizontalIndicatorState();
}
class _HorizontalIndicatorState extends State<HorizontalIndicator> {
#override
Widget build(BuildContext context) {
var rnd = new Random();
var next = rnd.nextInt(10) * 1;
double screenWidth = MediaQuery.of(context).size.width;
return Container(
height: 120,
padding: EdgeInsets.only(top: 0),
width: screenWidth,
child: Stack(
overflow: Overflow.visible,
fit: StackFit.expand,
children: <Widget>[
Container(
child: new Swiper(
itemBuilder: (BuildContext context, int index) {
return Container(
margin: EdgeInsets.symmetric(vertical: 6),
decoration: new BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(26)),
boxShadow: [
BoxShadow(
color: ThemeColor.shadowColor,
blurRadius:
3.0,
spreadRadius:
0,
)
],
),
child: Padding(
padding: const EdgeInsets.only(right: 12),
child: ClipRRect(
borderRadius: BorderRadius.circular(26),
child: Image.network(
"https://picsum.photos/150/120?" +
"$index" +
"$next",
fit: BoxFit.cover,
),
),
),
);
},
itemCount: 10,
viewportFraction: 0.43,
scale: 1,
itemWidth: 150,
itemHeight: 120,
layout: SwiperLayout.DEFAULT)),
]),
);
}
}
This is how I am positioning it:
...
Stack(
alignment: AlignmentDirectional.topStart,
fit: StackFit.loose,
overflow: Overflow.visible,
children: [
ListView(children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 85, left: 50),
child: Column(
children: <Widget>[
HorizontalIndicator(),
HorizontalIndicator(),
HorizontalIndicator(),
HorizontalIndicator(),
],
),
),
]),
//ProgressBarLarge2(),
],
),
...
I finally got this layout to work.
Here is how I positioned the items:
Stack(
alignment: AlignmentDirectional.topStart,
fit: StackFit.loose,
children: [
ListView(physics: ClampingScrollPhysics(), children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 80, left: 0),
child: Column(
children: <Widget>[
HorizontalIndicator(),
HorizontalIndicator(),
HorizontalIndicator(),
],
),
),
]),
ProgressBarLarge(
context, ThemeColor.primaryColor, 0.5, 48, 11, "Done", "Pending"),
],
),
This is how the horizontal widget was structured (sorry for the long code!).
I just used Stack and Positioned.fill widget with a -100 right value and tweaked the viewportFraction values:
Container(
height: 124,
padding: EdgeInsets.only(top: 0),
child: Stack(alignment: Alignment.centerLeft, children: <Widget>[
Positioned.fill(
left: 47,
right: -100,
child: Container(
child: new Swiper(
itemBuilder: (BuildContext context, move) {
return Container(
padding: EdgeInsets.symmetric(vertical: 0),
decoration: new BoxDecoration(
borderRadius:
BorderRadius.all(Radius.circular(26)),
boxShadow: [
BoxShadow(
color: ThemeColor.shadowColor.withOpacity(0),
offset: Offset(0, 2),
blurRadius:
87.0, // has the effect of softening the shadow
spreadRadius:
0, // has the effect of extending the shadow
)
],
),
child: Padding(
padding: const EdgeInsets.all(0),
child: Container(
margin: EdgeInsets.all(5),
child: MaterialButton(
elevation: 0,
highlightElevation: 2,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(26.0)),
padding: EdgeInsets.fromLTRB(0, 0.0, 0, 0.0),
color: Colors.grey.shade800,
onPressed: () {
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => SeatsPage()),
);
},
child: Container(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(0),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
left: 24,
top: 12,
right: 24),
child: FittedBox(
fit: BoxFit.scaleDown,
child: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: <Widget>[
Padding(
padding:
const EdgeInsets
.only(
top: 0,
right: 0),
child: Opacity(
opacity: 0.90,
child: Text(
"84",
style: ThemeText
.cardHeaderNumber,
textAlign:
TextAlign.left,
),
),
),
// Icon(
// Icons.more_vert,
// color: Colors.grey.withAlpha(0), // More
// ),
],
),
),
),
Padding(
padding:
const EdgeInsets.fromLTRB(
24, 2, 16, 2),
child: Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: <Widget>[
Opacity(
opacity: 0.50,
child: Text(
"Available",
style: ThemeText
.cardText,
),
),
Icon(
Icons
.fiber_smart_record,
color: ThemeColor
.primaryColor,
),
],
))
],
),
),
],
),
),
),
),
));
},
itemCount: 4,
viewportFraction: viewportFraction,
scale: 1,
itemWidth: 140,
itemHeight: 120,
layout: SwiperLayout.DEFAULT)),
),
]),
),