How to create a screen with a condition in flutter dart - flutter

I need a little help with flutter. I want to make a screen with a condition. The condition is if we have data show that data from firebase but if we don't have data show a button that says add data. The codes below show data from firebase but when we have no data that shows nothing.
Here are my codes that show a black screen.
#override
Widget build(BuildContext context) {
return GetBuilder<MapLogic>(
builder: (mapLogic) => Scaffold(
// backgroundColor: Colors.red,
body: StreamBuilder<QuerySnapshot>(
stream:
FirebaseFirestore.instance.collection('collection').snapshots(),
builder: (context, snapshot) {
if (snapshot.hasData) {
if (snapshot.data!.docs.isEmpty) {
return Padding(
padding: const EdgeInsets.only(top: 30),
child: InkWell(
onTap: () async {
generalController.focusOut(context);
Get.to(const AddNewVehicle());
},
child: Container(
height: 55,
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Styles.primaryColor,
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
color: Styles.primaryColor.withOpacity(0.19),
blurRadius: 40,
spreadRadius: 0,
offset: const Offset(
0, 22), // changes position of shadow
),
],
),
child: const Center(
child: Text(
"Add A Vehicle",
// style: state.buttonTextStyle
),
),
),
),
);
} else {
return FadedSlideAnimation(
child: Wrap(
children:
List.generate(snapshot.data!.docs.length, (index) {
if (snapshot.data!.docs[index].get('driver_id') ==
mapLogic.currentDriverData?.get('id')) {
return Padding(
padding: const EdgeInsets.fromLTRB(15, 30, 15, 0),
child: InkWell(
onTap: () {},
child: Container(
width: MediaQuery.of(context).size.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(19),
boxShadow: [
BoxShadow(
color: customThemeColor.withOpacity(0.19),
blurRadius: 40,
spreadRadius: 0,
offset: const Offset(
0, 22), // changes position of shadow
),
],
),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
children: [
///---image
Hero(
tag:
'${snapshot.data!.docs[index].get('image')}',
child: Material(
child: Container(
height: 80,
width: 80,
decoration: const BoxDecoration(
color: Colors.grey,
shape: BoxShape.circle),
child: ClipRRect(
borderRadius:
BorderRadius.circular(40),
child: Image.network(
'${snapshot.data!.docs[index].get('image')}',
fit: BoxFit.cover,
),
),
),
),
),
///---price
Expanded(
child: Align(
alignment:
Alignment.center,
child: Container(
width: 70,
decoration: BoxDecoration(
borderRadius:
BorderRadius
.circular(
19),
color:
customThemeColor),
child: Padding(
padding:
const EdgeInsets
.fromLTRB(
0, 2, 0, 2),
child: Center(
child: Text(
'\$${snapshot.data!.docs[index].get('dis_price')}',
style: state
.priceTextStyle!
.copyWith(
color: Colors
.white)),
),
),
),
),
),
],
),
],
),
),
))
],
),
),
),
),
);
} else {
return const SizedBox();
}
}),
),
beginOffset: const Offset(0, 0.3),
endOffset: const Offset(0, 0),
slideCurve: Curves.linearToEaseOut,
);
}
} else {
return Text(
'Record not found',
textAlign: TextAlign.center,
style: GoogleFonts.poppins(
fontSize: 20,
color: Colors.black,
fontWeight: FontWeight.w600),
);
}
}),
),
);
}

You can follow this pattern but I will suggest following docs' one
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done &&
!snapshot.hasData) {
return Text("could not find any data");
}
if (snapshot.hasData) {...}
if (snapshot.hasError) return Text("error");
return CircularProgressIndicator();
}

Related

How to change circularprogressindicator in Center

I'm having a little problem here, I want to map a circularprogressindicator in the middle of the page but it just appears in the top center of the page, how do I move it to the middle of the page, I've tried wrapping it using the Column widget but an error occurs. How do I solve this simple problem.
and one more how do I add a hintText in the dropdown as the default value, because the dropdown immediately takes the value 1.
Thank you.
note:
green color for dropdown case
red for circularprogressindicator cases
Here I attach the code.
class JadwalKuliah extends StatefulWidget {
const JadwalKuliah({super.key});
#override
State<JadwalKuliah> createState() => _JadwalKuliahState();
}
class _JadwalKuliahState extends State<JadwalKuliah> {
String? _selectedItem1;
List<int> listitems = [1, 2, 3, 4, 5, 6, 7, 8];
int semester = 1;
List<Datum> data = [];
#override
void initState() {
super.initState();
fetchData(semester);
}
fetchData(int smt) async {
final apiResponse = await JadwalKuliahProvider.getJadwalKuliah(smt);
setState(() {
data = (apiResponse);
});
}
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(kToolbarHeight),
child: CustomAppbar(
title: 'Jadwal Kuliah',
),
),
body: Center(
child: Padding(
padding: const EdgeInsets.only(
left: 14,
top: 14,
right: 14,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Header(),
listJadwal(),
],
),
),
),
);
}
Widget Header() {
return Container(
padding: const EdgeInsets.only(left: 12, right: 8),
width: double.infinity,
height: 50,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 9,
offset: const Offset(
1,
2,
),
),
],
),
child: DropdownButtonHideUnderline(
child: DropdownButton(
// hint: const Text('Pilih Semester'),
value: semester,
onChanged: (value) {
setState(
() {
semester = value!;
},
);
fetchData(value!);
},
hint: const SizedBox(
width: 150, //and here
child: Text(
"Pilih Semester",
style: TextStyle(color: Colors.grey),
),
),
items: listitems.map(
(itemone) {
return DropdownMenuItem(
value: itemone, child: Text(itemone.toString()));
},
).toList(),
),
),
);
}
Widget listJadwal() {
return FutureBuilder<List<Datum>>(
future: JadwalKuliahProvider.getJadwalKuliah(semester),
builder: (context, snapshot) {
if (snapshot.hasData) {
return Expanded(
child: ListView.builder(
padding: const EdgeInsets.only(
top: 10,
),
physics: const BouncingScrollPhysics(),
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.only(top: 14),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.all(
Radius.circular(
10,
),
),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.2),
spreadRadius: 1,
blurRadius: 9,
offset: const Offset(
1, 2), // changes position of shadow
),
],
),
padding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
// "Audit Bank Syariah (SPI)",
snapshot.data![index].nmMk.toString(),
style: bold6,
),
Text(
snapshot.data![index].dosenAjar!.nmDosen.toString(),
style: regular7,
),
Text(
// "Perbankan Syariah",
snapshot.data![index].prodi.toString(),
style: regular7,
),
const SizedBox(
height: 5,
),
Row(
children: [
Container(
height: 30,
width: 70,
decoration: BoxDecoration(
color: const Color(0xffECECEC),
borderRadius: BorderRadius.circular(5)),
child: Padding(
padding: const EdgeInsets.all(5),
child: Row(
children: [
Icon(
Icons.location_on_outlined,
color: greyColor,
size: 18,
),
const SizedBox(
width: 3,
),
Text(
'A201',
// snapshot.data![index]
// .dosenAjar!.nmDosen
// .toString(),
style: bold6.copyWith(color: greyColor),
),
],
),
),
),
const SizedBox(
width: 10,
),
Container(
height: 30,
width: 120,
decoration: BoxDecoration(
color: const Color(0xffECECEC),
borderRadius: BorderRadius.circular(5)),
child: Padding(
padding: const EdgeInsets.all(5),
child: Row(
children: [
Icon(
Icons.watch_later_outlined,
color: greyColor,
size: 18,
),
const SizedBox(
width: 3,
),
const SizedBox(
width: 3,
),
Text(
// snapshot
// .data![index].jamAwal
// .toString(),
'09:00',
style: bold6.copyWith(
color: greyColor,
),
),
const SizedBox(
width: 3,
),
Text(
'-',
// snapshot
// .data![index].jamAkhir
// .toString(),
style: bold6.copyWith(
color: greyColor,
),
),
const SizedBox(
width: 3,
),
Text(
'12:00',
// snapshot
// .data![index].jamAkhir
// .toString(),
style: bold6.copyWith(
color: greyColor,
),
),
],
),
),
),
const SizedBox(
width: 10,
),
SizedBox(
height: 30,
width: 100,
child: ElevatedButton.icon(
onPressed: () {},
icon: const Icon(
Icons.download,
size: 17,
color: Color(0xffCEE1FF),
),
label: Text(
'Materi',
style: bold6,
),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xff0062FF),
),
),
),
],
),
const SizedBox(
height: 10,
),
Container(
width: double.infinity,
height: 38,
child: TextButton(
onPressed: () {},
style: TextButton.styleFrom(
backgroundColor: const Color(0xffC9F7F5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text(
"Absen",
style: bold5.copyWith(
color: const Color(
0xff1BC5BD,
),
),
),
),
),
],
),
),
);
}),
);
} else {
return Center(
child: CircularProgressIndicator(color: primaryColor),
);
}
},
);
In your listJadwal change CircularProgressIndicator to this:
} else {
return Expanded(
child: Center(
child: CircularProgressIndicator(color: primaryColor),
),
);
}
Try below code I have same issue occurred I resolve this following code:
SizedBox(
height: MediaQuery.of(context).size.height / 1.0,//change on your need
child: Center(
child: CircularProgressIndicator(color: primaryColor),
),
),
Try this, Column will use your full screen size to center the widget
body: Column(mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: CircularProgressIndicator(),
)
],),

Tinder Widget Visiblility

I used swipe_cards package for tinder like swipe but i am unable to add Text Widget That are appear during left, right and top swipe (noop, like,and super like).
class DatingAppDesign extends StatefulWidget {
#override
_DatingAppDesignState createState() => _DatingAppDesignState();
}
class _DatingAppDesignState extends State<DatingAppDesign> {
List<SwipeItem> _swipeItems = [];
late MatchEngine _matchEngine;
GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey();
List<String> _names = ["1", "2", "3", "4", "last"];
List<Color> _colors = [
Colors.red,
Colors.blue,
Colors.green,
Colors.yellow,
Colors.orange
];
#override
void initState() {
for (int i = 0; i < _names.length; i++) {
_swipeItems.add(SwipeItem(
content: Content(text: _names[i], color: _colors[i]),
likeAction: () {
},
nopeAction: () {
},
superlikeAction: () {
}));
}
_matchEngine = MatchEngine(swipeItems: _swipeItems,);
super.initState();
}
#override
Widget build(BuildContext context) {
double ha = MediaQuery.of(context).size.height -
138 -
MediaQuery.of(context).padding.top;
return Scaffold(
body: Container(
height: ha,
width: double.infinity,
color: Colors.white,
child: Column(
children: [
Container(
decoration: BoxDecoration(
// color: Colors.white,
borderRadius: BorderRadius.vertical(
top: Radius.circular(35.0),
),
),
width: MediaQuery.of(context).size.width*0.8,
height: ha*0.7,
child: Center(
child: SwipeCards(
matchEngine: _matchEngine,
itemBuilder: (BuildContext context, int index) {
return Stack(children: [
Container(
alignment: Alignment.center,
color: _swipeItems[index].content.color,
child: Text(
_swipeItems[index].content.text,
style: TextStyle(fontSize: 100),
),
),
Center(child: Text("Hello World"),),
],
);
},
onStackFinished: () {
},
),
),
),
Container(
height: ha * 0.3,
child: Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Container(
padding: EdgeInsets.all(1),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey,
//offset: Offset(0.0, 1.0), //(x,y)
blurRadius: 10.0,
),
],
color: Colors.white,
borderRadius: BorderRadius.circular(39),
),
constraints: BoxConstraints(maxHeight: 78, minWidth: 78),
child: Center(
child: SvgPicture.asset(
'assets/icons/cross.svg',
// color: Colors.white12,
),
),
),
Container(
padding: EdgeInsets.all(1),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey,
// offset: Offset(0.0, 1.0), //(x,y)
blurRadius: 10.0,
),
],
color: Colors.red,
borderRadius: BorderRadius.circular(49.5),
),
constraints: BoxConstraints(maxHeight: 99, minWidth: 99),
child: Center(
child: SvgPicture.asset(
'assets/icons/heart.svg',
// color: Colors.white12,
),
),
),
Container(
padding: EdgeInsets.all(1),
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey,
// offset: Offset(0.0, 1.0), //(x,y)
blurRadius: 10.0,
),
],
color: Colors.white,
borderRadius: BorderRadius.circular(39),
),
constraints: BoxConstraints(maxHeight: 78, minWidth: 78),
child: Center(
child: SvgPicture.asset(
'assets/icons/star.svg',
// color: Colors.white12,
),
),
),
],
),
),
],
),
),
appBar: appbar,
bottomNavigationBar: BottomNevigationDesign(),
);
}
}
I used Gesture Detector but it did not work. I read all event that under swipe_cards use same example that are on pub.dev. I am totally stuck please help me out thank you.
Based on your comment I think you are looking for snackbar in flutter.
https://flutter.dev/docs/cookbook/design/snackbars

Flutter How to get value from a custom widget

I have a container that color can change using a color list. I want to get the selected color of the container from the main page. When the container clicked, a list of colors appears and we can select the color for the container. I want to do is to get the color value from that container when I press a button
Widget build(BuildContext context) {
return Container(
height: 80,
width: 40,
padding: EdgeInsets.all(5),
child: InkWell(
onTap: () {
showDialog(
context: context,
child: Dialog(
backgroundColor: Colors.white,
// insetPadding: EdgeInsets.all(100),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
child: Column(
children: [
Container(
color: Colors.red,
height: 50,
alignment: Alignment(0, 0),
child: Text(
'Select the Color',
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 20),
),
),
ListView.builder(
shrinkWrap: true,
itemCount: colors.length,
itemBuilder: (context, index) {
return GestureDetector(
child: Container(
decoration: BoxDecoration(
//border: Border.all(),
),
padding: EdgeInsets.all(5),
child: Row(
children: <Widget>[
SizedBox(
width: 20,
),
Container(
decoration: BoxDecoration(
boxShadow: <BoxShadow>[
BoxShadow(blurRadius: 10)
],
border: Border.all(),
borderRadius:
BorderRadius.circular(100),
color: color[index]),
padding: EdgeInsets.all(5),
//color: color[index],
height: 45,
width: 45,
),
Padding(
padding: EdgeInsets.all(10),
),
Text(
colors[index],
style: TextStyle(
fontFamily:
GoogleFonts.inter().fontFamily,
color: color[index],
fontSize: 20.0,
shadows: [
Shadow(
// bottomLeft
offset: Offset(0, 1.5),
blurRadius: 5,
color: Colors.black),
],
),
),
],
),
),
onTap: () {
Navigator.pop(context);
setState(() {
selectedColor = color[index];
print(index);
});
},
);
})
],
)),
);
},
child: Container(
padding: EdgeInsets.all(10),
width: 20,
height: 60,
decoration: BoxDecoration(
color: selectedColor,
borderRadius: BorderRadius.circular(10),
),
),
),
);
}
You can pass the value to parent when you call Navigator.pop().
https://flutter.dev/docs/cookbook/navigation/returning-data
onTap: () {
Navigator.pop(context, color[index]);
setState(() {
selectedColor = color[index];
print(index);
});
},
In this case, you need to wait for result after call Navigator push method.
final result = await Navigator.push(
...

Flutter will not color in containers

Im am using flutter and I have a custom widget that I've made. I use a list.builder to create the list of widgets. Now I want to color the container in which the custom widget lives in but I cant. I color coded each of the container I could see but for some reason I cant. I took it a step further and colored all the indiviual parts of the custom widget to no avail.
Custom Widget:
return Scaffold(
body: Center(
child: AnimatedContainer(
width: 400,
height: 400,
duration: Duration(seconds: 0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10.0)),
border: Border.all(color: Colors.black),
color: Colors.pink,
),
child: Stack(
children: [
Container(
margin: EdgeInsets.fromLTRB(15, 15, 15, 0),
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 3),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
border: Border.all(color: Colors.black),
color: Colors.indigoAccent,
),
child: Text(
title,
overflow: TextOverflow.ellipsis,
),
),
Container(
color: Colors.limeAccent,
child: FutureBuilder(
future: RetrieveProfile_getImage(),
initialData: [],
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: Text('Please wait its loading...'));
} else {
if (snapshot.hasError) {
return Center(
child: Text('Error: ${snapshot.error}'));
} else {
return new Container(
margin: EdgeInsets.fromLTRB(0, 50, 0, 0),
// padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
color: Colors.lightGreenAccent,
height: 275,
child: Center(
child: Image(
fit: BoxFit.contain,
image: MemoryImage(_base64),
),
),
);
}
}
}),
),
Container(
margin: EdgeInsets.fromLTRB(15, 330, 15, 0),
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 3),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
border: Border.all(color: Colors.black),
color: Colors.orange,
),
child: Text(
owner,
overflow: TextOverflow.ellipsis,
),
),
Container(
margin: EdgeInsets.fromLTRB(15, 360, 15, 0),
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 3),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5.0)),
border: Border.all(color: Colors.black),
color: Colors.purpleAccent,
),
child: Text(
location,
overflow: TextOverflow.ellipsis,
),
),
Container(
color: Colors.lightBlue,
margin: EdgeInsets.fromLTRB(340, 345, 15, 35),
child: FutureBuilder(
future: getLikes(),
initialData: [],
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(child: Text('Please wait its loading...'));
} else {
if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'));
} else {
return LikeButton(
isLiked: _liked,
animationDuration: Duration(milliseconds: 500),
onTap: changeLike,
likeBuilder: (bool isLiked) {
return Icon(
Icons.favorite,
color: isLiked ? Colors.red : Colors.grey,
);
},
countPostion: CountPostion.left,
likeCount: likeCount,
countBuilder: (likeCount, bool isLiked, String text) {
var color = isLiked ? Colors.red : Colors.grey;
Widget result;
if (likeCount == 0) {
result = Text(
'',
style: TextStyle(color: color),
);
} else {
result = Text(
likeCount.toString(),
style: TextStyle(color: color),
);
}
return result;
},
);
}
}
},
),
),
],
),
),
),
);
ListBuilder:
ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: likedEvent.length,
itemBuilder: (context, index) {
EventResource e =
likedEvent[index];
print("ID: " + e.photoModel.id);
return Material(
color: Colors.deepPurple,
child: Container(
color: Colors.amber,
margin: EdgeInsets.all(12),
child: Container(
width: 430,
color: Colors.green,
child: Container(
color: Colors.blue,
child: Event(
user: id,
owner: e.owner,
location: e.address,
title: e.name,
ImageID: e.photoModel.id,
)
),
),
));
},
);
Flutter Render:
Set a backgroundColor inside scaffold

How to ensure button is always pinned to bottom of slide up panel - Flutter

I have the following view.
I would like the "confirm" button to always appear at the bottom of the slide up panel no matter what device is being used. If I position at the bottom correctly using padding or empty containers it is cut off on smaller screen size. Or if I position correctly on a smaller screen I am now running into issues with white space at the bottom. I am using the safe area widget which I thought ensured all widgets stay within the SafeArea?
Here is my code so far:
class ChooseAppointmentView extends StatefulWidget {
#override
_ChooseAppointmentViewState createState() => _ChooseAppointmentViewState();
}
class _ChooseAppointmentViewState extends State<ChooseAppointmentView> {
final List<Appointment> appointmentList = [
Appointment("Monday", DateTime.now(), DateTime.now(), "AM"),
Appointment("Tuesday", DateTime.now(), DateTime.now(), "AM"),
Appointment("Wednesday", DateTime.now(), DateTime.now(), "PM"),
Appointment("Thursday", DateTime.now(), DateTime.now(), "AM"),
Appointment("Friday", DateTime.now(), DateTime.now(), "PM"),
];
DateTime _dateSelected = DateTime.now();
DateTime _initialiseDate = DateTime.now();
#override
Widget build(BuildContext context) {
BorderRadiusGeometry radius = BorderRadius.only(
topLeft: Radius.circular(24.0),
topRight: Radius.circular(24.0),
);
return BaseView<ConfirmDetailsViewModel>(
builder: (context, model, child) => Scaffold(
backgroundColor: AppColours.primaryColour,
body: SafeArea(
child: WillPopScope(
onWillPop: () async {
return false;
},
child: SlidingUpPanel(
maxHeight: MediaQuery.of(context).size.height * .80,
minHeight: 75.0,
parallaxEnabled: true,
parallaxOffset: .5,
panel: Stack(
children: <Widget>[
Center(
child: Column(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.02),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 30,
height: 5,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius:
BorderRadius.all(Radius.circular(12.0))),
),
],
),
Container(
height: MediaQuery.of(context).size.height * 0.02),
Container(
child: Text(
"Select a date in here.",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 24.0,
),
),
),
Container(
height: MediaQuery.of(context).size.height * 0.05),
Container(
height: 200,
child: CupertinoDatePicker(
mode: CupertinoDatePickerMode.date,
minimumDate: _initialiseDate,
maximumDate: _initialiseDate.add(Duration(days: 7)),
initialDateTime: _initialiseDate,
onDateTimeChanged: (dateSelected) {
setState(() {
_dateSelected = dateSelected;
});
},
),
),
Container(
height: MediaQuery.of(context).size.height * 0.05),
Container(
height: 50.0,
width: MediaQuery.of(context).size.width - 50,
child: RaisedButton(
onPressed: () async {
//await model.submit();
Navigator.push(
context,
SizeRoute(
page: ChooseAppointmentView(),
),
);
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0),
),
child: Text('Confirm'),
color: AppColours.primaryLightColour,
textColor: Colors.white,
padding: EdgeInsets.fromLTRB(9, 9, 9, 9),
),
),
],
),
),
],
),
collapsed: Center(
child: Column(
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height * 0.02),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
width: 30,
height: 5,
decoration: BoxDecoration(
color: Colors.grey[300],
borderRadius:
BorderRadius.all(Radius.circular(12.0))),
),
],
),
Container(
height: MediaQuery.of(context).size.height * 0.02),
Container(
decoration: BoxDecoration(
color: Colors.white, borderRadius: radius),
child: Center(
child: Text(
"Select a different date",
style: TextStyle(
color: Colors.black,
fontWeight: FontWeight.normal,
fontSize: 20.0,
),
),
),
),
],
),
),
body: Container(
decoration: BoxDecoration(color: Colors.white),
child: ListView.builder(
padding: EdgeInsets.only(bottom: 100.0),
itemCount: appointmentList.length,
itemBuilder: (BuildContext context, int index) =>
buildAppointmentCards(context, index),
),
),
borderRadius: radius,
),
),
),
),
);
}
Widget buildAppointmentCards(BuildContext context, int index) {
final appointment = appointmentList[index];
return Padding(
padding: const EdgeInsets.all(10.0),
child: Material(
color: Colors.white.withOpacity(0.0),
child: InkWell(
splashColor: Colors.red,
onTap: () {
print('card tapped');
},
child: new Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 7,
offset: Offset(0, 3), // changes position of shadow
),
],
gradient: LinearGradient(
colors: [
AppColours.primaryColour,
AppColours.primaryLightColour,
AppColours.primaryLighterColour,
//add more colors for gradient
],
begin: Alignment.topLeft, //begin of the gradient color
end: Alignment.bottomRight, //end of the gradient color
stops: [0, 0.2, 0.5] //stops for individual color
//set the stops number equal to numbers of color
),
borderRadius: BorderRadius.circular(10),
),
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Container(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 4.0, bottom: 4.0),
child: Row(
children: <Widget>[
Text(
appointment.day,
style:
TextStyle(fontSize: 30.0, color: Colors.white),
),
Spacer(),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 4.0, bottom: 80.0),
child: Row(
children: <Widget>[
Text(
"${DateFormat('hh:mm').format(appointment.date).toString()} - ${DateFormat('hh:mm').format(appointment.date).toString()}",
style:
TextStyle(fontSize: 20.0, color: Colors.white),
),
Spacer(),
],
),
),
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Row(
children: <Widget>[
Text(
DateFormat(
'dd/MM/yyyy',
).format(appointment.date).toString(),
style:
TextStyle(fontSize: 20.0, color: Colors.white),
),
Spacer(),
Text(
appointment.ampm,
style:
TextStyle(fontSize: 20.0, color: Colors.white),
),
],
),
)
],
),
),
),
),
),
),
);
}
}
[enter link description here][2]
I think you can use the Align widget for positioning your widget in Stack. For more information can see in this link in this link you will see examples including explanation in the video.