Setting Height on Grid Tile Bar - flutter

I have a general question regarding the height of a GridTile Bar.
I currently have the GridTile display like this:
My Objective is to have it like this:
When I add the SizedBox to leave a space between price and Address, the address gets cut off the second line.
Any Ideas on how to move it up.
Here is my code of the Grid Tile:
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:intl/intl.dart';
import '../providers/listing.dart';
class ListingItem extends StatelessWidget {
#override
Widget build(BuildContext context) {
final listing = Provider.of<Listing>(context, listen: false);
final formatDolar = new NumberFormat("#,##0.00", "en_US");
return ClipRRect(
borderRadius: BorderRadius.circular(10),
child: GridTile(
child: GestureDetector(
onTap: () {},
child: Image.network(
listing.coverPhoto,
fit: BoxFit.cover,
),
),
header: GridTileBar(
title: Text(''),
trailing: IconButton(
icon: Icon(Icons.favorite_border),
color: Theme.of(context).accentColor,
onPressed: () {},
),
),
footer: GridTileBar(
backgroundColor: Colors.black54,
title: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'\$ ${formatDolar.format(listing.price)}',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
SizedBox(
width: 20,
height: 5,
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Flexible(
child: Text(
'${listing.street}, ${listing.street2}, ${listing.city}, ${listing.state}, ${listing.zipCode}',
maxLines: 3,
style: TextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.w500),
),
),
SizedBox(
height: 5,
),
Text(
'|',
style: TextStyle(
fontSize: 18,
color: Colors.white,
fontWeight: FontWeight.bold),
),
SizedBox(
width: 5,
),
Text(
'${listing.bedRooms} bds',
style: TextStyle(
fontSize: 18,
color: Colors.white,
fontWeight: FontWeight.bold),
),
SizedBox(
width: 5,
),
Text(
'|',
style: TextStyle(
fontSize: 18,
color: Colors.white,
fontWeight: FontWeight.bold),
),
SizedBox(
width: 5,
),
Text(
'${listing.bathRooms} bth',
style: TextStyle(
fontSize: 18,
color: Colors.white,
fontWeight: FontWeight.bold),
),
SizedBox(
width: 5,
),
],
),
),
SizedBox(
height: 1,
),
],
),
),
),
);
}
}
and here it is the code for the Grid:
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/listings.dart';
import './listing_item.dart';
class ListingGrid extends StatelessWidget {
#override
Widget build(BuildContext context) {
final listingData = Provider.of<Listings>(context);
final listings = listingData.items;
return GridView.builder(
padding: const EdgeInsets.all(10.0),
itemCount: 10,
itemBuilder: (ctx, i) => ChangeNotifierProvider.value(
value: listings[i],
child: ListingItem(),
),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
childAspectRatio: 3.5 / 2,
crossAxisSpacing: 10,
mainAxisSpacing: 10),
);
}
}
I have tried changing the childAspectRatio in the grid but I only get the cover photo to get bigger not the Tile Bar which is what I want to move up.
Any Ideas?
Kind Regards.

Put GridTileBar widget in a Container widget and give it the height that you want. Here's an example code:
GridTile(
footer: Container(
padding: const EdgeInsets.all(8),
color: Colors.black54,
height: 60,
child: GridTileBar(
title: Text(
"Example",
style: TextStyle(color: Colors.black),
),
),
),

Related

Flutter App Screen is appearing weird on Samsung S8

Image is here
Flutter app screen and text is appearing weird in Samsung S8 mobile
but tested in Other Samsung devises and its working fine, you can see how its supposed to work on the other devices on the above image
any one know why is this screen issue is happening only on samsung s8 ,only this image is here no log is getting so it is hard to resolve , is anyone faced this issue before,
minimumSdk is 21
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:smooth_page_indicator/smooth_page_indicator.dart';
import 'package:splink/src/constants/app_colors.dart';
import 'package:splink/src/controllers/login_view_controllers.dart';
import 'package:splink/src/view/login_view/login_welcome_view.dart';
import 'package:splink/src/view/signup_view/signup_welcome_view.dart';
class LandingView extends StatefulWidget {
const LandingView({Key? key}) : super(key: key);
#override
State<LandingView> createState() => _LandingViewState();
}
class _LandingViewState extends State<LandingView> {
final signLoginController = Get.find<LoginViewController>();
final controller = PageController(
viewportFraction: 1,
keepPage: true,
);
List items = [
"assets/images/6D2Lmtv_X8A.png",
"assets/images/secondimage.png",
"assets/images/thirdImage.png"
];
List textItems = [
//first page of intro
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Text(
"Find and play sports at",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
Text(
"anywhere, anytime",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
SizedBox(
height: 25,
),
Text(
"splink helps you find, connect and organise activities",
style: TextStyle(
color: Colors.white,
),
),
Text(
"with other sports players easily at anywhere, anytime",
style: TextStyle(
color: Colors.white,
),
),
],
),
//second page of intro
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Text(
"Organise and manage",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
Text(
"activties easily",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
SizedBox(
height: 25,
),
Text(
"no more messy groups and missed activities.",
style: TextStyle(
color: Colors.white,
),
),
Text(
"Activity creation and RSVPs, calendar-tracking",
style: TextStyle(
color: Colors.white,
),
),
Text(
"or notifications, everything doe easily in-app",
style: TextStyle(
color: Colors.white,
),
),
],
),
//third page of intro
Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Text(
"Meet, play and endorse",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
Text(
"one another",
style: TextStyle(
fontSize: 28, color: Colors.white, fontWeight: FontWeight.bold),
),
SizedBox(
height: 25,
),
Text(
"Have fun, encourage one another by exchanging medals,",
style: TextStyle(
color: Colors.white,
),
),
Text(
"track sports statistics and keep on playing!",
style: TextStyle(
color: Colors.white,
),
),
],
),
];
#override
Widget build(BuildContext context) {
var size = MediaQuery.of(context).size;
final pages = List.generate(
3,
(index) => Image.asset(
items[index],
fit: BoxFit.cover,
),
);
final pages2 = List.generate(3, (index) => textItems[index]);
return Scaffold(
backgroundColor: primaryColor,
body: Column(
children: [
Expanded(
child: ClipPath(
clipper: ClipPathClass(),
child: PageView.builder(
controller: controller,
padEnds: false,
// itemCount: pages.length,
itemBuilder: (_, index) {
return SizedBox(
height: size.height,
width: size.width,
child: pages[index % pages.length]);
},
onPageChanged: (value) {
signLoginController.curouselIndex(value % pages.length);
},
),
),
),
Expanded(
child: Container(
color: primaryColor,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
child: SmoothPageIndicator(
controller: controller,
count: 3,
effect: const ExpandingDotsEffect(
strokeWidth: 2.0,
dotColor: Colors.white,
activeDotColor: Colors.white,
dotHeight: 6,
dotWidth: 6,
),
),
),
const SizedBox(
height: 15,
),
Obx(
() => textItems[signLoginController.curouselIndex.value],
),
const SizedBox(
height: 70,
),
Padding(
padding: const EdgeInsets.only(right: 15, left: 15),
child: Material(
color: Colors.white,
borderRadius: BorderRadius.circular(15),
child: InkWell(
onTap: () {
Get.to(SignupWelcomeView());
},
borderRadius: BorderRadius.circular(15),
child: Container(
width: size.width,
height: 50,
alignment: Alignment.center,
child: Text(
'Sign Up',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: primaryColor),
),
),
),
),
),
const SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.only(right: 15, left: 15),
child: InkWell(
onTap: () {
Get.to(LoginWelcomeView());
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
border: Border.all(color: Colors.white),
),
width: size.width,
height: 50,
alignment: Alignment.center,
child: const Text(
'Login',
style: TextStyle(
fontSize: 17,
fontWeight: FontWeight.w600,
color: Colors.white),
),
),
),
),
],
),
),
)
],
),
);
}
}
class ClipPathClass extends CustomClipper<Path> {
#override
Path getClip(Size size) {
Path path = Path();
path.addOval(Rect.fromCircle(
center: Offset(size.width * 0.5, -10),
radius: size.height - 20,
));
return path;
}
#override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
I mean, the "issue" is that the width/pixel density of the device is causing the text to overflow to the next line. You can either use a FittedBox, or tweak the fontSize to optimize it depending on the width (using MediaQuery or LayoutBuilder), both sould work.
You can also align the text on the center, instead of to the right, and I'd add some padding to ensure the text doesn't go right up to the screen border.
How do I auto scale down a font in a Text widget to fit the max number of lines?

ListView taking all the vertical space

I am working on a website using Flutter, but I have encountered a problem with ListView.builder. It's working fine until I try to scroll it down, then it takes all the possible space on screen. I also tried to create a ListView.builder in column and I had the same issue that the ListView was showing on the whole possible height.
main.dart:
import 'package:flutter/material.dart';
import 'package:kakadu_web/pages/shop.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Welcome to Flutter',
home: Builder(
builder: (BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Scaffold(body: ShopPage(width, height));
},
));
}
}
shop.dart:
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:google_fonts/google_fonts.dart';
import '../resources/values/colors.dart';
import '../widgets/buttons.dart';
Widget ShopPage(var width, var height) {
return Container(
alignment: Alignment.center,
child: Row(children: [
SizedBox(
width: 80,
height: height,
child: Container(
decoration: BoxDecoration(
color: AppColors.primaryBackgroundColor,
),
child: Column(mainAxisAlignment: MainAxisAlignment.start, children: [
Padding(
padding: const EdgeInsets.only(top: 15),
child: RichText(
text: TextSpan(
style: GoogleFonts.josefinSans(
fontWeight: FontWeight.w700,
fontSize: 60,
color: AppColors.primaryIconColor),
children: [TextSpan(text: "M")])),
),
Container(
height: 200,
),
PageSelectionButton(
text: "Sklepik ",
icon: Icon(Icons.shopping_cart_outlined),
),
PageSelectionButton(
text: "Sklepik ",
icon: Icon(Icons.shopping_cart_outlined),
),
PageSelectionButton(
text: "Sklepik ",
icon: Icon(Icons.shopping_cart_outlined),
),
]),
),
),
Expanded(
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Row(children: [
Expanded(child: Container()),
Flexible(
child: ListTile(
minVerticalPadding: 8,
selectedTileColor: Colors.indigoAccent,
selected: true,
title: Center(
child: RichText(
text: TextSpan(
style: GoogleFonts.rubik(
fontSize: 16, fontWeight: FontWeight.w500),
text: "Wszystko"),
)),
tileColor: Colors.indigo,
),
),
Flexible(
child: ListTile(
minVerticalPadding: 8,
contentPadding: EdgeInsets.only(left: 16),
selectedTileColor: Colors.indigoAccent,
selected: true,
title: Center(
child: RichText(
text: TextSpan(
style: GoogleFonts.rubik(
fontSize: 16, fontWeight: FontWeight.w500),
text: "Wszystko"),
)),
tileColor: Colors.indigo,
),
),
Expanded(child: Container()),
]),
),
Divider(),
Expanded(
child: Container(
child: ListView.builder(
shrinkWrap: true,
padding: EdgeInsets.only(
top: 8,
),
itemBuilder: (context, index) => Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(12),
child: ListTile(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(60))),
leading: SvgPicture.asset(
"assets/drink.svg",
),
title: RichText(
text: TextSpan(
style: GoogleFonts.rubik(
fontSize: 20, fontWeight: FontWeight.w400),
text: "Tymbark Jabłkowy 2L",
)),
subtitle: RichText(
text: TextSpan(
style: GoogleFonts.rubik(
fontSize: 16, fontWeight: FontWeight.w300),
text: "20.00 zł",
)),
onTap: () => debugPrint("Przycisnął"),
tileColor: AppColors.primaryBackgroundColor,
trailing: Container(
width: 100,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
SvgPicture.asset(
"assets/sweets.svg",
semanticsLabel: "Vege",
width: 50,
),
SvgPicture.asset("assets/cold.svg",
semanticsLabel: "Vege", width: 50)
]),
),
),
),
),
],
),
),
),
),
],
),
),
]),
);
}
These are screens how it looks like:
ListView after adding SizedBox
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:google_fonts/google_fonts.dart';
import '../resources/values/colors.dart';
import '../widgets/buttons.dart';
Widget ShopPage() {
return Expanded(
child: Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Row(children: [
Expanded(child: Container()),
Flexible(
child: ListTile(
minVerticalPadding: 8,
selectedTileColor: Colors.indigoAccent,
selected: true,
title: Center(
child: RichText(
text: TextSpan(
style: GoogleFonts.rubik(
fontSize: 16, fontWeight: FontWeight.w500),
text: "Wszystko"),
)),
tileColor: Colors.indigo,
),
),
Flexible(
child: ListTile(
minVerticalPadding: 8,
contentPadding: EdgeInsets.only(left: 16),
selectedTileColor: Colors.indigoAccent,
selected: true,
title: Center(
child: RichText(
text: TextSpan(
style: GoogleFonts.rubik(
fontSize: 16, fontWeight: FontWeight.w500),
text: "Wszystko"),
)),
tileColor: Colors.indigo,
),
),
Expanded(child: Container()),
]),
),
Divider(),
Expanded(
child: SizedBox( // Here is created SizedBox
height: 500,
child: ListView.builder(
shrinkWrap: true,
padding: EdgeInsets.only(
top: 8,
),
itemBuilder: (context, index) => Row(
children: [
Expanded(
child: Padding(
padding: const EdgeInsets.all(12),
child: ListTile(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(60))),
leading: SvgPicture.asset(
"assets/drink.svg",
),
title: RichText(
text: TextSpan(
style: GoogleFonts.rubik(
fontSize: 20, fontWeight: FontWeight.w400),
text: "Tymbark Jabłkowy 2L",
)),
subtitle: RichText(
text: TextSpan(
style: GoogleFonts.rubik(
fontSize: 16, fontWeight: FontWeight.w300),
text: "20.00 zł",
)),
onTap: () => debugPrint("Przycisnął"),
tileColor: AppColors.primaryBackgroundColor,
trailing: Container(
width: 100,
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
SvgPicture.asset(
"assets/sweets.svg",
semanticsLabel: "Vege",
width: 50,
),
SvgPicture.asset("assets/cold.svg",
semanticsLabel: "Vege", width: 50)
]),
),
),
),
),
],
),
),
),
),
],
),
);
}
Listview is expected to take all the possible height given by its parent. So if you expect to have a Listview with finite height you should create a SizedBox() with specific height and make Listview its child.
Here is a youtube video from Flutter team explaining this: https://www.youtube.com/watch?v=jckqXR5CrPI

How do i make background images in container widget change in flutter

I am a newbie to flutter, i am building a website with flutter, i want my container background image to be changing like a carousel. i have tried the carousel widget it works, but it doesnt allow my images to be full width and height. if i can get a way i can make the background image change while maintaining the full screen size, ill appreciate. thanks
here is my code.
import 'dart:ui';
//import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hexcolor/hexcolor.dart';
void main() {
runApp(
MyApp(),
);
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Udos Computers',
home: Scaffold(
extendBodyBehindAppBar: true,
appBar: PreferredSize(
preferredSize: Size(double.infinity, 70.0),
child: ClipRRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: AppBar(
toolbarHeight: 70,
backgroundColor: Colors.black87.withOpacity(0.4),
leading: Image(
image: AssetImage('images/udx.jpg'),
),
title: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextButton(
onPressed: () {},
child: Text(
'PC BUILDER',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
SizedBox(
width: 24,
),
TextButton(
onPressed: () {},
child: Text(
'SHOP',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
SizedBox(
width: 24,
),
TextButton(
onPressed: () {},
child: Text(
'ABOUT US',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
SizedBox(
width: 24,
),
TextButton(
onPressed: () {},
child: Text(
'CONTACT',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
SizedBox(
width: 24,
),
],
),
),
),
),
),
// backgroundColor: Colors.red,
body: Container(
// width: double.infinity,
decoration: BoxDecoration(
color: Colors.black,
image: DecorationImage(
colorFilter: new ColorFilter.mode(
Colors.black.withOpacity(0.4), BlendMode.dstATop),
image: AssetImage('images/udx.jpeg'),
fit: BoxFit.cover,
),
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'We Build Customized Gaming\n computers',
textAlign: TextAlign.center,
style: GoogleFonts.lato(
fontWeight: FontWeight.w900,
fontStyle: FontStyle.normal,
fontSize: 74,
color: Colors.white,
letterSpacing: -2,
),
),
Padding(
padding: const EdgeInsets.only(top: 24),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ButtonBar(
alignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 50,
width: 150,
child: ElevatedButton(
style: TextButton.styleFrom(
backgroundColor: HexColor('#D91702'),
),
onPressed: () {},
child: Text(
'PC Builder',
style: GoogleFonts.lato(
fontSize: 16,
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
letterSpacing: 0.3),
),
),
),
SizedBox(
height: 50,
width: 150,
child: OutlinedButton(
style: OutlinedButton.styleFrom(
// backgroundColor: Colors.red
side: BorderSide(color: Colors.white),
),
onPressed: () {},
child: Text(
'Learn More',
style: GoogleFonts.lato(
fontWeight: FontWeight.w500,
fontSize: 16,
fontStyle: FontStyle.normal,
letterSpacing: 0.3,
color: Colors.white70,
),
),
),
),
],
)
],
),
)
],
),
),
),
),
);
}
}
Here you go, I think this is how you wanted it to be. All you have to do is, instead of using one Container() you need two Containers Stacked on top of each other using Stack() and the top container needs to be transparent with the Column() data and the bottom Container() can be a Carousel Slider with DecorationImage and colorFilter. I completed the code for you, you can test it out.
import 'dart:ui';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:hexcolor/hexcolor.dart';
void main() {
runApp(
const MyApp(),
);
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Udos Computers',
home: Scaffold(
extendBodyBehindAppBar: true,
appBar: PreferredSize(
preferredSize: const Size(double.infinity, 70.0),
child: ClipRRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 5, sigmaY: 5),
child: AppBar(
toolbarHeight: 70,
backgroundColor: Colors.black87.withOpacity(0.4),
leading: const Image(
image: AssetImage('images/udx.jpg'),
),
title: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextButton(
onPressed: () {},
child: Text(
'PC BUILDER',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
const SizedBox(
width: 24,
),
TextButton(
onPressed: () {},
child: Text(
'SHOP',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
const SizedBox(
width: 24,
),
TextButton(
onPressed: () {},
child: Text(
'ABOUT US',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
const SizedBox(
width: 24,
),
TextButton(
onPressed: () {},
child: Text(
'CONTACT',
style: GoogleFonts.lato(
fontWeight: FontWeight.w800,
color: Colors.white70,
),
),
),
const SizedBox(
width: 24,
),
],
),
),
),
),
),
body: Stack(children: [
CarouselSlider(
options: CarouselOptions(
autoPlay: true,
height: double.infinity,
viewportFraction: 1.0,
enlargeCenterPage: false,
),
items: [
Container(
decoration: BoxDecoration(
color: Colors.grey[900],
image: DecorationImage(
colorFilter: ColorFilter.mode(
Colors.black.withOpacity(0.4), BlendMode.dstATop),
image: const AssetImage('images/udx.jpg'),
fit: BoxFit.cover,
),
),
)
]),
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'We Build Customized Gaming\n computers',
textAlign: TextAlign.center,
style: GoogleFonts.lato(
fontWeight: FontWeight.w900,
fontStyle: FontStyle.normal,
fontSize: 74,
color: Colors.white,
letterSpacing: -2,
),
),
Padding(
padding: const EdgeInsets.only(top: 24),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
ButtonBar(
alignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 50,
width: 150,
child: ElevatedButton(
style: TextButton.styleFrom(
backgroundColor: HexColor('#D91702'),
),
onPressed: () {},
child: Text(
'PC Builder',
style: GoogleFonts.lato(
fontSize: 16,
fontWeight: FontWeight.w500,
fontStyle: FontStyle.normal,
letterSpacing: 0.3),
),
),
),
SizedBox(
height: 50,
width: 150,
child: OutlinedButton(
style: OutlinedButton.styleFrom(
// backgroundColor: Colors.red
side: const BorderSide(color: Colors.white),
),
onPressed: () {},
child: Text(
'Learn More',
style: GoogleFonts.lato(
fontWeight: FontWeight.w500,
fontSize: 16,
fontStyle: FontStyle.normal,
letterSpacing: 0.3,
color: Colors.white70,
),
),
),
),
],
)
],
),
)
],
),
),
]),
),
);
}
}

Plotting a drop-down menu with a list of cards

In my flutter project, I want to plot a dropdown list first and then a list of Cards.
Like the above picture, I want to keep a dropdown menu with list of items("All, Visited, Pending, Cancelled") below the appbar and the "All" option selected by default. Below the dropdown box, I want to plot a list of cards.
My main aim is to select the card according to the selected item in the dropdown box. If I select the Pending option from the dropdown then below the cards with only Pending status will be shown. If I choose All option from the dropdown then all of the cards will be shown.
I want to choose the cards according to the dropdown's items.
I have written the code for plotting a list of cards but unable to find out the way to write the code for dropdown menu. Kindly help me plotting the dropdown box (below the appbar & before the cards).
Here is my code for the list of cards:
import 'package:flutter/material.dart';
class AdminHomeContent extends StatefulWidget {
#override
_AdminHomeContentState createState() => _AdminHomeContentState();
}
class _AdminHomeContentState extends State<AdminHomeContent> {
Color getdynamicColor(String status) {
if(status == "Pending"){
return Colors.lightGreen;
}
if (status == "Visited") {
return Colors.green[900];
}
if (status == "Cancelled") {
return Colors.red;
}
return Colors.black;
}
final List<Patient> patients = [
Patient('Person A', 'https://images.unsplash.com/photo-1545996124-0501ebae84d0?ixid=MXwxMjA3fDB8MHxzZWFyY2h8OHx8aHVtYW58ZW58MHx8MHw%3D&ixlib=rb-1.2.1&w=1000&q=80',
8, 2, 'Pending', '10-08-2015', true),
Patient('Person B', 'https://images.unsplash.com/photo-1544005313-94ddf0286df2?ixid=MXwxMjA3fDB8MHxzZWFyY2h8MTF8fGh1bWFufGVufDB8fDB8&ixlib=rb-1.2.1&w=1000&q=80',
8, 5, 'Cancelled', '23-12-2019', false),
Patient('Person C', 'https://images.unsplash.com/photo-1554151228-14d9def656e4?ixid=MXwxMjA3fDB8MHxzZWFyY2h8NHx8aHVtYW58ZW58MHx8MHw%3D&ixlib=rb-1.2.1&w=1000&q=80',
8, 7, 'Visited', '01-02-2019', false),
Patient('Person D', 'https://upload.wikimedia.org/wikipedia/commons/e/ec/Woman_7.jpg',
8, 4, 'Pending', '20-09-2018', true),
Patient('Person E', 'https://cdn.pixabay.com/photo/2017/08/07/14/15/portrait-2604283__340.jpg',
8, 6, 'Visited', '28-04-2017', false)
];
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: aapBarSection('Today\'s Appointments' , Colors.blueAccent[700], context),
body:
Container(
margin: EdgeInsets.only(top: 60.0),
child: ListView.builder(
itemCount: patients.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(9.0),
child: SizedBox(
height: 120,
child: Card(
elevation: 5.0,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: Row(
children: [
Expanded(
flex: 3,
child: Container(
child: CircleAvatar(
backgroundImage: NetworkImage(patients[index].imgPath),
radius: 40.0,
),
),
),
Expanded(
flex: 4,
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(patients[index].name, style: TextStyle(
fontSize: 23.0,
fontWeight: FontWeight.bold,
color: Colors.black87
),),
SizedBox(
height: 20,
),
Text(patients[index].completedSession.toString() +'/'+ patients[index].totalSession.toString(),
style: TextStyle(
fontSize: 18.0,
fontWeight: FontWeight.bold,
color: Colors.black54
),),
],
),
),
),
Expanded(
flex: 3,
child: Container(
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Container(
height: 10,
width: 10,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: getdynamicColor(patients[index].status)
),
),
SizedBox(
width: 8.0,
),
Text(patients[index].status,
style: TextStyle(
fontSize: 15.0,
fontWeight: FontWeight.bold,
color: getdynamicColor(patients[index].status)
),
),
],
),
),
),
],
),
),
),
),
),
);
},
),
),
);
}
}
Here is my model class:
patient.dart
class Patient {
String name ;
String imgPath ;
int totalSession ;
int completedSession ;
String status ;
String dob ;
bool isActive ;
Patient(this.name, this.imgPath,this.totalSession,this.completedSession,this.status,this.dob,this.isActive);
}
Use ExpansionTile , its Easy
ExpansionTile(
initiallyExpanded: false,
title: Text(
"Settings",
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w700,
color: Colors.white),
),
children: <Widget>[
Container(
color: Colors.grey[100],
child: Column(
children: [
ListTile(
title: Text(
'Charges',
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w500,
color: Colors.black87),
),
onTap: () {},
),
Divider(
color: Colors.grey[600],
),
ListTile(
title: Text(
'Billing',
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w500,
color: Colors.black87),
),
onTap: () {},
),
Divider(
color: Colors.grey[600],
),
ListTile(
title: Text(
'Notice',
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.w500,
color: Colors.black87),
),
onTap: () {},
),
],
),

'RenderBox was not laid out' error even after using Expanded

I have added two card widgets in a row enclosed in a columnCode:
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: [
Padding(
padding: EdgeInsets.fromLTRB(0.0, 10, 0.0, 0.0),
child: Row(
children: [
Expanded(
child: SizedBox(
height: 70,
child: Card(
color: Colors.orange[500],
child: ListTile(
leading: CircleAvatar(
backgroundImage:
AssetImage('assets/card_photo.png'),
),
title: Text(
'Teacher of the month',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
fontFamily: 'Poppins-Bold'),
),
subtitle: Text(
'MAY 2020',
style: TextStyle(
fontSize: 8,
fontWeight: FontWeight.bold,
color: Colors.white,
fontFamily: 'Poppins-Bold'),
),
onTap: () {},
),
),
),
),
Expanded(
child: SizedBox(
height: 70,
child: Card(
color: Colors.orange[500],
child: ListTile(
leading: CircleAvatar(
backgroundImage:
AssetImage('assets/card_photo.png'),
),
title: Text(
'Teacher of the month',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
fontFamily: 'Poppins-Bold'),
),
subtitle: Text(
'CLASS NAME',
style: TextStyle(
fontSize: 8,
fontWeight: FontWeight.bold,
color: Colors.white,
fontFamily: 'Poppins-Bold'),
),
onTap: () {},
),
),
),
),
],
),
),
],
),
),
);
}
}
This is the output:Output Image
However I want this row to be scrollabe widgets of cards. But even after using expanded, I am getting 'RenderBox was not laid out' error.
Here is the code for it:
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: MyApp(),
));
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
children: [
Padding(
padding: EdgeInsets.fromLTRB(0.0, 10, 0.0, 0.0),
child: SingleChildScrollView(//added scrollview widget
scrollDirection: Axis.horizontal,
child: Row(
children: [
Expanded(
child: SizedBox(
height: 70,
child: Card(
color: Colors.orange[500],
child: ListTile(
leading: CircleAvatar(
backgroundImage:
AssetImage('assets/card_photo.png'),
),
title: Text(
'Teacher of the month',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
fontFamily: 'Poppins-Bold'),
),
subtitle: Text(
'MAY 2020',
style: TextStyle(
fontSize: 8,
fontWeight: FontWeight.bold,
color: Colors.white,
fontFamily: 'Poppins-Bold'),
),
onTap: () {},
),
),
),
),
Expanded(
child: SizedBox(
height: 70,
child: Card(
color: Colors.orange[500],
child: ListTile(
leading: CircleAvatar(
backgroundImage:
AssetImage('assets/card_photo.png'),
),
title: Text(
'Teacher of the month',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
fontFamily: 'Poppins-Bold'),
),
subtitle: Text(
'CLASS NAME',
style: TextStyle(
fontSize: 8,
fontWeight: FontWeight.bold,
color: Colors.white,
fontFamily: 'Poppins-Bold'),
),
onTap: () {},
),
),
),
),
],
),
),
),
],
),
),
);
}
}
Edit: I also want text below the icon. If someone could help me with that also. Sample image name icon
Check if this works
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class something extends StatelessWidget {
#override
Widget build(BuildContext context) {
var appBar = AppBar();
return Container(
height: MediaQuery.of(context).size.height / 3,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 6,
itemExtent: MediaQuery.of(context).size.height / 3,
itemBuilder: (context, index) {
return _cards(context, appBar);
},
),
);
}
}
Widget _cards(BuildContext context, AppBar appBar) {
return Align(
child: Container(
height: 100,
child: Card(
semanticContainer: true,
clipBehavior: Clip.antiAliasWithSaveLayer,
elevation: 5,
margin: EdgeInsets.all(10),
color: Colors.orange[500],
child: ListTile(
leading: Column(
children: [
CircleAvatar(
backgroundImage: NetworkImage(
'https://flutter.github.io/assets-for-api-docs/assets/widgets/owl.jpg'),
),
Text("Name"),
],
),
title: Text('Teacher of the month', style: _textStyle(10)),
subtitle: Text('MAY 2020', style: _textStyle(8)),
onTap: () {},
),
),
),
);
}
_textStyle(double size) {
return TextStyle(
fontSize: size,
fontWeight: FontWeight.bold,
color: Colors.white,
fontFamily: 'Poppins-Bold');
}
It gives me output like this
You should use listView widget.
ListView(
children: <Widget>[
ItemOne(),
ItemTwo(),
ItemThree(),
],
),
and to change the scroll physics use:
scrollDirection: Axis.horizontal,