Error message - A value of type 'Color?' can't be assigned to a variable of type 'Color' because 'Color?' is nullable and 'Color' isn't - flutter

How do I resolve this issue because it worked in an older version of flutter saw it on a Youtube video dated 2 years ago. Added some constraints because it's required now.
Getting this error msg - A value of type 'Color?' can't be assigned to a variable of type 'Color' because 'Color?' is nullable and 'Color' isn't.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'info.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
#override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
]);
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData.light(),
home: const MyPage(),
);
}
}
class MyPage extends StatefulWidget {
const MyPage({super.key});
#override
State<MyPage> createState() => _MyPageState();
}
class _MyPageState extends State<MyPage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Restaurant"),
),
body: Padding(
padding: const EdgeInsets.all(5),
child: ListView(
scrollDirection: Axis.vertical,
children: <Widget>[
Hero(
tag: "cakeitem",
child: FittedBox(
child: GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => InfoPage()),
);
},
child: Card(
// color: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
elevation: 5,
child: Row(
children: <Widget>[
itemcake(),
SizedBox(
width: 90,
height: 100,
child: ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: const Image(
fit: BoxFit.cover,
alignment: Alignment.topRight,
image: AssetImage('assets/cake.jpg'),
),
),
),
],
),
),
),
),
),
FittedBox(
child: Card(
// color: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
elevation: 5,
child: Row(
children: <Widget>[
juiceitem(),
Container(
width: 90,
height: 100,
child: ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: const Image(
fit: BoxFit.cover,
alignment: Alignment.topRight,
image: AssetImage('assets/juice.jpg'),
),
),
),
],
),
),
),
FittedBox(
child: Card(
// color: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
elevation: 5,
child: Row(
children: <Widget>[
pizzaitem(),
SizedBox(
width: 90,
height: 100,
child: ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: const Image(
fit: BoxFit.cover,
alignment: Alignment.topRight,
image: AssetImage('assets/pizza.jpg'),
),
),
),
],
),
),
),
FittedBox(
child: Card(
// color: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
elevation: 5,
child: Row(
children: <Widget>[
eliteitem(),
Container(
width: 90,
height: 100,
child: ClipRRect(
borderRadius: BorderRadius.circular(15.0),
child: const Image(
fit: BoxFit.cover,
alignment: Alignment.topRight,
image: AssetImage('assets/elite.jpg'),
),
),
),
],
),
),
),
],
),
),
);
}
Widget itemcake() {
return Column(
//mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const Padding(
padding: EdgeInsets.symmetric(horizontal: 5),
child: Text(
"Italian Choco Cake",
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 15, color: Colors.red),
),
),
const SizedBox(
height: 5,
),
const Text(
"Dark belgium chocolate",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 9.5,
color: Colors.grey),
),
const SizedBox(
height: 5,
),
Row(
children: <Widget>[
const Icon(
Icons.shopping_cart,
size: 15,
),
const SizedBox(
width: 5,
),
Container(
width: 35,
decoration: BoxDecoration(
color: Colors.lightBlue[100],
//color: Theme.of(context).accentColor,
borderRadius: BorderRadius.circular(10),
),
alignment: Alignment.center,
child: const Text(
"Cold",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 9.5),
),
),
const SizedBox(
width: 5,
),
Container(
width: 35,
decoration: BoxDecoration(
color: Colors.red[100],
//color: Theme.of(context).accentColor,
borderRadius: BorderRadius.circular(10),
),
alignment: Alignment.center,
child: const Text(
"Fresh",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 9.5),
),
),
],
),
const SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const <Widget>[
Text(
"Ratings",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 7,
color: Colors.grey),
),
SizedBox(
width: 10,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
],
),
],
);
}
Widget juiceitem() {
return Container(
//width: 150,
child: Column(
//mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const Padding(
padding: EdgeInsets.symmetric(horizontal: 5),
child: Text(
"Fresh Mango Juice",
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 15, color: Colors.red),
),
),
const SizedBox(
height: 5,
),
const Text(
"Dark belgium chocolate",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 9.5,
color: Colors.grey),
),
const SizedBox(
height: 5,
),
Row(
children: <Widget>[
const Icon(
Icons.shopping_cart,
size: 15,
),
const SizedBox(
width: 5,
),
Container(
width: 35,
decoration: BoxDecoration(
color: Colors.lightBlue[100],
//color: Theme.of(context).accentColor,
borderRadius: BorderRadius.circular(10),
),
alignment: Alignment.center,
child: const Text(
"Cold",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 9.5),
),
),
const SizedBox(
width: 5,
),
Container(
width: 35,
decoration: BoxDecoration(
color: Colors.red[100],
//color: Theme.of(context).accentColor,
borderRadius: BorderRadius.circular(10),
),
alignment: Alignment.center,
child: const Text(
"Fresh",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 9.5),
),
),
const SizedBox(
width: 5,
),
Container(
width: 35,
decoration: BoxDecoration(
color: Colors.yellow[400],
//color: Theme.of(context).accentColor,
borderRadius: BorderRadius.circular(10),
),
alignment: Alignment.center,
child: const Text(
"New",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 9.5),
),
),
],
),
const SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const <Widget>[
Text(
"Ratings",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 7,
color: Colors.grey),
),
SizedBox(
width: 10,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
],
),
],
),
);
}
Widget pizzaitem() {
return Column(
//mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const Padding(
padding: EdgeInsets.symmetric(horizontal: 5),
child: Text(
"Cheese Pizza Italy ",
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 15, color: Colors.red),
),
),
const SizedBox(
height: 5,
),
const Text(
"Double cheese New York Style",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 9.5,
color: Colors.grey),
),
const SizedBox(
height: 5,
),
Row(
children: <Widget>[
const Icon(
Icons.shopping_cart,
size: 15,
),
const SizedBox(
width: 5,
),
Container(
width: 35,
decoration: BoxDecoration(
color: Colors.deepOrange[300],
//color: Theme.of(context).accentColor,
borderRadius: BorderRadius.circular(10),
),
alignment: Alignment.center,
child: const Text(
"Spicy",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 9.5),
),
),
const SizedBox(
width: 5,
),
Container(
width: 35,
decoration: BoxDecoration(
color: Colors.yellow[400],
//color: Theme.of(context).accentColor,
borderRadius: BorderRadius.circular(10),
),
alignment: Alignment.center,
child: const Text(
"New",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 9.5),
),
),
],
),
const SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const <Widget>[
Text(
"Ratings",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 7,
color: Colors.grey),
),
SizedBox(
width: 10,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
],
),
],
);
}
Widget eliteitem() {
return Column(
//mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
const Padding(
padding: EdgeInsets.symmetric(horizontal: 5),
child: Text(
"Alinea Chicago",
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 15, color: Colors.red),
),
),
const SizedBox(
height: 5,
),
const Text(
"Classical French cooking",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 9.5,
color: Colors.grey),
),
const SizedBox(
height: 5,
),
Row(
children: <Widget>[
const Icon(
Icons.shopping_cart,
size: 15,
),
const SizedBox(
width: 5,
),
Container(
width: 35,
decoration: BoxDecoration(
color: Colors.deepOrange[300],
//color: Theme.of(context).accentColor,
borderRadius: BorderRadius.circular(10),
),
alignment: Alignment.center,
child: const Text(
"Spicy",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 9.5),
),
),
const SizedBox(
width: 5,
),
Container(
width: 35,
decoration: BoxDecoration(
color: Colors.red,
//color: Theme.of(context).accentColor,
borderRadius: BorderRadius.circular(10),
),
alignment: Alignment.center,
child: const Text(
"Hot",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 9.5,
color: Colors.white),
),
),
const SizedBox(
width: 5,
),
Container(
width: 35,
decoration: BoxDecoration(
color: Colors.yellow[400],
//color: Theme.of(context).accentColor,
borderRadius: BorderRadius.circular(10),
),
alignment: Alignment.center,
child: const Text(
"New",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 9.5,
),
),
),
],
),
const SizedBox(
height: 5,
),
Row(
mainAxisAlignment: MainAxisAlignment.start,
children: const <Widget>[
Text(
"Ratings",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 7,
color: Colors.grey),
),
SizedBox(
width: 10,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
Icon(
Icons.star,
size: 10,
color: Colors.orangeAccent,
),
],
),
],
);
}
}

The problem isn’t that one is nullable and the other is not. The problem is that one may have no value but the other requires one. So what do you think should happen if there is no value? You need to figure that out first before you can change your code.

Related

How to center a Text (vertical and horizontal) in a given space of a card with Flutter?

This is a flutter code and i cant find a way to center the text in the white space. Does anybody know how to center the text of the code in the white space? I have tried to wrap the text with a container and set the textalign to center but nothing worked.
Card(
margin: EdgeInsets.only(left: 24),
elevation: 12,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: Container(
height: MediaQuery.of(context).size.height/4,
width: MediaQuery.of(context).size.width-48,
child: Stack(
children:[
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: const [
Text(
'My',
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 28,
color: Colors.black,
),
),
Text(
'Text',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 28,
color: Colors.black,
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Ink(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(12),
bottomRight: Radius.circular(12),
),
color: Colors.blueAccent,
),
width: 120,
height: MediaQuery.of(context).size.height/4,
child: Align(
alignment: Alignment.center,
child: Icon(
Icons.myicon,
size: 60,
),
),
),
],
),
InkWell(
onTap: () => {},
),
],
),
),
),
enter image description here
#rew, welcome to stackoverflow. have you tried wrapping the text widget by "Center"
Center(
child:Text(
'My',
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 28,
color: Colors.black,
),
),
Try this
Card(
margin: EdgeInsets.only(left: 24),
elevation: 12,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
child: Container(
height: MediaQuery.of(context).size.height/4,
width: MediaQuery.of(context).size.width-48,
child: Stack(
children:[
Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: const [
Center(
child: Text(
'My',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 28,
color: Colors.black,
),
),
),
Center(
child: Text(
'Text',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 28,
color: Colors.black,
),
),
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Ink(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topRight: Radius.circular(12),
bottomRight: Radius.circular(12),
),
color: Colors.blueAccent,
),
width: 120,
height: MediaQuery.of(context).size.height/4,
child: Align(
alignment: Alignment.center,
child: Icon(
Icons.myicon,
size: 60,
),
),
),
],
),
InkWell(
onTap: () => {},
),
],
),
),
),

Flutter Expansion tile

enter image description hereI have a nested list as a expantiontile for example :
if I have a list of years each one includes a list of months and into each one there is a list of days
I want when I press on the day number in the list give me a year, the month, and the day I had to choose.
Example:
If I choose the year 2019 the month Feb then day 5 I need when I press on the day or in the expansion tile it well gives my 5 Feb 2019
.
I tried many ways but all time it gave me just the number of the day without the month and year
In the photo u can see wood ward
Into it there many choices : gate 1 , gate 2 and wood ward st
In gate 1 we had many choices such as tower crane or forkleft etc...
I want when i press on a service like tower crane 1
Return all info : woodward , gate 1 , tower crane 1 .
Now it return just tower crane 1
Than you.
//You can try this code hope this will work for you, Thanks
import 'package:flutter/material.dart';
class DocumentTile extends StatelessWidget {
const DocumentTile({Key ?key,}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Padding(
padding: const EdgeInsets.all(30.0),
child: Card(
margin: const EdgeInsets.only(top: 12, right: 30),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
color: Colors.blue[800],
clipBehavior: Clip.antiAlias,
child: Container(
width: MediaQuery.of(context).size.width * 0.83,
decoration: BoxDecoration(
border: Border.all(color: Colors.pink,width: 1.0),
borderRadius: BorderRadius.circular(8.0),
),
child: ExpansionTile(
tilePadding: const EdgeInsets.only(left: 40.0, right: 30.0),
backgroundColor: Colors.blue[800],
trailing: Container(
width: MediaQuery.of(context).size.width * 0.49,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Container(
width: 0.5,
height: 50,
color: Colors.white,
margin: const EdgeInsets.only(right: 16.0),
),
const Text(
"NUMBER -1",
style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
const Text(
" TITLE",
style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis,
maxLines: 1,
),
],
),
/* Row(
children: [
Container(
margin: const EdgeInsets.only(right: 6),
height: 35,
width: 35,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(4),
),
child: Center(
child: Text(
"guyguy",
),
)),
Container(
height: 35,
width: 35,
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(4),
),
child: IconButton(
icon: Icon(Icons.add, color: Colors.white),
iconSize: 25,
padding: const EdgeInsets.all(5.5),
onPressed: () {},
)),
],
),
Row(
children: [
Container(
margin: const EdgeInsets.only(right: 6),
height: 35,
width: 35,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(4),
),
child: IconButton(
icon: Icon(Icons.more_vert, color: Colors.white),
iconSize: 25,
padding: const EdgeInsets.all(5.5),
onPressed: () {},
)),
Container(
margin: const EdgeInsets.only(right: 6),
height: 35,
width: 35,
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.circular(4),
),
child: IconButton(
icon: Icon(Icons.share_outlined, color: Colors.white),
iconSize: 20,
padding: const EdgeInsets.all(5.5),
onPressed: () {},
)),
Container(
height: 35,
width: 35,
decoration: BoxDecoration(
color: Colors.blueAccent,
borderRadius: BorderRadius.circular(4),
),
child: IconButton(
icon: Icon(Icons.arrow_forward, color: Colors.white),
iconSize: 25,
padding: const EdgeInsets.all(5.5),
onPressed: () {
},
)),
],
),*/
],
),
),
title: const Text(
"No",
style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis,
maxLines: 2,
),
children: [
Container(
width: double.maxFinite,
padding: const EdgeInsets.only(
left: 40.0, right: 30.0, top: 20, bottom: 20),
color: Colors.blue[800],
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: const [
Text(
"Subtitle",
style: TextStyle(
color: Colors.white,
fontSize: 10,
fontWeight: FontWeight.w300),
),
SizedBox(height: 10,),
Text(
"Subtitle2",
style: TextStyle(
color: Colors.white,
fontSize: 10,
fontWeight: FontWeight.w300),
),
SizedBox(height: 10,),
Text(
"Subtitle3",
style: TextStyle(
fontSize: 10,
color: Colors.white,
fontWeight: FontWeight.w300),
),
SizedBox(height: 10,),
Text(
"Subtitle4",
style: TextStyle(
color: Colors.white,
fontSize: 10,
fontWeight: FontWeight.w300),
),
],
),
)
],
),
),
),
),
);
}
}

How to set a image inside a container but also expand outside the container in flutter

I tried to code this all the way I can, but It's still can't move .
I tried to wrap this all in stack and I put the picture as second child, even if i adjust the container width, the image can't get out of the card, and the card padding is stuck there, I can't change anything, how do i fix that
here is the example design
here is my code
children: [
SizedBox(height: 37),
const Text("Hey Mishal,",
style: TextStyle(
fontSize: 26,
color: Color(0xFF0D1333),
fontWeight: FontWeight.bold,
)),
const Text("Find a course you want to learn",
style: TextStyle(
fontSize: 20,
color: Color(0xFF61688B),
height: 2,
)),
Container(
height: 150,
width: 357,
alignment: Alignment.topLeft,
margin: const EdgeInsets.symmetric(vertical: 30),
decoration: BoxDecoration(
color: kDeepBlueTheme,
borderRadius: BorderRadius.circular(15)),
child: Stack(
children: [
Card(
color: Colors.blueAccent,
child: Padding(
padding: const EdgeInsets.only(left: 15, top: 23),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// SizedBox(height: 30, width: 100,),
const Text('50% off',
style: TextStyle(
color: Colors.white,
fontSize: 27,
fontWeight: FontWeight.bold)),
const SizedBox(
height: 5,
),
const Text('For Any Courses',
style: TextStyle(
letterSpacing: 2,
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.w300)),
const SizedBox(
height: 6,
),
ElevatedButton(
//on pressed
onPressed: () async {},
//text to shoe in to the button
child: const Text('Join Now!',
style: TextStyle(color: kMainTheme)),
//style section code here
style: ButtonStyle(
elevation:
MaterialStateProperty.all<double>(0),
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
)),
backgroundColor:
MaterialStateProperty.all<Color>(
Colors.black),
),
),
]),
),
),
Positioned(
bottom: 1,
left: 100,
child: Image.asset(
'assets/person_home.png',
height: 230,
),
)
],
),
),
],
and here is my result ,
how can I achieve that ?
Wrap your Stack with a SizedBox and give it a height greater than the height of Card, use media query heights to make it responsive.
SizedBox(
height: 220,
child: Stack(
alignment: Alignment.bottomCenter,
children: [
Container(
height: 200,
width: double.infinity,
padding: const EdgeInsets.all(8.0),
child: Card(
color: Colors.blueAccent,
child: Padding(
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text('50% off',
style: TextStyle(
color: Colors.white,
fontSize: 25,
fontWeight: FontWeight.bold)),
const SizedBox(
height: 5,
),
const Text('For Any Courses',
style: TextStyle(
letterSpacing: 2,
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.w300)),
const SizedBox(
height: 6,
),
ElevatedButton(
//on pressed
onPressed: () async {},
//text to shoe in to the button
child: const Text('Join Now!',
style: TextStyle(color: Colors.white)),
//style section code here
style: ButtonStyle(
elevation: MaterialStateProperty.all<double>(0),
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
)),
backgroundColor:
MaterialStateProperty.all<Color>(Colors.black),
),
),
]),
),
),
),
Positioned(
right: 0,
top: 0,
child: Image.network(
'https://i.ibb.co/7Kr3Vc2/Screenshot-2022-02-23-at-6-11-05-PM-removebg-preview.png',
fit: BoxFit.cover,
height: 210,
),
)
],
),
),
Try This Result Will be like in pic..
Stack(
children: [
Align(
alignment: Alignment.bottomCenter,
child: Container(
height: 400,
alignment: Alignment.bottomCenter,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.blueGrey,
),
),
),
Row(
children: [
const Padding(
padding:EdgeInsets.only(left: 20,right: 5),
child: Text('hello'),
),
Spacer(),
SizedBox(
height: 700,
child: Image.asset('assets/images/place_holder_avatar.png',fit: BoxFit.cover,),
),
],
),
],
)

Flutter 'child' and 'duration' parameter aren't defined

I don't understand why in Positioned widget, I get an error that child parameter isn't defined as well as in AnimatedContainer the 'duration' parameter isn't defined.
I checked the official documentation first, but don't know why it's not working.
https://api.flutter.dev/flutter/widgets/Positioned-class.html
https://api.flutter.dev/flutter/widgets/AnimatedContainer-class.html
class _DetailsPageState extends State<DetailsPage> {
var selectedCard = 'WEIGHT';
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFF7A9BEE),
appBar: AppBar(
leading: IconButton(
onPressed: () {
Navigator.of(context).pop();
},
icon: Icon(Icons.arrow_back_ios),
color: Colors.white,
),
backgroundColor: Colors.transparent,
elevation: 0.0,
title: Text('Details',
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 18.0,
color: Colors.white)),
centerTitle: true,
actions: <Widget>[
IconButton(
icon: Icon(Icons.more_horiz),
onPressed: () {},
color: Colors.white,
)
],
),
body: ListView(children: [
Stack(children: [
Container(
height: MediaQuery.of(context).size.height - 82.0,
width: MediaQuery.of(context).size.width,
color: Colors.transparent),
Positioned(
top: 75.0,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(45.0),
topRight: Radius.circular(45.0),
),
color: Colors.white),
height: MediaQuery.of(context).size.height - 100.0,
width: MediaQuery.of(context).size.width)),
Positioned(
top: 30.0,
left: (MediaQuery.of(context).size.width / 2) - 100.0,
child: Hero(
tag: widget.heroTag,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(widget.heroTag),
fit: BoxFit.cover)),
height: 200.0,
width: 200.0))),
Positioned(
top: 250.0,
left: 25.0,
right: 25.0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(widget.foodName,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 22.0,
fontWeight: FontWeight.bold)),
SizedBox(height: 20.0),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(widget.foodPrice,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 20.0,
color: Colors.grey)),
Container(height: 25.0, color: Colors.grey, width: 1.0),
Container(
width: 125.0,
height: 40.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(17.0),
color: Color(0xFF7A9BEE)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
InkWell(
onTap: () {},
child: Container(
height: 25.0,
width: 25.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7.0),
color: Color(0xFF7A9BEE)),
child: Center(
child: Icon(
Icons.remove,
color: Colors.white,
size: 20.0,
),
),
),
),
Text('2',
style: TextStyle(
color: Colors.white,
fontFamily: 'Montserrat',
fontSize: 15.0)),
InkWell(
onTap: () {},
child: Container(
height: 25.0,
width: 25.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(7.0),
color: Colors.white),
child: Center(
child: Icon(
Icons.add,
color: Color(0xFF7A9BEE),
size: 20.0,
),
),
),
)
],
),
)
],
),
SizedBox(height: 20.0),
Container(
height: 150.0,
child: ListView(
scrollDirection: Axis.horizontal,
children: <Widget>[
_buildInfoCard('WEIGHT', '300', 'G'),
SizedBox(width: 10.0),
_buildInfoCard('CALORIES', '267', 'CAL'),
SizedBox(width: 10.0),
_buildInfoCard('VITAMINS', 'A, B6', 'VIT'),
SizedBox(width: 10.0),
_buildInfoCard('AVAIL', 'NO', 'AV')
],
)
),
SizedBox(height: 20.0),
Padding(
padding: EdgeInsets.only(bottom:5.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(topLeft: Radius.circular(10.0), topRight: Radius.circular(10.0), bottomLeft: Radius.circular(25.0), bottomRight: Radius.circular(25.0)),
color: Colors.black
),
height: 50.0,
child: Center(
child: Text(
'\$52.00',
style: TextStyle(
color: Colors.white,
fontFamily: 'Montserrat'
)
),
),
),
)
],
))
])
]));
}
Widget _buildInfoCard(String cardTitle, String info, String unit) {
return InkWell(
onTap: () {
selectCard(cardTitle);
},
child: AnimatedContainer(
duration: Duration(milliseconds: 500),
curve: Curves.easeIn,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: cardTitle == selectedCard ? Color(0xFF7A9BEE) : Colors.white,
border: Border.all(
color: cardTitle == selectedCard ?
Colors.transparent :
Colors.grey.withOpacity(0.3),
style: BorderStyle.solid,
width: 0.75
),
),
height: 100.0,
width: 100.0,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.only(top: 8.0, left: 15.0),
child: Text(cardTitle,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 12.0,
color:
cardTitle == selectedCard ? Colors.white : Colors.grey.withOpacity(0.7),
)),
),
Padding(
padding: const EdgeInsets.only(left: 15.0, bottom: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(info,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 14.0,
color: cardTitle == selectedCard
? Colors.white
: Colors.black,
fontWeight: FontWeight.bold)),
Text(unit,
style: TextStyle(
fontFamily: 'Montserrat',
fontSize: 12.0,
color: cardTitle == selectedCard
? Colors.white
: Colors.black,
))
],
),
)
]
)
)
);
}
selectCard(cardTitle) {
setState(() {
selectedCard = cardTitle;
});
}
}
Solved, for some reason I didn't have my Flutter SDK path specified:
1.) Go to Settings
2.) Search Flutter
3.) Click Flutter under Languages & Frameworks
4.) Add you Flutter directory to path, in my case C:\flutter
5.) Apply & OK, Restart IDE

Flutter Card Layout

So I'm new to flutter, and I'm trying to make a card. But I can't seem to get my desired output.
I tried to separate the different widgets, by using rows and columns, but I kept messing it up.
This is my target output
Target output
This is my current progressCurrent progress
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: buildhomePageAppBar(),
body: buildExhibitorBody(),
);
}
Widget buildExhibitorBody() {
return Container(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
buildExhibitorText(),
SizedBox(
height: 10,
),
buildExhibitorCards(),
SizedBox(height: 10),
],
),
),
);
}
Widget buildhomePageAppBar() {
double profileDimension = 35;
return AppBar(
backgroundColor: Colors.white,
titleSpacing: 0,
title: Padding(
padding: EdgeInsets.only(
left: 20,
),
child: Row(
children: [
Padding(
padding: EdgeInsets.only(
top: 5,
bottom: 5,
),
child: Image(
image: AssetImage('assets/images/plain_logo.png'),
height: 30,
),
),
SizedBox(width: 5),
Text(
'Virtex',
style: TextStyle(
color: Colors.black87,
fontFamily: 'Poppins',
fontSize: 16,
fontWeight: FontWeight.bold,
),
)
],
),
),
actions: [
Padding(
padding: EdgeInsets.only(
top: 10,
bottom: 10,
),
child: Container(
height: profileDimension,
width: profileDimension,
alignment: Alignment.center,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.black54,
width: 2,
),
borderRadius: BorderRadius.circular(50),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(50),
child: Image(
width: profileDimension,
height: profileDimension,
image: AssetImage(
'assets/images/profile-image.jpeg',
),
fit: BoxFit.cover,
),
),
),
),
SizedBox(width: 20),
],
);
}
Widget buildExhibitorText() {
return Padding(
padding: EdgeInsets.only(
left: 20,
right: 20,
top: 20,
bottom: 10,
),
child: Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
child: Text(
"Exhibitors",
textAlign: TextAlign.justify,
style: TextStyle(
fontFamily: "DMSans",
letterSpacing: -0.2,
fontSize: 20.0,
color: Colors.black,
fontWeight: FontWeight.w400,
),
),
),
],
),
),
);
}
Widget buildExhibitorCards() { // I think my problem is I don't know how to do the layout here
return Container(
width: 400,
height: 150,
child: Column(children: <Widget>[
Card(
elevation: 1,
child: Padding(
padding: const EdgeInsets.only(),
child: Row(children: [
buildCardImage(),
buildCardExhibitor(),
buildCardIndustry(),
buildCardGo(),
])),
),
]),
);
}
Widget buildCardExhibitor() {
return Row(mainAxisAlignment: MainAxisAlignment.center, children: [
Container(
padding: EdgeInsets.all(10),
width: 40,
height: 40,
child: Center(
child: Row(
children: <Widget>[
Text(
"EN",
style: TextStyle(
fontSize: 15.0,
color: Colors.white,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
Text('Exhibitor Name')
],
),
),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(200),
),
color: Colors.red,
),
),
]);
}
Widget buildCardImage() {
return Container(
height: 100,
width: 100,
child: Image(
image: AssetImage('assets/images/onboarding-2.jpg'),
height: 100,
),
);
}
Widget buildCardIndustry() {
return Padding(
padding: EdgeInsets.only(
left: 40,
right: 40,
),
child: Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text(
"Industry 1",
style: TextStyle(
fontFamily: "DMSans",
color: Colors.grey,
letterSpacing: 0.3,
fontSize: 12,
),
),
Text(
"Industry 2",
style: TextStyle(
fontFamily: "DMSans",
letterSpacing: -0.3,
fontSize: 12,
color: Colors.grey,
fontWeight: FontWeight.w500,
),
),
],
),
),
);
}
Widget buildCardGo() {
return Row(mainAxisAlignment: MainAxisAlignment.end, children: [
Text(
'Go to Booth',
style: TextStyle(
color: Colors.blue,
fontFamily: 'Poppins',
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
SizedBox(width: 5),
IconButton(
icon: Icon(
MdiIcons.fromString('arrow-right'),
size: 30,
color: Colors.black,
),
onPressed: () {
Navigator.of(context).pop();
},
),
]);
}
}
I would greatly appreciate any kind of help.
Look:
My own Code
import 'package:flutter/material.dart';
class CardLayout extends StatelessWidget {
Widget buildCardImage = Container(
margin: EdgeInsets.only(right: 10.0),
width: 150,
height: 150,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage("https://picsum.photos/250?image=9"),
),
),
);
Widget buildCardExhibitor =
Row(mainAxisAlignment: MainAxisAlignment.start, children: [
Container(
padding: EdgeInsets.all(10.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(200),
),
color: Colors.red,
),
child: Text(
"EN",
style: TextStyle(
fontSize: 15.0,
color: Colors.white,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
),
SizedBox(
width: 10.0,
),
Text(
'Exhibitor Name',
style: TextStyle(
fontSize: 15.0,
color: Colors.black,
fontWeight: FontWeight.bold,
),
textAlign: TextAlign.center,
),
]);
Widget buildCardIndustry = Padding(
padding: EdgeInsets.all(8.0),
child: Container(
child: new Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
padding:
EdgeInsets.only(left: 10.0, right: 10.0, top: 5, bottom: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(100),
),
color: Colors.blueGrey.shade400,
),
child: Text(
'Industry 1',
style: TextStyle(
fontFamily: "DMSans",
color: Colors.white,
letterSpacing: 0.3,
fontSize: 12,
),
),
),
SizedBox(
width: 10.0,
),
Container(
padding:
EdgeInsets.only(left: 10.0, right: 10.0, top: 5, bottom: 5),
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(100),
),
color: Colors.blueGrey.shade400,
),
child: Text(
'Industry 2',
style: TextStyle(
fontFamily: "DMSans",
color: Colors.white,
letterSpacing: 0.3,
fontSize: 12,
),
),
),
],
),
),
);
Widget buildCardGo = Row(mainAxisAlignment: MainAxisAlignment.end, children: [
Text(
'Go to Booth',
style: TextStyle(
color: Colors.blue,
fontFamily: 'Poppins',
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
SizedBox(width: 3),
IconButton(
icon: Icon(
Icons.arrow_forward_rounded,
size: 30,
color: Colors.blue,
),
onPressed: () {
//Navigator.pop(context);
},
),
]);
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
appBar: AppBar(
title: Text('Exhibitor'),
actions: [
IconButton(
icon: Icon(Icons.filter_list_rounded),
onPressed: () {
Navigator.pop(context);
})
],
),
body: Container(
margin: EdgeInsets.only(top: 10.0),
width: MediaQuery.of(context).size.width,
//height: 150.0, // remove this line -------------- (1) [EDIT]
child: Column(
// wrap card with column and add listtile as children -------------- (2) [EDIT]
children: [
ListTile(
leading: Text('Exhibitor'),
trailing: IconButton(
icon: Icon(Icons.filter_list_rounded),
onPressed: () {
Navigator.pop(context);
}),
),
Card(
elevation: 5.0,
color: Colors.white,
child: Padding(
padding: EdgeInsets.all(5.0),
child: Row(
children: <Widget>[
buildCardImage,
Expanded(
child: Column(
children: <Widget>[
buildCardExhibitor,
buildCardIndustry,
buildCardGo
],
))
],
),
),
),
],
),
),
));
}
}