Black Screen when I click on Navigator.pop() - flutter

So I have this app I want it to open a new page when I click on a button. It was working before when my second page is a stateless widget. But when I changed it to Stateful Widget , and clicked on the button , my entire screen turns black.
Problem :
The Problem (PICTURE)
And here is my code :
class _MainBodyState extends State<MainBody> {
Color lol = Colors.red;
showMsg(msg) {
return ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(msg.toString()),
),
);
}
#override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(10),
child: SingleChildScrollView(
child: Column(
children: [
Text(
"Welcome to",
style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.bold,
),
),
Text(
"I d k what it is tbh",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.grey,
),
),
Divider(
color: Colors.black,
thickness: 1,
),
Padding(
padding: const EdgeInsets.all(10),
child: Card(
semanticContainer: true,
clipBehavior: Clip.antiAliasWithSaveLayer,
child: Container(
child: Image.asset(
'assets/images/3.jpg',
alignment: Alignment.bottomCenter,
fit: BoxFit.cover,
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
elevation: 8,
),
),
Divider(
color: Colors.black,
thickness: 1,
),
Padding(
padding: const EdgeInsets.only(bottom: 10, top: 10),
child: Text(
"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.",
textAlign: TextAlign.justify,
style: TextStyle(
fontSize: 20,
letterSpacing: 1.4,
height: 1.4,
),
),
),
Divider(
color: Colors.black,
thickness: 1,
),
Text(
"Images",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
for (int i = 1; i <= 3; i++)
GestureDetector(
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(10),
child: Card(
semanticContainer: true,
clipBehavior: Clip.antiAliasWithSaveLayer,
child: Container(
width: 200,
height: 200,
color: Colors.accents[i],
child: Image.asset(
"assets/images/$i.jpg",
alignment: Alignment.bottomCenter,
fit: BoxFit.cover,
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
elevation: 5,
),
),
Padding(
padding: const EdgeInsets.only(top: 5, bottom: 5),
child: Center(
child: Text(
i.toString(),
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
),
],
),
),
Divider(
color: Colors.black,
thickness: 1,
),
TextButton(
child: Text(
"CLICK FOR MAGIK",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
onPressed: () {
setState(() {
lol = Color(Random().nextInt(0xffffffff));
});
},
style: TextButton.styleFrom(
backgroundColor: lol,
),
),
TextButton(
child: Text(
"CLICK FOR NEW PAGE",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
onPressed: () {
showMsg("Open new page");
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()), <== The Open Second Page
);
},
style: TextButton.styleFrom(
backgroundColor: Colors.red,
),
),
Divider(
color: Colors.black,
thickness: 1,
),
],
),
),
);
}
}
And This is my Second Screen code :
class SecondRoute extends StatefulWidget {
#override
_SecondRouteState createState() => _SecondRouteState();
}
class _SecondRouteState extends State<SecondRoute> {
#override
Widget build(BuildContext context) {
return Container(
child: SingleChildScrollView(
child: Column(
children: <Widget>[
ElevatedButton(
onPressed: () {
// Navigate back to first route when tapped.
Navigator.pop(context);
},
child: Text('Go back!'),
),
],
),
),
);
}
}
Both of my widget is Stateful ( Before that my second widget was Stateless and it works fine )
Any help is appreciated , thanks !
UPDATE : When I change my second widget back to stateless , It shows black screen and isn't working either

Related

Flutter: I would like to scroll the ListView after the main SingleChildScrollView Scroll end

I have a ListView.builder wrapped with a SingleChildScrollView, and each has its scroll, so when I click at the ListView it only scroll the ListView without Scroll the SingleChildScrollView, and my ListView is dynamic so I can't use physics: const NeverScrollableScrollPhysics() because it disable my ListVeiw.builder
I want to Scroll the main screen which has some widgets and the ListView, builder in the middle and in last has a bottom
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Carrinho",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 18,
fontFamily: 'Inter'),
),
),
body: SingleChildScrollView(
child: Column(
children: [
Stack(
children: <Widget>[
Container(
width: 400,
child: Image.asset('assets/images/cover.jpg'),
),
Center(
child: Column(
children: [
SizedBox(height: 60),
Text(
"MEU CESTO",
textAlign: TextAlign.center,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 30,
fontFamily: 'Inter'),
),
],
),
),
],
),
Container(
height: 80,
padding: const EdgeInsets.all(15),
decoration: BoxDecoration(
color: sGreenColour,
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10),
),
),
child: Container(
child: Column(
children: [
Row(children: [
Text(
"ITENS: ",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 16),
),
Text("$itemsQtd",
style: TextStyle(color: Colors.white, fontSize: 16))
]),
Row(children: [
Text("TOTAL: ",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 18)),
Text("$totalValue MT",
style: TextStyle(color: Colors.white, fontSize: 18))
])
],
),
),
),
Container(
height: MediaQuery.of(context).size.height,
// HERE MY ListView.buider
child: CartProducts(
cart_list: cart_list,
),
),
SizedBox(height: 40),
Container(
width: MediaQuery.of(context).size.width - 30,
child: Row(
children: [
Container(
height: 50,
width: (MediaQuery.of(context).size.width / 2) - 15,
child: ElevatedButton(
onPressed: () {},
child: Text("$totalValue MT",
style: TextStyle(color: sGreenColour)),
style: ButtonStyle(
backgroundColor: MaterialStateProperty.all<Color>(
sGreenLightColour),
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
),
),
),
),
Container(
height: 50,
width: (MediaQuery.of(context).size.width / 2) - 15,
child: ElevatedButton(
onPressed: () {},
child: Text(
"TERMINAR",
style: TextStyle(color: Colors.white),
),
style: ButtonStyle(
shape:
MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
side: BorderSide(color: sGreenColour),
),
),
),
),
)
],
),
),
SizedBox(height: 10),
],
),
));
}
}
and my ListView.builder
class _CartProductsState extends State<CartProducts> {
#override
Widget build(BuildContext context) {
return ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(), // Disable Scroll
itemCount: widget.cart_list.length,
itemBuilder: (BuildContext context, int index) {
return SigleProduct(
name: widget.cart_list[index]["name"],
picture: widget.cart_list[index]["picture"],
price: widget.cart_list[index]["price"],
unit: widget.cart_list[index]["unit"],
);
});
}
}
// THE ELEMENT OF THE GRIDVIEW
class SigleProduct extends StatelessWidget {
SigleProduct({this.name, this.picture, this.price, this.unit})
: super(key: null);
final name;
final picture;
final price;
final unit;
showAlertDialog(BuildContext context, int id) {
// set up the buttons
Widget cancelButton = TextButton(
child: Text("Não"),
onPressed: () {
Navigator.of(context).pop(); // dismiss dialog
},
);
Widget continueButton = TextButton(
child: Text(
"Sim",
style: TextStyle(color: Colors.red),
),
onPressed: () {
Navigator.of(context).pop(); // dismiss dialog
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("Producto Removido!"),
));
},
);
// set up the AlertDialog
AlertDialog alert = AlertDialog(
title: Center(child: Text("Alerta!")),
content: Text("Gostaria de Remover o producto do carrinho?"),
actions: [
cancelButton,
continueButton,
],
);
// show the dialog
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
#override
Widget build(BuildContext context) {
return Container(
child: Card(
elevation: 2,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.zero,
),
child: ListTile(
onTap: () {},
leading: Container(
width: 80,
//color: Colors.amber,
child: Image.asset(picture),
),
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(name,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.black,
fontSize: 14)),
Text("$price MT",
style: TextStyle(
fontWeight: FontWeight.bold,
color: sGreenColour,
fontSize: 14)),
],
),
subtitle: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Unit: $price MT/$unit',
style: TextStyle(color: Colors.black45)),
Text('Qtd: 2/$unit', style: TextStyle(color: Colors.black45)),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Container(
height: 25,
width: 110,
child: ElevatedButton(
onPressed: () {
showAlertDialog(context, 1);
},
child: Text(
"REMOVER",
style: TextStyle(fontSize: 10, color: Colors.white),
),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.red)),
),
),
Container(
height: 25,
width: 110,
child: ElevatedButton(
onPressed: () {},
child: Text("ACTUALIZAR",
style:
TextStyle(fontSize: 10, color: Colors.white))),
),
],
)
],
),
selected: false,
),
),
);
}
}
Please Help

In dialog box how to change container background color when click on it in flutter?

My goal is to achieve the dialog like the below image. I want that when I press the cancel or confirm button in the dialog, the background color of the cancel and confirm buttons should change.
I have designed this dialog the same as but only I am not able to change the cancel or confirm container background color when I click on it. my designed dialog is below here.
Please help me, anyone, how can I achieve this.
class MyHomePage1 extends StatefulWidget {
#override
State createState() {
return MyHomePage1State();
}
}
class MyHomePage1State extends State<MyHomePage1> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: InkWell(
onTap: (){
showDialog(
context: context,
builder: (BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0)), //this right here
child: Container(
height: 200,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.only(left: 20,right: 20),
child: Center(
child: Text(
Strings.confirmation,
style: TextStyle(
color: AppColors.orange.withOpacity(.65),
//fontSize: DeviceSize.width(context) / 26,
fontSize: 24,
fontFamily: "Poppins",
fontWeight: FontWeight.w600,
),
textAlign: TextAlign.center,
),
),
),
Container(
padding: EdgeInsets.only(left: 20,right: 20),
child: Center(
child: Text(
Strings.youAreAboutTO,
style: TextStyle(
color: AppColors.grey30,
//fontSize: DeviceSize.width(context) / 26,
fontSize: 12,
fontFamily: "Gilroy-Bold"),
textAlign: TextAlign.center,
),
),
),
Container(
padding: EdgeInsets.only(left: 20,right: 20),
child: Center(
child: Text(
Strings.add1Stamp,
style: TextStyle(
color: AppColors.grey50,
//fontSize: DeviceSize.width(context) / 26,
fontSize: 12,
fontFamily: "Poppins"),
textAlign: TextAlign.center,
),
),
),
Container(
padding: EdgeInsets.only(left: 20,right: 20),
child: Center(
child: Text(
Strings.redeem1FreeSet,
style: TextStyle(
color: AppColors.grey50,
//fontSize: DeviceSize.width(context) / 26,
fontSize: 12,
fontFamily: "Poppins"),
textAlign: TextAlign.center,
),
),
),
Container(
padding: EdgeInsets.only(left: 25,right: 25,top: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
GestureDetector(
onTap:(){
setState(() {
});
},
child: Container(
alignment: Alignment.center,
//color: AppColors.blueColorNew,
//margin: EdgeInsets.only(bottom: 20),
width: 100,
height: 32,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: AppColors.white,
border: Border.all(color: AppColors.orange)
),
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Text(
"Cancel",
style: TextStyle(
fontFamily: "Gilroy-Bold",
color:AppColors.orange),
),
),
),
),
InkWell(
onTap:(){
setState(() {
});
},
child: Container(
alignment: Alignment.center,
//color: AppColors.blueColorNew,
//margin: EdgeInsets.only(bottom: 20),
width: 100,
height: 32,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
color: AppColors.white,
border: Border.all(color: AppColors.orange,
)
),
child: Padding(
padding: const EdgeInsets.all(5.0),
child: Text(
"Confirm",
style: TextStyle(
fontFamily: "Gilroy-Bold",
color:AppColors.orange),
),
),
),
)
],
),
),
],
),
),
),
);
});
},
child: Container(
height: 50,
width: 100,
color: Colors.orange,
child: Center(
child: Text("Click on",
style: TextStyle(
color: Colors.white
),),
),
),
),
)
);
}
}
You need to use StatefulBuilder to update on dialog.
onTap: () {
showDialog(
context: context,
builder: (BuildContext context) {
bool isCancelBtnTappeed = false;
bool isConfirmBtnTappeed = false;
return StatefulBuilder(
builder: (context, setStateSB) {
return Dialog(
shape: RoundedRectangleBorder(
/// ........
GestureDetector(
onTap: () {
setStateSB(() {
isCancelBtnTappeed = true;
});
},
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(5),
color: isCancelBtnTappeed
? Colors.red
: Colors.white,

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),
),

Flutter: Listview is scrolling on iOS but not on Android

Custom Widget Listview is scrolling properly on iOS devices but not on Andriod devices. I checked on multiple devices, the same result. I'm using the same widget in BottomSheet it works just fine on both platforms. I couldn't figure out what is the issue.
The following is the code:
UI Screen
class OnBoardingScreen extends StatelessWidget {
//
final _dataAssetController = Get.find<DataAsset>();
#override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: Container(
width: double.infinity,
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.cover,
image: AssetImage('images/ss.jpg'),
),
),
child: SafeArea(
child: Padding(
padding: const EdgeInsets.only(left: 15.0, top: 25.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
///---------------------- Title
Text(
'Your',
style: TextStyle(
fontSize: 30.0,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
Text(
'Star Sign?',
style: TextStyle(
fontSize: 45.0,
fontFamily: 'FredokaOne',
letterSpacing: 2.0,
color: _dataAssetController.mainColor,
),
),
SizedBox(height: 15.0),
///---------------------- Zodiac List
ZodiacListWidget(),
],
),
),
),
),
),
);
}
}
Listview Widget
class ZodiacListWidget extends StatelessWidget {
//
final _dataAssetController = Get.find<DataAsset>();
//
final _zodiacController = Get.find<ZodiacApiController>();
#override
Widget build(BuildContext context) {
return Container(
child: ListView.builder(
shrinkWrap: true,
itemCount: _dataAssetController.zodiacList.length,
itemBuilder: (BuildContext context, index) {
return Padding(
padding: EdgeInsets.symmetric(horizontal: 8.0),
child: Card(
color: Colors.grey[800],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: ListTile(
title: Padding(
padding: EdgeInsets.only(left: 16.0),
child: Text(
_dataAssetController.zodiacList[index],
style: TextStyle(
color: Colors.grey[100],
fontSize: 25.0,
fontWeight: FontWeight.bold,
),
),
),
subtitle: Padding(
padding: EdgeInsets.only(left: 15.0),
child: Text(
_dataAssetController.zodiacDateRangeList[index],
style: TextStyle(
color: Colors.grey[500],
fontSize: 18.0,
),
),
),
leading: CircleAvatar(
radius: 20.0,
backgroundColor: Colors.grey[800],
child: SvgPicture.asset(
_dataAssetController.zodiacSVGList[index],
color: _dataAssetController.mainColor,
),
),
trailing: IconButton(
icon: GetBuilder<ZodiacApiController>(
builder: (_zController) => Icon(
Icons.adjust,
size: 25.0,
color: _dataAssetController.zodiacList[index] ==
_zController.zodiacSign
? _dataAssetController.mainColor
: Colors.grey[300],
),
),
onPressed: () {
_zodiacController.changeZodiac(index);
_zodiacController.onBoarding != null
? null
: Get.defaultDialog(
title: '',
titleStyle: TextStyle(
fontSize: 0.0,
),
middleText: _zodiacController.zodiacSign!,
middleTextStyle: TextStyle(
fontSize: 30.0,
fontWeight: FontWeight.bold,
),
textConfirm: 'Confirm',
confirmTextColor: Colors.white,
onConfirm: () {
_zodiacController.onBoarding != null
? null
: _zodiacController.changeOnBoarding();
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => HomeScreen(),
),
);
},
textCancel: 'Back',
cancelTextColor: Colors.blueAccent,
onCancel: () => Navigator.pop(context),
);
},
),
),
),
);
},
),
);
}
}

How do I show data which depends on data from another String in flutter?

I have 2 selection boxes, which show an AlertDialog. The first one shows an listview.builder in the alertdialog with the options of 'Havo' or 'Vwo'. When the user selects Havo , the options 1-5 must be shown in the second alert dialog. When the user selects Vwo, the options 1-6 must be shown in the second alertdialog.
This is my list which holds the data:
(Also holds other data, please ignore)
const LEVELS = [
Level(level: 'Vwo', subjects: [
'Nederlandse taal en literatuur',
'Engelse taal en literatuur',
'Frans',
'Duits',
'Maatschappijleer',
'Culturele en kunstzinnige vorming',
'Lichamelijke opvoeding',
'Grieks',
'Latijn',
'Wiskunde A',
'Wiskunde C',
'Wiskunde B',
'Natuurkunde',
'Scheikunde',
'Biologie',
'Economie',
'Geschiedenis',
'Informatica',
'Bedrijfseconomie',
'Spaans'
], years: [
'1',
'2',
'3',
'4',
'5',
'6'
]),
Level(level: 'Havo', subjects: [
'Nederlands',
'Engels',
'Mens en natuur',
'Mens en maatschappij',
'Kunst en cultuur',
'Bewegen en sport',
'Duits',
'Frans',
], years: [
'1',
'2',
'3',
'4',
'5'
])
];
This is how my code is built up:
import 'package:flutter/material.dart';
import '../../models/studyOptionsModel.dart';
class SetupScreenThreeForm extends StatefulWidget {
#override
_SetupScreenThreeFormState createState() => _SetupScreenThreeFormState();
}
class _SetupScreenThreeFormState extends State<SetupScreenThreeForm> {
final _formKey = GlobalKey<FormState>();
var _isLoginPage = false;
var _schoolLevel = 'Niveau';
var _classYear = 'Klas';
var _bestSubjects = '';
var selectionOptions = LEVELS.toList();
//The alertdialog for setting the level
createAlertDialog(BuildContext context, selectionType) {
return showDialog(
context: context,
builder: (context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
backgroundColor: Color(0xFF7E36EC),
child: ListView.builder(
shrinkWrap: true,
itemCount: selectionOptions.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
InkWell(
onTap: () {
setState(() {
_schoolLevel = selectionOptions[index].level;
print(_schoolLevel);
Navigator.pop(context);
});
},
child: ListTile(
leading: Text(
selectionOptions[index].level,
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
))),
],
),
);
},
));
});
}
#override
Widget build(BuildContext context) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
SizedBox(
height: 20,
),
Container(
width: double.infinity,
height: 50,
child: InkWell(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)),
color: Color(0xFF7E36EC),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
_schoolLevel,
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
),
),
onPressed: () {
createAlertDialog(context, 'level');
},
),
),
),
SizedBox(
height: 20,
),
Container(
width: double.infinity,
height: 50,
child: InkWell(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)),
color: Color(0xFF7E36EC),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
_classYear,
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
),
),
onPressed: () {
createAlertDialog(context, 'years');
},
),
),
),
SizedBox(
height: 20,
),
Container(
width: double.infinity,
height: 50,
child: InkWell(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)),
color: Color(0xFF212121),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Sterkste vakken',
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
),
),
onPressed: () {},
),
),
),
SizedBox(
height: 20,
),
Container(
width: double.infinity,
height: 50,
child: InkWell(
child: RaisedButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25)),
color: Color(0xFF212121),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Minst sterkste vakken',
style: TextStyle(
color: Colors.white,
fontFamily: 'Poppins',
fontWeight: FontWeight.w500,
fontSize: 14),
),
),
onPressed: () {},
),
),
)
],
)
]);
}
}
You will use if statement and if the condition is true do the following:
if (userselection=='Havo'){
LEVELS.length(x) //x is the number of levels you want to show for example for 4 levels x=3
}