Text not updating on pressing button in dialog - flutter

I have a Text widget and two buttons to increase or decrease the count. + button to increase the count and - button to decrease the count. And the count is displayed in a Text widget. When I debug, count is changing but the Text is not updating. Not getting any error as well. How to do this. Here is my code:
_showDetails(BuildContext context, String barcodeResult) {
return showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)),
child: Container(
height: 350.0,
width: 200.0,
decoration:
BoxDecoration(borderRadius: BorderRadius.circular(20.0)),
child: Column(
children: <Widget>[
Stack(
children: <Widget>[
Container(
height: 150.0,
),
Container(
height: 100.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(10.0),
),
color: Colors.teal),
),
Positioned(
top: 50.0,
left: 94.0,
child: Container(
height: 90.0,
width: 90.0,
child: CircleAvatar(
ExactAssetImage(
'assets/images/user-image-default.png'),
),
),
)
],
),
SizedBox(
height: 20.0,
),
Padding(
padding: EdgeInsets.all(10.0),
child: Text(
name,
style: TextStyle(
fontSize: 14.0, fontWeight: FontWeight.w300),
),
),
Padding(
padding: EdgeInsets.all(10.0),
child: Text(
description,
style: TextStyle(
fontSize: 14.0, fontWeight: FontWeight.w300),
),
),
Padding(
padding: EdgeInsets.all(10.0),
child: Text(
'Price : $price',
style: TextStyle(
fontSize: 14.0, fontWeight: FontWeight.w300),
),
),
SizedBox(
height: 15.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ClipOval(
child: Material(
color: Colors.teal, // button color
child: InkWell(
//splashColor: Colors.red, // inkwell color
child: SizedBox(
width: 40,
height: 40,
child: Icon(
Icons.add,
color: Colors.white,
)),
onTap: () {
setState(() {
// count++;
count = count + 1;
print(count);
});
},
),
),
),
SizedBox(
width: 20,
),
Text(count.toString()),
SizedBox(
width: 20,
),
ClipOval(
child: Material(
color: Colors.teal, // button color
child: InkWell(
// splashColor: Colors.red, // inkwell color
child: SizedBox(
width: 40,
height: 40,
child: Icon(
Icons.remove,
color: Colors.white,
)),
onTap: () {
setState(() {
//count--;
count = count - 1;
print(count);
});
},
),
),
),
],
),
],
),
),
);
});
}

Screenshot:
Here is the working code.
_showDetails(BuildContext context, String barcodeResult) {
return showDialog(
context: context,
barrierDismissible: true,
builder: (BuildContext context) {
return StatefulBuilder(builder: (context, setState) {
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10.0)),
child: Container(
height: 350.0,
width: 200.0,
decoration: BoxDecoration(borderRadius: BorderRadius.circular(20.0)),
child: Column(
children: <Widget>[
Stack(
children: <Widget>[
Container(
height: 150.0,
),
Container(
height: 100.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(10.0),
topRight: Radius.circular(10.0),
),
color: Colors.teal),
),
Positioned(
top: 50.0,
left: 94.0,
child: Container(
height: 90.0,
width: 90.0,
child: CircleAvatar(
backgroundImage: ExactAssetImage(chocolateImage),
),
),
)
],
),
SizedBox(
height: 20.0,
),
Padding(
padding: EdgeInsets.all(10.0),
child: Text(
name,
style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w300),
),
),
Padding(
padding: EdgeInsets.all(10.0),
child: Text(
description,
style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w300),
),
),
Padding(
padding: EdgeInsets.all(10.0),
child: Text(
'Price : \$${price * count}',
style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.w300),
),
),
SizedBox(
height: 15.0,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ClipOval(
child: Material(
color: Colors.teal, // button color
child: InkWell(
//splashColor: Colors.red, // inkwell color
child: SizedBox(
width: 40,
height: 40,
child: Icon(
Icons.add,
color: Colors.white,
)),
onTap: () {
setState(() {
// count++;
count = count + 1;
print(count);
});
},
),
),
),
SizedBox(
width: 20,
),
Text(count.toString()),
SizedBox(
width: 20,
),
ClipOval(
child: Material(
color: Colors.teal, // button color
child: InkWell(
// splashColor: Colors.red, // inkwell color
child: SizedBox(
width: 40,
height: 40,
child: Icon(
Icons.remove,
color: Colors.white,
)),
onTap: () {
setState(() {
//count--;
count = count - 1;
print(count);
});
},
),
),
),
],
),
],
),
),
);
});
});
}

Related

Navigate back from page flutter

I want to navigate to the previous page using the arrow icon I have added in this code. to where I want to add that code and tell me how to code that part. want to navigate from detail_screen.dart to home_page.dart using the arrow icon I have added. can someone please provide a proper answer for this?
detail_screen.dart
import 'package:flutter/material.dart';
class DetailsScreen extends StatelessWidget {
const DetailsScreen({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
//shadowColor: Colors.transparent,
leading: Icon(
Icons.arrow_back_rounded,
color: Colors.black,
),
actions: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: const [
CircleAvatar(
radius: 40,
backgroundColor: Colors.white,
child:
Icon(Icons.favorite_border_outlined, color: Colors.black),
),
CircleAvatar(
radius: 40,
backgroundColor: Colors.white,
child: Icon(Icons.shopping_bag_outlined, color: Colors.black),
)
],
),
),
],
),
body: Column(
children: <Widget>[
Stack(
alignment: Alignment.bottomRight,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 0),
child: Container(
height: MediaQuery.of(context).size.height * 0.9,
width: MediaQuery.of(context).size.width * 0.9,
padding: const EdgeInsets.only(left: 20),
decoration: const BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/image23.png"),
fit: BoxFit.contain,
),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 20,
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Colors.grey.shade100,
),
alignment: const Alignment(1, 1),
height: 310,
width: 375,
child: Column(
children: [
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(left: 10),
child: Text(
"Crop Top",
style: TextStyle(
fontSize: 24,
color: Color(0xff262626),
fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
),
SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: SizedBox(
width: 25,
height: 25,
child: FloatingActionButton(
onPressed: () {},
backgroundColor: Colors.blueAccent,
child: null),
),
),
SizedBox(
width: 25,
height: 25,
child: FloatingActionButton(
onPressed: () {},
backgroundColor: Colors.amber,
child: null),
),
Padding(
padding: const EdgeInsets.all(10.0),
child: SizedBox(
width: 25,
height: 25,
child: FloatingActionButton(
onPressed: () {},
backgroundColor: Colors.lightGreen,
child: null),
),
),
]),
],
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 0, 270, 10),
child: Text(
"Sizes",
style: TextStyle(
fontSize: 16,
color: Color(0xff262626),
fontWeight: FontWeight.w700),
textAlign: TextAlign.left,
),
),
// SizedBox(
// height: 30,
// ),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.black,
),
),
onPressed: () {
print('XS');
},
child: Text('XS'),
),
TextButton(
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.black,
),
),
onPressed: () {
print('X');
},
child: Text('S'),
),
TextButton(
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.black,
),
),
onPressed: () {
print('M');
},
child: Text('M'),
),
TextButton(
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.black,
),
),
onPressed: () {
print('L');
},
child: Text('L'),
),
TextButton(
style: TextButton.styleFrom(
side: BorderSide(
color: Colors.black,
),
),
onPressed: () {
print('XL');
},
child: Text('XL'),
),
],
),
SizedBox(
height: 30,
),
Row(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"30% off",
style: TextStyle(
fontSize: 25,
color: Colors.purple,
fontWeight: FontWeight.w700),
),
),
],
),
SizedBox(
height: 30,
),
Row(
children: const [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Rs.2950",
style: TextStyle(
fontSize: 18,
color: Color(0xff8399A9),
fontWeight: FontWeight.w700,
decoration: TextDecoration.lineThrough),
),
),
Text(
"Rs.2750",
style: TextStyle(
fontSize: 24,
color: Color(0xff0DA75F),
fontWeight: FontWeight.w700,
),
),
],
),
],
),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(230, 110, 0, 0),
child: ElevatedButton(
onPressed: () {},
child: const Text(
"Add to Cart ",
),
style: ElevatedButton.styleFrom(
primary: Colors.pinkAccent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
bottomRight: Radius.circular(20),
),
),
padding: const EdgeInsets.all(28),
),
),
),
],
),
],
),
);
}
}
home_page.dart
import 'package:flutter/material.dart';
import 'package:fashion_app/details_screen.dart';
import 'package:flutter/services.dart';
class HomePage extends StatefulWidget {
#override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
//final double _borderRadious = 24;
#override
#override
void initState() {
// TODO: implement initState
super.initState();
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []);
}
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.pinkAccent,
),
body: ListView(
padding: const EdgeInsets.only(top: 40, left: 20, right: 20),
children: [
HelloText(),
Name(),
SizedBox(
height: 10,
),
buildSearchInput(),
SizedBox(
height: 10,
),
Stack(children: [
Padding(
padding: const EdgeInsets.fromLTRB(10, 45, 10, 0),
child: TextButton(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Colors.red.shade50,
),
height: 137,
width: 327,
child: Column(
children: const [
Padding(
padding: const EdgeInsets.fromLTRB(20, 40, 100, 40),
child: Text(
"Summer Collections",
style: TextStyle(
fontSize: 24,
color: Color(0xff262626),
fontWeight: FontWeight.w700),
textAlign: TextAlign.justify,
),
),
],
)),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DetailsScreen()));
},
),
),
const Padding(
padding: EdgeInsets.fromLTRB(200, 0, 10, 0),
child: Image(
image: AssetImage("assets/images/dressone.png"),
),
),
]),
Stack(children: [
Padding(
padding: const EdgeInsets.fromLTRB(10, 45, 10, 0),
child: TextButton(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Colors.red.shade50,
),
height: 137,
width: 327,
child: Column(
children: const [
Padding(
padding: const EdgeInsets.fromLTRB(20, 40, 100, 40),
child: Text(
"Winter Collections",
style: TextStyle(
fontSize: 24,
color: Color(0xff262626),
fontWeight: FontWeight.w700),
textAlign: TextAlign.justify,
),
),
],
)),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const DetailsScreen()));
},
),
),
const Padding(
padding: EdgeInsets.fromLTRB(200, 0, 10, 0),
child: Image(
image: AssetImage("assets/images/dresstwo.png"),
),
),
]),
Stack(children: [
Padding(
padding: const EdgeInsets.fromLTRB(5, 20, 10, 0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0),
color: Colors.blue.shade50,
),
height: 137,
width: 327,
child: Row(
children: const [
Padding(
padding: EdgeInsets.fromLTRB(150, 40, 0, 40),
child: Text(
"Get",
style: TextStyle(
fontSize: 24,
color: Colors.black,
fontWeight: FontWeight.w700),
),
),
Padding(
padding: EdgeInsets.all(5.0),
child: Text(
"30%",
style: TextStyle(
fontSize: 24,
color: Colors.purple,
fontWeight: FontWeight.w700),
),
),
Text(
"Off",
style: TextStyle(
fontSize: 24,
color: Colors.black,
fontWeight: FontWeight.w700),
),
],
)),
),
const Padding(
padding: EdgeInsets.fromLTRB(15, 0, 10, 0),
child: Image(
image: AssetImage("assets/images/dressthree.png"),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(230, 110, 0, 40),
child: ElevatedButton(
onPressed: () {},
child: const Text(
"Know More",
),
style: ElevatedButton.styleFrom(
primary: Colors.black,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
bottomRight: Radius.circular(20))),
padding: const EdgeInsets.all(15)),
),
),
]),
],
),
);
}
Widget HelloText() => Container(
child: Row(children: [
Text(
'Hello,',
style: TextStyle(
fontSize: 28,
color: Colors.black,
fontWeight: FontWeight.w500,
),
),
]),
);
Widget Name() => Container(
child: Row(children: [
Text(
'Nirasha',
style: TextStyle(
fontSize: 28,
color: Colors.amber,
fontWeight: FontWeight.w500,
),
),
]),
);
Widget buildSearchInput() => Container(
decoration: BoxDecoration(
color: Colors.grey[300], borderRadius: BorderRadius.circular(20)),
child: Padding(
padding: const EdgeInsets.only(left: 20.0, right: 20),
child: Row(
children: [
Icon(
Icons.search,
size: 30,
color: Colors.grey,
),
Flexible(
child: TextField(
decoration: InputDecoration(border: InputBorder.none),
),
),
],
),
),
);
}
use following Structure in detail_screen.dart scaffold:
body : SafeArea(
child: Column(
children: <Widget>[
Container(child: IconButton(
icon: Icon(
Icons.chevron_left_sharp, //backIcon
color: Colors.indigo,
size: 30,
),
onPressed: () {
Navigator.pop(context);
},
),
-------------------- //other Elements Of body
]
),
)
Please use this : Navigator.of(context).pop();
In your detail_screen.dart, use this code in Appbar leading.
IconButton(
icon: new Icon(
Icons.arrow_back_rounded,
color: Colors.black,
),
onPressed: () => Navigator.pop(context),
),
Used this code now it is working.
leading: IconButton(
icon: new Icon(
Icons.arrow_back_rounded,
color: Colors.black,
),
onPressed: () {Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomePage()));
},
),
In your DetailScreen, your leading widget should be IconButton and handle onpressed event of that IconButton to pop the activity from stack.
Here it is:
leading: IconButton(
icon: new Icon(
Icons.arrow_back_rounded,
color: Colors.black,
),
onPressed: () => Navigator.pop(context),
),

How to write text below the container in row

I have always struggled with making this ui dynamically. Its a row of 4 or can be more than 4 containers with images in it and below that row there is text showing the name of the category made. I currently doing the name part with padding's according to my own device but it slips away in larger or smaller screen size devices other than mine. How can I tackle this. Image is also attached for better understanding if required. Also in the next code named intopage I am trying to stick the please read lines and the terms and conditions, privacy policy to the bottom but it isn't sticking
Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
height: 80,
width: 80,
decoration: BoxDecoration(
color: Colors.black,
border: Border.all(color: Colors.black),
borderRadius:
const BorderRadius.all(Radius.circular(20))),
child: Center(
child: Image.asset("assets/salonicon.png",
scale: 1.2, color: Colors.white),
),
),
Container(
height: 80,
width: 80,
decoration: BoxDecoration(
color: Colors.black,
border: Border.all(color: Colors.black),
borderRadius:
const BorderRadius.all(Radius.circular(20))),
child: Center(
child: Image.asset("assets/hairdresser.png",
scale: 1.2, color: Colors.white),
),
),
Container(
height: 80,
width: 80,
decoration: BoxDecoration(
color: Colors.black,
border: Border.all(color: Colors.black),
borderRadius:
const BorderRadius.all(Radius.circular(20))),
child: Center(
child: Image.asset("assets/facial-massage.png",
scale: 1.2, color: Colors.white),
),
),
Container(
height: 80,
width: 80,
decoration: BoxDecoration(
color: Colors.black,
border: Border.all(color: Colors.black),
borderRadius:
const BorderRadius.all(Radius.circular(20))),
child: Center(
child: Image.asset("assets/body-massage.png",
scale: 1.2, color: Colors.white),
),
),
],
),
const SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.start,
// crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 30.0),
child: Text(
"Salons".toUpperCase(),
textAlign: TextAlign.center,
style: const TextStyle(fontWeight: FontWeight.w600),
),
),
Padding(
padding: const EdgeInsets.only(left: 50.0),
child: Text(
"Hair".toUpperCase(),
textAlign: TextAlign.center,
style: const TextStyle(fontWeight: FontWeight.w600),
),
),
Padding(
padding: const EdgeInsets.only(left: 60.0),
child: Text(
"Skin".toUpperCase(),
textAlign: TextAlign.center,
style: const TextStyle(fontWeight: FontWeight.w600),
),
),
Padding(
padding: const EdgeInsets.only(left: 65.0),
child: Text(
"Body".toUpperCase(),
textAlign: TextAlign.center,
style: const TextStyle(fontWeight: FontWeight.w600),
),
),
],
),
class IntroPage extends StatelessWidget {
const IntroPage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF29F76),
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Stack(
children: <Widget>[
Image.asset(
"assets/intropage.png",
fit: BoxFit.fill,
),
Padding(
padding: const EdgeInsets.only(
top: 550,
),
child: Center(
child: GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const SignUpPage()));
},
child: Container(
width: 180,
height: 60,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.white,
),
borderRadius:
const BorderRadius.all(Radius.circular(40))),
child: const Center(
child: Text(
"Sign Up",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.black),
),
),
),
),
),
),
Padding(
padding: const EdgeInsets.only(
top: 650,
),
child: Center(
child: GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const SignInPage()));
},
child: Container(
width: 180,
height: 60,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: Colors.white,
),
borderRadius:
const BorderRadius.all(Radius.circular(40))),
child: const Center(
child: Text(
"Sign In",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Color(0xFFFE6B01)),
),
),
),
),
),
),
Padding(
padding: const EdgeInsets.only(
top: 750,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
height: 2,
width: 150,
color: Colors.white,
),
const Text(
" Please Read ",
style: TextStyle(color: Colors.white),
),
Container(
height: 2,
width: 150,
color: Colors.white,
),
],
),
),
Padding(
padding: const EdgeInsets.only(
top: 760,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 20, top: 6),
child: GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
TermsandConditions()));
},
child: const Text(
"Terms & Conditions",
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.underline),
),
),
),
Padding(
padding: const EdgeInsets.only(right: 20, top: 6),
child: GestureDetector(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PrivacyPolicy()));
},
child: const Text(
"Privacy Policy",
style: TextStyle(
color: Colors.white,
decoration: TextDecoration.underline),
),
),
),
],
),
),
],
)
],
),
),
);
}
}
Use row then columns to specify them according to your needs it took me 3 minutes to change your code according to your needs super easy just practice a couple of times and you won' forget it.
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
children: <Widget>[
Container(
height: 100.0,
width: 100.0,
decoration: BoxDecoration(
image: const DecorationImage(
image: AssetImage('assets/rnpic.png'),
fit: BoxFit.fill,
),
border: Border.all(color: Colors.black),
borderRadius:
const BorderRadius.all(Radius.circular(20))),
child: Stack(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(),
child: Align(
alignment: Alignment.topRight,
child: Container(
width: 70,
height: 30,
decoration: BoxDecoration(
color: const Color(0xFFFF6D00),
border: Border.all(
color: const Color(0xFFFF6D00)),
borderRadius: const BorderRadius.only(
topRight: Radius.circular(20.0),
)),
child: const Center(
child: Text(
"-50% OFF",
style: TextStyle(color: Colors.white),
),
),
),
),
)
],
),
),
],
),
const SizedBox(
width: 150,
child: Center(
child: Text(
"Colorado Salon special hairstyle",
style:
TextStyle(fontWeight: FontWeight.w500, fontSize: 16),
),
),
),
Container(
width: 80,
height: 30,
decoration: const BoxDecoration(
color: Color(0xFFFF6D00),
borderRadius: BorderRadius.all(Radius.circular(20))),
child: Center(
child: Text(
"View".toUpperCase(),
style: const TextStyle(
fontWeight: FontWeight.w600, color: Colors.white),
),
),
),
],
)
],
),
Make the layout like this
Row(
mainAxisAlignment : MainAxisAlignment.spaceBetween,
children:[
//item 1
Column(
children:[
Icon(),
Text(),
]
),
//item 2
Column(
children:[
Icon(),
Text(),
]
),
//item 3
Column(
children:[
Icon(),
Text(),
]
)
]
)

How to increase button height

i am trying to change the height of two buttons as you can see on the very bottom of the screen. I placed them in a row since i need the side by side and placed that row in a sized box so i can set the width and height for the buttons to fill.
They fill up the width but whenever i try to change the height it keeps giving a render layout error. Does the "Expanded" widget not work for height?
import 'package:/styles/style.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class RelationshipPreferences extends StatelessWidget {
const RelationshipPreferences({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
double height = MediaQuery.of(context).size.height;
return Scaffold(
backgroundColor: Colors.transparent,
body: SizedBox(
width: width,
height: height,
child: Stack(
children: [
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomLeft,
colors: [Color(0xFF1F1F1F), Color(0xFF1F1F1F)],
),
image: DecorationImage(
image: AssetImage("lib/assets/images/topbig.png"),
alignment: Alignment.topCenter,
),
),
),
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('lib/assets/images/toptop.png'),
alignment: Alignment.topCenter,
),
),
),
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('lib/assets/images/top.png'),
alignment: Alignment.topCenter,
),
),
),
Positioned(
top: 70.0,
left: 30.0,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: [
InkWell(
onTap: () {},
child: Container(
decoration: BoxDecoration(),
child: ClipRRect(
// borderRadius: BorderRadius.circular(10.0),
child: Image.asset('lib/assets/images/bluetick.png',
width: 40.0, height: 40.0),
),
),
),
Text(
"━━━━━",
style: TextStyle(color: kcPrimaryColor),
),
InkWell(
onTap: () {},
child: Container(
decoration: BoxDecoration(),
child: ClipRRect(
// borderRadius: BorderRadius.circular(10.0),
child: Image.asset('lib/assets/images/purplewatch.png',
width: 40.0, height: 40.0),
),
),
),
Text(
"━━━━━",
style: TextStyle(color: kcMediumGreyColor),
),
InkWell(
onTap: () {},
child: Container(
decoration: BoxDecoration(),
child: ClipRRect(
// borderRadius: BorderRadius.circular(10.0),
child: Image.asset('lib/assets/images/numba3.png',
width: 40.0, height: 40.0),
),
),
),
Text(
"━━━━━",
style: TextStyle(color: kcMediumGreyColor),
),
InkWell(
onTap: () {},
child: Container(
decoration: BoxDecoration(),
child: ClipRRect(
// borderRadius: BorderRadius.circular(10.0),
child: Image.asset('lib/assets/images/numba4.png',
width: 40.0, height: 40.0),
),
),
),
],
),
),
Positioned(
top: 130.0,
left: 25.0,
child: Row(
children: [
Text(
"Profile",
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
),
),
SizedBox(
width: 40,
),
Text(
"Relationship",
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
),
),
SizedBox(
width: 40,
),
Text(
"animals",
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
),
),
SizedBox(
width: 40,
),
Text(
"Profile Pic",
style: TextStyle(
color: Colors.white,
fontSize: 15.0,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
),
)
],
)),
Positioned(
top: 200,
right: 60,
child: Align(
alignment: Alignment.center,
child: Text(
'Choose Your Relationship Status',
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.bold,
fontFamily: 'Montserrat',
),
),
),
),
Positioned(
top: 240,
right: 40,
child: Align(
alignment: Alignment.center,
child: SizedBox(
child: Center(
child: Text(
'You can change this afterwards if you get lucky',
style: ktsMediumGreyBodyText,
),
),
),
),
),
Positioned(
top: 270,
right: 180,
child: Align(
alignment: Alignment.center,
child: SizedBox(
child: Center(
child: Text(
'...or unlucky!',
style: ktsMediumGreyBodyText,
),
),
),
),
),
Positioned(
bottom: 50,
child: SizedBox(
width: width,
height: 90,
child: Row(
children: [
Expanded(
child: TextButton(
onPressed: () {},
child: Text("Back"),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
Colors.transparent),
foregroundColor: MaterialStateProperty.all<Color>(
kcPrimaryColor)),
),
),
Expanded(
child: TextButton(
onPressed: () {},
child: Text("Next"),
),
),
],
),
),
),
],
),
),
);
}
}
Code i am talking about within the file:
Positioned(
bottom: 50,
child: SizedBox(
width: width,
height: 90,
child: Row(
children: [
Expanded(
child: TextButton(
onPressed: () {},
child: Text("Back"),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
Colors.transparent),
foregroundColor: MaterialStateProperty.all<Color>(
kcPrimaryColor)),
),
),
Expanded(
child: TextButton(
onPressed: () {},
child: Text("Next"),
),
),
],
),
),
),
Instead of using SizedBox in Row i used SizedBox for each of the two buttons and that sorted the issue, here is the code:
Positioned(
bottom: 50,
child: Row(
children: [
SizedBox(
height: 60,
width: width / 2,
child: TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => MusicPreferences()),
);
},
child: Text("Back"),
style: ButtonStyle(
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
),
),
backgroundColor: MaterialStateProperty.all<Color>(
Colors.transparent),
foregroundColor:
MaterialStateProperty.all<Color>(kcPrimaryColor)),
),
),
SizedBox(
height: 60,
width: width / 2,
child: TextButton(
style: ButtonStyle(
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(18.0),
),
),
backgroundColor:
MaterialStateProperty.all<Color>(kcPrimaryColor),
foregroundColor:
MaterialStateProperty.all<Color>(Colors.white)),
onPressed: () {},
child: Text("Done"),
),
),
],
),
),

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.

Flutter wrap text inside nested Widgets

My Text widget is not wrapping, causing an overflow. I've tried methods from this post, but appear to be missing the right spot to add in a flex/expanded.
The spot where it says "//get this text to wrap" is the Text widget I'd like to wrap.
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Text(snapshot.data[index].message_text, //get this text to wrap
style: TextStyle(
color: Colors.grey,
fontSize: 15.0,
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.visible,
),
),
Full Code:
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(title: Text("Comments")),
body: Container(
child: Column(
children: <Widget>[
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30.0),
topRight: Radius.circular(30.0),
),
),
child: ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30.0),
topRight: Radius.circular(30.0),
),
child: new RefreshIndicator(
child:
Container(
child: FutureBuilder(
future: getAllCommentsForAd(this.ad_id_passed_in),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Container(
child: Center(
child: Text("Loading..."),
)
);
} else {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
// return ListTile(
// leading: CircleAvatar(
// radius: 35.0,
// backgroundImage: new NetworkImage(snapshot.data[index].imageUrl),
// ),
// title: Text(snapshot.data[index].email),
// );
return GestureDetector(
onTap: () => (
print("tapped that")
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (_) => MessageScreenRoom(
// snapshot.data[index],this.logged_in_user_id
// ),
// ),
// )
),
child: Container(
margin: EdgeInsets.only(
top: 5.0,
bottom: 5.0,
right: 1.0,
left: 10.0,
),
padding:
EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
decoration: BoxDecoration(
color: snapshot.data[index].hearted ? Colors.lime[50] : Colors.white,
borderRadius: BorderRadius.only(
topRight: Radius.circular(20.0),
bottomRight: Radius.circular(20.0),
topLeft: Radius.circular(20.0),
bottomLeft: Radius.circular(20.0),
)),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Expanded(
child: Row(
children: <Widget>[
CircleAvatar(
radius: 35.0,
backgroundImage: new NetworkImage(snapshot.data[index].imageUrl),
),
SizedBox(
width: 10.0,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(snapshot.data[index].user_name,
style: TextStyle(
color: Colors.grey,
fontSize: 15.0,
fontWeight: FontWeight.bold,
)),
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Text(snapshot.data[index].message_text, //get this text to wrap
style: TextStyle(
color: Colors.grey,
fontSize: 15.0,
fontWeight: FontWeight.bold,
)),
),
SizedBox(
height: 10.0,
),
Container(
width: MediaQuery.of(context).size.width * 0.45,
child: Text(
"",
style: TextStyle(
color: Colors.blueGrey,
fontSize: 15.0,
fontWeight: FontWeight.w600,
),
overflow: TextOverflow.ellipsis,
),
)
],
),
],
),
),
Column(
children: <Widget>[
Text("",
style: TextStyle(
color: Colors.grey,
fontSize: 15.0,
fontWeight: FontWeight.bold)),
SizedBox(
height: 5.0,
),
snapshot.data[index].hearted
? Container(
width: 40.0,
height: 20.0,
alignment: Alignment.center,
child: Icon(Icons.favorite, color: Colors.red, size: 30),
)
: Icon(Icons.favorite_border, color: Colors.red, size: 30),
],
),
],
),
),
);
},
);
}
}
),
),
onRefresh: refreshMessages,
),
),
),
),
// _buildMessageComposer(),
Row(
children: <Widget>[
Expanded(child: TextField(
textCapitalization: TextCapitalization.sentences,
controller: text_message_controller,
onChanged: (value){
},
decoration: InputDecoration.collapsed(hintText: ' Leave a comment...'),
)),
IconButton(
icon: Icon(Icons.send),
iconSize: 30.0,
color: Theme.of(context).primaryColor,
onPressed: () {
//send comment TODO: do this comment send
sendComment(ad_id_passed_in, this.logged_in_user_id, text_message_controller.text);
text_message_controller.clear();
setState(() {
});
})
],
),
],
),
),
);
}
try wrapping your text with Flexible widget