I am new in flutter and I try to make scrollable UI.
I try to add Expanded widgets, ListViews Widgets , SingleChildScrollView widgets but didn't get the expected result.
Also, I try to wrap the stack inside Container and then inside SingleChildScrollView. But it throws error.
I tried many aspects to make my homepage scrollable. But, I got errors (Mentioned below)
I/flutter ( 6259): Another exception was thrown: RenderBox was not laid out: RenderSemanticsGestureHandler#e1279 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 6259): Another exception was thrown: RenderBox was not laid out: _RenderColoredBox#89cc6 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 6259): Another exception was thrown: RenderBox was not laid out: RenderRepaintBoundary#9505f NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
I/flutter ( 6259): Another exception was thrown: 'package:flutter/src/rendering/sliver_multi_box_adaptor.dart': Failed assertion: line 549 pos 12: 'child.hasSize': is not true.
GestureDetector(
onTap: () {
FocusScope.of(context).unfocus();
new TextEditingController().clear();
},
child: Stack(
children: <Widget>[
Container(
height: 200,
child: TopBar(),
),
Container(
margin: EdgeInsets.only(top: 55),
child: Text(
"PriceTrackers",
style: TextStyle(
color: Colors.white,
fontSize: 50.0,
fontWeight: FontWeight.w900,
),
),
),
Container(
margin: EdgeInsets.fromLTRB(265, 0, 0, 0),
child: Text(
".",
style: TextStyle(
fontSize: 120,
color: Colors.white,
),
)),
ListView(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 200),
child: Form(
key: _formKey,
child: Column(children: <Widget>[
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(Icons.store),
Text(
"Supported Store",
style: TextStyle(
fontSize: 20,
color: Colors.green,
),
),
Image.asset(
"Assets/img/amazon.png",
width: 20,
),
Image.asset(
"Assets/img/flipkart.png",
width: 20,
),
Image.asset(
"Assets/img/ajio.png",
width: 20,
),
Image.asset(
"Assets/img/snapdeal.png",
width: 20,
),
Image.asset(
"Assets/img/ss.jpg",
width: 20,
),
],
),
margin: EdgeInsets.fromLTRB(40, 10, 40, 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
// boxShadow: [
// BoxShadow(color: Colors.white, spreadRadius: 3),
// ],
),
),
// Add TextFormFields and RaisedButton here.
TextFormField(
controller: _controller,
enableInteractiveSelection: true,
textInputAction: TextInputAction.done,
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.green),
borderRadius: BorderRadius.circular(20),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.black),
borderRadius: BorderRadius.circular(20),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
borderRadius: BorderRadius.circular(20),
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.red,
),
borderRadius: BorderRadius.circular(20),
),
hintText: "Enter Product URL",
suffixIcon: Icon(Icons.search),
),
// onFieldSubmitted: (term){
// FocusScope.of(context).unfocus();
// _controller.clear();
// },
showCursor: true,
autofocus: false,
// The validator receives the text that the user has entered.
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
} else if (!value.contains("amazon") ||
!value.contains("flipkart") ||
!value.contains("myntra")) {
return "Please Enter Supported Store URL";
}
return null;
},
),
RaisedButton.icon(
icon: Icon(
Icons.search,
color: Colors.white,
),
color: Colors.black,
padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
elevation: 20.0,
onPressed: () async {
// Validate returns true if the form is valid, otherwise false.
if (_formKey.currentState.validate()) {
setState(() {
createAlbum(_controller.text).then((value) => {
Navigator.push(
context,
EnterExitRoute(
exitPage: HomePage(),
enterPage: LineChartSample2(
getData: value)))
});
});
Scaffold.of(context).showSnackBar(SnackBar(
content: Text(
'Processing Data',
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.green,
));
// If the form is valid, display a snackbar. In the real world,
// you'd often call a server or save the information in a database.
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) => LineChartSample2()),
// );
}
},
label: Text(
'View Price Graph',
style: TextStyle(
color: Colors.white,
),
),
),
Container(
margin: EdgeInsets.only(top: 20),
width: 380,
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.blue[200],
blurRadius: 25.0, // soften the shadow
spreadRadius: 5.0, //extend the shadow
offset: Offset(
15.0, // Move to right 10 horizontally
15.0, // Move to bottom 10 Vertically
),
)
],
),
child: Row(
children: <Widget>[
Container(
width: 130,
height: 130,
padding: EdgeInsets.fromLTRB(5, 10, 5, 10),
child: FadeInImage(
fit: BoxFit.scaleDown,
// here `bytes` is a Uint8List containing the bytes for the in-memory image
placeholder: AssetImage("Assets/img/bag.png"),
image: NetworkImage(
'https://images-na.ssl-images-amazon.com/images/I/81j14WXbc%2BL._UL1500_.jpg'),
),
),
Expanded(
child: Container(
padding: EdgeInsets.fromLTRB(0, 20, 10, 0),
child: Column(
children: <Widget>[
Text(
"Redux Analogue Blue Dial Men’s &S... ",
maxLines: 2,
softWrap: true,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w400,
color: Colors.black),
),
Container(
margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
child: Column(
children: <Widget>[
OutlineButton.icon(
onPressed: () => {},
icon: Icon(Icons.shopping_basket),
label: Text("But Now #28939")),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text(
"Avg Price : 7,98,374",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w900,
),
),
Text(
"Avg Price :34,43,343",
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w900,
),
)
],
),
Container(
margin: EdgeInsets.all(5),
),
FlatButton.icon(
icon: Icon(Icons.show_chart),
color: Colors.black,
textColor: Colors.white,
disabledColor: Colors.grey,
disabledTextColor: Colors.black,
padding: EdgeInsets.fromLTRB(
20, 5, 20, 5),
splashColor: Colors.blueAccent,
onPressed: () {
/*...*/
},
label: Text(
"Show Price Graph",
style: TextStyle(fontSize: 15.0),
),
)
],
)),
],
),
))
],
),
),
])),
),
],
),
Container(
margin: EdgeInsets.only(top: 650),
child: GridView.count(
primary: false,
padding: const EdgeInsets.all(20),
crossAxisSpacing: 10,
mainAxisSpacing: 10,
crossAxisCount: 2,
children: <Widget>[
Container(
padding: const EdgeInsets.all(8),
child: const Text("He'd have you all unravel at the"),
color: Colors.teal[100],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Heed not the rabble'),
color: Colors.teal[200],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Sound of screams but the'),
color: Colors.teal[300],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Who scream'),
color: Colors.teal[400],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Revolution is coming...'),
color: Colors.teal[500],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Revolution, they...'),
color: Colors.teal[600],
),
],
)),
],
));
You can copy paste run full code below
Step 1: Use LayoutBuilder and ConstrainedBox
return LayoutBuilder(builder: (context, constraints) {
...
child: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: double.infinity),
child: Stack(
Step 2: Change ListView to Column
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Column(
Step 3: GridView use shrinkWrap: true
working demo
full code
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
#override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, constraints) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: GestureDetector(
onTap: () {
FocusScope.of(context).unfocus();
TextEditingController().clear();
},
child: SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: double.infinity),
child: Stack(
children: <Widget>[
Container(
height: 200,
child: Text("TopBar()"),
),
Container(
margin: EdgeInsets.only(top: 55),
child: Text(
"PriceTrackers",
style: TextStyle(
color: Colors.black,
fontSize: 50.0,
fontWeight: FontWeight.w900,
),
),
),
Container(
margin: EdgeInsets.fromLTRB(265, 0, 0, 0),
child: Text(
".",
style: TextStyle(
fontSize: 120,
color: Colors.white,
),
)),
Padding(
padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 200),
child: Form(
//key: _formKey,
child: Column(children: <Widget>[
Container(
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(Icons.store),
Text(
"Supported Store",
style: TextStyle(
fontSize: 20,
color: Colors.green,
),
),
Image.network(
'https://picsum.photos/250?image=9',
width: 20,
),
Image.network(
'https://picsum.photos/250?image=10',
width: 20,
),
Image.network(
'https://picsum.photos/250?image=11',
width: 20,
),
Image.network(
'https://picsum.photos/250?image=12',
width: 20,
),
Image.network(
'https://picsum.photos/250?image=13',
width: 20,
),
],
),
margin: EdgeInsets.fromLTRB(40, 10, 40, 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.white,
// boxShadow: [
// BoxShadow(color: Colors.white, spreadRadius: 3),
// ],
),
),
// Add TextFormFields and RaisedButton here.
TextFormField(
//controller: _controller,
enableInteractiveSelection: true,
textInputAction: TextInputAction.done,
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.green),
borderRadius: BorderRadius.circular(20),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.black),
borderRadius: BorderRadius.circular(20),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.blue),
borderRadius: BorderRadius.circular(20),
),
errorBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.red,
),
borderRadius: BorderRadius.circular(20),
),
hintText: "Enter Product URL",
suffixIcon: Icon(Icons.search),
),
// onFieldSubmitted: (term){
// FocusScope.of(context).unfocus();
// _controller.clear();
// },
showCursor: true,
autofocus: false,
// The validator receives the text that the user has entered.
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
} else if (!value.contains("amazon") ||
!value.contains("flipkart") ||
!value.contains("myntra")) {
return "Please Enter Supported Store URL";
}
return null;
},
),
RaisedButton.icon(
icon: Icon(
Icons.search,
color: Colors.white,
),
color: Colors.black,
padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
elevation: 20.0,
onPressed: () async {
// Validate returns true if the form is valid, otherwise false.
},
label: Text(
'View Price Graph',
style: TextStyle(
color: Colors.white,
),
),
),
Container(
margin: EdgeInsets.only(top: 20),
width: 380,
height: 200,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.blue[200],
blurRadius: 25.0,
// soften the shadow
spreadRadius: 5.0,
//extend the shadow
offset: Offset(
15.0,
// Move to right 10 horizontally
15.0, // Move to bottom 10 Vertically
),
)
],
),
child: Row(
children: <Widget>[
Container(
width: 130,
height: 130,
padding:
EdgeInsets.fromLTRB(5, 10, 5, 10),
child: FadeInImage(
fit: BoxFit.scaleDown,
// here `bytes` is a Uint8List containing the bytes for the in-memory image
placeholder: NetworkImage(
"https://picsum.photos/250?image=9"),
image: NetworkImage(
'https://images-na.ssl-images-amazon.com/images/I/81j14WXbc%2BL._UL1500_.jpg'),
),
),
Expanded(
child: Container(
padding:
EdgeInsets.fromLTRB(0, 20, 10, 0),
child: Column(
children: <Widget>[
Text(
"Redux Analogue Blue Dial Men’s &S... ",
maxLines: 2,
softWrap: true,
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w400,
color: Colors.black),
),
Container(
margin: EdgeInsets.fromLTRB(
0, 10, 0, 0),
child: Column(
children: <Widget>[
OutlineButton.icon(
onPressed: () => {},
icon: Icon(Icons
.shopping_basket),
label: Text(
"But Now #28939")),
Row(
mainAxisAlignment:
MainAxisAlignment
.spaceEvenly,
children: <Widget>[
Text(
"Avg Price : 7,98,374",
style: TextStyle(
fontSize: 10,
fontWeight:
FontWeight.w900,
),
),
Text(
"Avg Price :34,43,343",
style: TextStyle(
fontSize: 10,
fontWeight:
FontWeight.w900,
),
)
],
),
Container(
margin: EdgeInsets.all(5),
),
FlatButton.icon(
icon:
Icon(Icons.show_chart),
color: Colors.black,
textColor: Colors.white,
disabledColor: Colors.grey,
disabledTextColor:
Colors.black,
padding:
EdgeInsets.fromLTRB(
20, 5, 20, 5),
splashColor:
Colors.blueAccent,
onPressed: () {
/*...*/
},
label: Text(
"Show Price Graph",
style: TextStyle(
fontSize: 15.0),
),
)
],
)),
],
),
))
],
),
),
])),
),
],
),
),
Container(
margin: EdgeInsets.only(top: 650),
child: GridView.count(
shrinkWrap: true,
primary: false,
padding: const EdgeInsets.all(20),
crossAxisSpacing: 10,
mainAxisSpacing: 10,
crossAxisCount: 2,
children: <Widget>[
Container(
padding: const EdgeInsets.all(8),
child: const Text(
"He'd have you all unravel at the"),
color: Colors.teal[100],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Heed not the rabble'),
color: Colors.teal[200],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Sound of screams but the'),
color: Colors.teal[300],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Who scream'),
color: Colors.teal[400],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Revolution is coming...'),
color: Colors.teal[500],
),
Container(
padding: const EdgeInsets.all(8),
child: const Text('Revolution, they...'),
color: Colors.teal[600],
),
],
)),
],
),
),
)),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
});
}
}
You need to remove height from container.
SingleChildScrollView(
child: Container(
child: Stack(
children: <Widget>[
])))
Related
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),
),
I just started learning flutter and am trying to build a todo app, the problem I encountered was the widget buildActionSwipeLeft() set as dismissible background goes up rather than left to right after the list item is dismissed although I set the direction of the dismissible from left to right or start to end. Any help would be appreciated.
My code:
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
horizontal: 24.0,
),
color: const Color(0xfff6f6f6f6),
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(bottom: 32.0, top: 32.0),
child: const Text(
"Reminders",
style: TextStyle(
fontSize: 25.0,
fontWeight: FontWeight.bold
),
),
),
Expanded(
child: ListView.builder(
itemCount: todos.length,
physics: const BouncingScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.only(
bottom: 15.0
),
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
elevation: 4,
child: ClipRRect(
clipBehavior: Clip.antiAlias,
child: Dismissible(
background: buildActionSwipeLeft(),
onDismissed: (direction) {
setState(() {
todos.removeAt(index);
_titleController.removeAt(index);
_detailController.removeAt(index);
});
},
direction: DismissDirection.startToEnd,
key: UniqueKey(),
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
vertical: 13.0,
horizontal: 24.0
),
margin: const EdgeInsets.only(
bottom: 20.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextField(
cursorColor: Colors.black,
controller: _titleController[index],
style: const TextStyle(
fontSize: 22.0,
fontWeight: FontWeight.bold
),
decoration: const InputDecoration(
hintText: "Enter a title",
border: InputBorder.none,
),
),
const Divider(
color: Colors.black,
),
Padding(
padding: const EdgeInsets.only(top: 0.0),
child: TextField(
controller: _detailController[index],
style: TextStyle(
fontSize: 20.0,
color: Colors.grey[900],
),
cursorColor: Colors.black,
maxLines: null,
decoration: const InputDecoration(
hintText: "Enter the description",
label: Text("description"),
border: InputBorder.none
),
),
),
],
),
),
),
),
),
);
},
),
)
],
),
Positioned(
bottom: 24.0,
right: 0.0,
child: GestureDetector(
onTap: () {
setState(() {
todos.add('');
_titleController.add(TextEditingController());
_detailController.add(TextEditingController());
});
},
child: Container(
width: 60.0,
height: 60.0,
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.circular(20.0),
),
child: const Icon(Icons.add, color: Colors.white, size: 35.0),
),
),
)
],
),
),
),
);
}
}
Widget buildActionSwipeLeft() => Container(
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(16.0),
color: Colors.redAccent,
),
padding: const EdgeInsets.symmetric(horizontal: 30),
child: const Icon(Icons.delete, color: Colors.white, size: 30),
);
I figured out that this was not an issue as this is the default animation thats played when a list tile wrapped in a dismissible widget is dismissed. And the dismiss direction just determines the direction in which you can swipe the widget and not the direction in which the widget animates after dismissal.
I just started learning flutter and am trying to build a todo app, the problem I encountered was the Dismissible container and the todo list view item have different heights and after trying everything I still couldn't fix it, the next problem was that the todo item would be dismissed from left to right whereas the container would go up. Any help would be much appreciated. My code:
class _HomePageState extends State<HomePage> {
List todos = [];
List<TextEditingController> _titleController = [];
List<TextEditingController> _detailController = [];
#override
void initState() {
super.initState();
todos.add('');
_titleController.add(TextEditingController());
_detailController.add(TextEditingController());
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
horizontal: 24.0,
),
color: const Color(0xfff6f6f6f6),
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(bottom: 32.0, top: 32.0),
child: const Text(
"Reminders",
style: TextStyle(
fontSize: 25.0,
fontWeight: FontWeight.bold
),
),
),
Expanded(
child: ListView.builder(
itemCount: todos.length,
physics: const BouncingScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
return Dismissible(
background: buildActionSwipeLeft(),
onDismissed: (direction) {
setState(() {
todos.removeAt(index);
_titleController.removeAt(index);
_detailController.removeAt(index);
DismissDirection.startToEnd;
});
},
direction: DismissDirection.startToEnd,
key: Key(todos[index]),
child: Padding(
padding: const EdgeInsets.only(
bottom: 15.0
),
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
elevation: 4,
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
vertical: 15.0,
horizontal: 24.0
),
margin: const EdgeInsets.only(
bottom: 20.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextField(
cursorColor: Colors.black,
controller: _titleController[index],
style: const TextStyle(
fontSize: 22.0,
fontWeight: FontWeight.bold
),
decoration: const InputDecoration(
hintText: "Enter a title",
border: InputBorder.none,
),
),
const Divider(
color: Colors.black,
),
Padding(
padding: const EdgeInsets.only(top: 0.0),
child: TextField(
controller: _detailController[index],
style: TextStyle(
fontSize: 20.0,
color: Colors.grey[900],
),
cursorColor: Colors.black,
maxLines: null,
decoration: const InputDecoration(
hintText: "Enter the description",
label: Text("description"),
border: InputBorder.none
),
),
),
],
),
),
),
),
);
},
),
)
],
),
Positioned(
bottom: 24.0,
right: 0.0,
child: GestureDetector(
onTap: () {
setState(() {
todos.add('');
_titleController.add(TextEditingController());
_detailController.add(TextEditingController());
});
},
child: Container(
width: 60.0,
height: 60.0,
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.circular(20.0),
),
child: const Icon(Icons.add, color: Colors.white, size: 35.0),
),
),
)
],
),
),
),
);
}
}
Widget buildActionSwipeLeft() => Container(
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.red,
),
padding: const EdgeInsets.symmetric(horizontal: 30),
child: const Icon(Icons.delete, color: Colors.white, size: 30),
);
class _HomePageState extends State<HomePage> {
List todos = [];
List<TextEditingController> _titleController = [];
List<TextEditingController> _detailController = [];
#override
void initState() {
super.initState();
todos.add('');
_titleController.add(TextEditingController());
_detailController.add(TextEditingController());
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
horizontal: 24.0,
),
color: const Color(0xfff6f6f6f6),
child: Stack(
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.only(bottom: 32.0, top: 32.0),
child: const Text(
"Reminders",
style: TextStyle(
fontSize: 25.0, fontWeight: FontWeight.bold),
),
),
Expanded(
child: ListView.builder(
itemCount: todos.length,
physics: const BouncingScrollPhysics(),
itemBuilder: (BuildContext context, int index) {
return Stack(
clipBehavior: Clip.hardEdge,
children: [
Padding(
padding: const EdgeInsets.only(top:10.0,left: 8.0, right: 8.0),
child: buildActionSwipeLeft(),
),
Dismissible(
onDismissed: (direction) {
setState(() {
todos.removeAt(index);
_titleController.removeAt(index);
_detailController.removeAt(index);
DismissDirection.startToEnd;
});
},
direction: DismissDirection.startToEnd,
key: UniqueKey(),
child: Padding(
padding: const EdgeInsets.only(bottom: 15.0),
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
elevation: 4,
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
vertical: 15.0, horizontal: 24.0),
margin: const EdgeInsets.only(
bottom: 20.0,
),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
TextField(
cursorColor: Colors.black,
controller: _titleController[index],
style: const TextStyle(
fontSize: 22.0,
fontWeight: FontWeight.bold),
decoration: const InputDecoration(
hintText: "Enter a title",
border: InputBorder.none,
),
),
const Divider(
color: Colors.black,
),
Padding(
padding:
const EdgeInsets.only(top: 0.0),
child: TextField(
controller:
_detailController[index],
style: TextStyle(
fontSize: 20.0,
color: Colors.grey[900],
),
cursorColor: Colors.black,
maxLines: null,
decoration: const InputDecoration(
hintText:
"Enter the description",
label: Text("description"),
border: InputBorder.none),
),
),
],
),
),
),
),
)
],
);
},
),
)
],
),
Positioned(
bottom: 24.0,
right: 0.0,
child: GestureDetector(
onTap: () {
setState(() {
todos.add('');
_titleController.add(TextEditingController());
_detailController.add(TextEditingController());
});
},
child: Container(
width: 60.0,
height: 60.0,
decoration: BoxDecoration(
color: Colors.black87,
borderRadius: BorderRadius.circular(20.0),
),
child:
const Icon(Icons.add, color: Colors.white, size: 35.0),
),
),
)
],
),
),
),
);
}
}
Widget buildActionSwipeLeft() => Container(
height: 180,
alignment: Alignment.centerLeft,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.red,
),
padding: const EdgeInsets.only(left: 30),
child: const Icon(Icons.delete, color: Colors.white, size: 30),
);
Achieving this has a disadvantage of loosing a few animation. Will research more:
How to add circular border for dialog box in a flutter?,I tried the below code but I can't able to get the desired output, I already added circular border but it's not working, I need circular border for dialog,Refer the expected output for details, please guide
My code :
`
class CustomDialog extends StatelessWidget {
#override
Widget build(BuildContext context) {
const double padding = 1.0;
return Dialog(
backgroundColor: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(20.0))),
child: Column(mainAxisSize: MainAxisSize.min, children: [
Container(
margin: EdgeInsets.all(1),
width: double.infinity,
child: Text('title',
style: TextStyle(fontSize: 30, color: Colors.white)),
color: Colors.green,
),
Container(
color: Colors.white,
padding: EdgeInsets.all(10),
child: ListView(
shrinkWrap: true,
children: [
Container(
margin: EdgeInsets.only(left: 10, bottom: 10),
height: 30,
child: Text('one',
style: TextStyle(
fontSize: 20,
))),
Container(
margin: EdgeInsets.only(left: 10, bottom: 10),
height: 30,
child: Text('one',
style: TextStyle(
fontSize: 20,
))),
Container(
margin: EdgeInsets.only(left: 10, bottom: 10),
height: 30,
child: Text('one',
style: TextStyle(
fontSize: 20,
))),
],
),
),
Divider(
color: Colors.white,
),
Container(
color: Colors.white,
height: 50,
padding: EdgeInsets.all(5),
alignment: Alignment.centerRight,
child: Text(
'CANCEL',
style: TextStyle(fontSize: 20),
)),
])));
}
}
`
My expectation:
current output:
Just need to add ClipBehavior to Dialog.
import 'package:flutter/material.dart';
class CustomDialog extends StatelessWidget {
#override
Widget build(BuildContext context) {
const double padding = 1.0;
return Dialog(
backgroundColor: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
),
clipBehavior: Clip.antiAlias, // add clipBehavior
child: Column(mainAxisSize: MainAxisSize.min, children: [
Container(
margin: EdgeInsets.all(1),
width: double.infinity,
child: Text('title',
style: TextStyle(fontSize: 30, color: Colors.white)),
color: Colors.green,
),
Container(
color: Colors.white,
padding: EdgeInsets.all(10),
child: ListView(
shrinkWrap: true,
children: [
Container(
margin: EdgeInsets.only(left: 10, bottom: 10),
height: 30,
child: Text('one',
style: TextStyle(
fontSize: 20,
))),
Container(
margin: EdgeInsets.only(left: 10, bottom: 10),
height: 30,
child: Text('one',
style: TextStyle(
fontSize: 20,
))),
Container(
margin: EdgeInsets.only(left: 10, bottom: 10),
height: 30,
child: Text('one',
style: TextStyle(
fontSize: 20,
))),
],
),
),
Divider(
color: Colors.white,
),
Container(
color: Colors.white,
height: 50,
padding: EdgeInsets.all(5),
alignment: Alignment.centerRight,
child: Text(
'CANCEL',
style: TextStyle(fontSize: 20),
)),
]),
);
}
}
The issue was with the Container you used to wrap the other widgets, you can add specific border radius to each container to fix.
I added a demo and code to get what you wanted your output to look like:
class CustomDialog extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15.0),
),
child: Container(
height: 340,
child: Column(
children: [
Container(
height: 60,
width: double.infinity,
padding: EdgeInsets.all(
15.0,
),
decoration: BoxDecoration(
color: Colors.green,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(
15.0,
),
topRight: Radius.circular(
15.0,
),
),
),
child: Text(
'Baby Names',
style: TextStyle(
fontSize: 20,
color: Colors.white,
),
),
),
...List.generate(
5,
(index) => Padding(
padding: const EdgeInsets.all(10.0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'List Names',
style: TextStyle(
fontSize: 18,
),
),
),
),
),
Divider(
color: Colors.grey[200],
thickness: 1.5,
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Align(
alignment: Alignment.centerRight,
child: Text(
'CANCEL',
style: TextStyle(
fontSize: 18,
color: Colors.green,
),
),
),
),
],
),
),
);
}
}
RESULT:
You added RoundedRectangleBorder(),
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
home: MyWidget(),
),
);
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Dialog(
backgroundColor: Colors.green,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
child: Container(
padding: EdgeInsets.only(
top: 10.0,
bottom: 5,
left: 5,
right: 5,
),
margin: EdgeInsets.only(top: 5),
decoration: new BoxDecoration(
color: Colors.white,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(5),
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 10.0,
offset: const Offset(0.0, 10.0),
),
],
),
child: Column(
mainAxisSize: MainAxisSize.min, // To make the card compact
children: <Widget>[
Text(
"Baby",
style: TextStyle(
fontSize: 24.0,
fontWeight: FontWeight.w700,
),
),
Divider(color: Colors.grey,),
SizedBox(height: 16.0),
Text(
"text",
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16.0,
),
),
SizedBox(height: 24.0),
Align(
alignment: Alignment.bottomRight,
child: FlatButton(
onPressed: () {
Navigator.of(context).pop(); // To close the dialog
},
child: Text("buttonText"),
),
),
],
),
),
);
}
}
I have three screens. One has no parameters and the second has two parameters. When I go to the third screen and I press on the back button of Android, returns to the first screen instead of the second.
I've tried manipulate the back button with WillPopScope, but it didn't work. I think the problem is because of second's parameters...
Here the third(ChosenOption) and second(Options2) screens:
import 'dart:async';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cruke_app/ui/options2.dart';
import 'package:flutter/material.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:rating_bar/rating_bar.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:cruke_app/ui/map.dart';
import 'package:flutter/services.dart' show rootBundle;
class ChosenOption extends StatefulWidget {
final String option;
final DocumentSnapshot document;
ChosenOption({Key key, #required this.document, this.option}) : super(key: key);
#override
_ChosenOptionState createState() => _ChosenOptionState();
}
class _ChosenOptionState extends State<ChosenOption> {
Completer<GoogleMapController> _controller = Completer();
GoogleMapController mapController;
String _mapStyle;
static const LatLng _center = const LatLng(45.521563, -122.677433);
#override
void initState() {
super.initState();
rootBundle.loadString('assets/map_style.txt').then((string) {
_mapStyle = string;
});
}
void _onMapCreated(GoogleMapController controller) {
mapController = controller;
mapController.setMapStyle(_mapStyle);
_controller.complete(controller);
}
#override
Widget build(BuildContext context) {
double _rating = 0;
return Scaffold(
body: SingleChildScrollView(
child: Column(
children: <Widget>[
Stack(
children: <Widget>[
CarouselSlider(
height: 200.0,
items: [1,2,3,4,5].map((i) {
return Builder(
builder: (BuildContext context) {
return Container(
width: MediaQuery.of(context).size.width,
margin: EdgeInsets.symmetric(horizontal: 1.0),
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(widget.document["image"]),
fit: BoxFit.cover,
),
),
child: Text('$i', style: TextStyle(fontSize: 16.0),)
);
},
);
}).toList(),
),
],
),
Container(
margin: EdgeInsets.only(top: 20.0, left: 13.0),
child: Row(
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width * 0.8,
child: Text(widget.document["title"],
style: TextStyle(color: Colors.black,
fontSize: 20.0, fontWeight: FontWeight.bold),),
),
Container(
width: MediaQuery.of(context).size.width * 0.15,
child: RawMaterialButton(
onPressed: () {},
child: Icon(
Icons.favorite,
color: Colors.white,
size: 20.0,
),
shape: CircleBorder(),
elevation: 2.0,
fillColor: Colors.red,
padding: EdgeInsets.all(8.0),
),
),
],
),
),
Row(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 13.0),
child: Icon(Icons.star, size: 18.0, color: Colors.black),
),
Container(
margin: EdgeInsets.only(left: 5.0),
child: RatingBar(
onRatingChanged: (rating) => setState(() => widget.document["rating"] == rating),
filledIcon: Icons.star,
emptyIcon: Icons.star_border,
halfFilledIcon: Icons.star_half,
isHalfAllowed: true,
filledColor: Colors.yellow,
emptyColor: Colors.grey,
halfFilledColor: Colors.yellow,
size: 18,
),
),
Container(
margin: EdgeInsets.only(left: 5.0),
child: Text(widget.document["avaliations"].toString()+" | ", style: TextStyle(color: Colors.black, fontSize: 10.0),),
),
Text(widget.document["city"], style: TextStyle(color: Colors.black, fontSize: 10.0),),
],
),
Container(
margin: EdgeInsets.all(13.0),
child: Text(widget.document["text"]),
),
Divider(),
Text("Avaliações", style: TextStyle(fontSize: 20,),),
buildEvaluation(_rating, "images/restaurant.jpg", "Leandro", "Minas Gerais - MG", "6 dias atrás"),
buildEvaluation(_rating, "images/restaurant.jpg", "Leandro", "Minas Gerais - MG", "10 dias atrás"),
buildEvaluation(_rating, "images/restaurant.jpg", "Leandro", "MInas Gerais - MG", "16 dias atrás"),
Stack(
children: <Widget>[
Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 20.0),
child: Text("Avaliar este Restaurante", style: TextStyle(fontSize: 18),),
),
Container(
alignment: Alignment.center,
margin: EdgeInsets.only(top: 10.0),
child: RatingBar(
onRatingChanged: (rating) => setState(() => _rating = rating),
filledIcon: Icons.star,
emptyIcon: Icons.star_border,
halfFilledIcon: Icons.star_half,
isHalfAllowed: true,
filledColor: Colors.yellow,
emptyColor: Colors.black,
halfFilledColor: Colors.yellow,
size: 20,
),
),
Container(
width: 300.0,
margin: EdgeInsets.only(bottom: 50.0),
child: TextField(
decoration: InputDecoration(
suffixIcon: Padding(
padding: EdgeInsetsDirectional.only(end: 12.0),
child: Icon(Icons.send, color: Colors.black),
),
hintText: "Comentar...",
hintStyle: TextStyle(color: Colors.grey, fontSize: 15.0),
fillColor: Colors.white,
),
textAlign: TextAlign.end,
),
),
Container(
margin: EdgeInsets.only(right: 220.0, bottom: 5.0),
child: Text("Local no mapa",
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.black),
),
),
Container(
width: 340.0,
height: 200.0,
margin: EdgeInsets.only(bottom: 10.0),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.grey,
offset: Offset(1.0, 1.0),
blurRadius: 10.0,
),
],
borderRadius: BorderRadius.circular(10.0),
),
child: GoogleMap(
mapType: MapType.normal,
onMapCreated: _onMapCreated,
initialCameraPosition: CameraPosition(
target: _center,
zoom: 18.0,
),
),
),
RaisedButton.icon(
onPressed: (){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => CrukeMap()),
);
},
label: Text(
'TRAÇAR ROTA',
style: TextStyle(fontSize: 13, color: Colors.white, fontWeight: FontWeight.bold),
),
color: Colors.red,
icon: Icon(Icons.directions, color: Colors.white),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(30.0)),
),
Row(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 20.0, top: 40.0),
child: Icon(Icons.place, color: Colors.red, size: 18,),
),
Container(
margin: EdgeInsets.only(left: 10.0, top: 40.0),
child: Text("R. Sete de Setembro, Porto Seguro - BA, 45810-000", style: TextStyle(fontSize: 12.0),),
),
],
),
Row(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 20.0, top: 10.0),
child: Icon(Icons.local_phone, color: Colors.red, size: 18,),
),
Container(
margin: EdgeInsets.only(left: 10.0, top: 10.0),
child: Text("(73)99906-3724", style: TextStyle(fontSize: 12.0),),
),
],
),
Row(
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 20.0, top: 10.0, bottom: 50.0),
child: Icon(Icons.timer, color: Colors.red, size: 18,),
),
Container(
margin: EdgeInsets.only(left: 10.0, top: 10.0, bottom: 50.0),
child: Text("Horário de Funcionamento: 12:00 às 20:00", style: TextStyle(fontSize: 12.0),),
),
],
),
],
),
],
),
],
),
),
);
}
Widget buildEvaluation(double _rating, String image, String name, String location, String time){
return Stack(
children: <Widget>[
Positioned(
child: Row(
children: <Widget>[
Padding(
padding: EdgeInsets.only(left: 20.0, right: 20.0, top: 30.0),
child: Container(
height: 80.0,
width: 80.0,
decoration: BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.fill,
image: ExactAssetImage(image),
),
)),
),
Container(
margin: EdgeInsets.only(left: 20.0),
child: RatingBar(
onRatingChanged: (rating) => setState(() => _rating = rating),
filledIcon: Icons.star,
emptyIcon: Icons.star_border,
halfFilledIcon: Icons.star_half,
isHalfAllowed: true,
filledColor: Colors.yellow,
emptyColor: Colors.grey,
halfFilledColor: Colors.yellow,
size: 20,
),
),
Container(
margin: EdgeInsets.only(left: 10.0),
child: Text(time, style: TextStyle(color: Colors.black, fontSize: 10.0),),
),
],
),
),
Column(
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 110.0, left: 5.0),
child: Text(name),
),
Container(
padding: EdgeInsets.only(top: 5.0, left: 10.0),
child: Text(location),
),
],
),
Container(
margin: EdgeInsets.only(left: 140.0, top: 70.0, bottom: 10.0),
width: 200.0,
child: Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt" +
"ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat." ),
),
],
);
}
}
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:cruke_app/main.dart';
import 'package:flutter/material.dart';
import 'package:rating_bar/rating_bar.dart';
//import 'package:cruke_app/main.dart';
import 'package:cruke_app/ui/chosen_option.dart';
class Options2 extends StatefulWidget {
final String text, city;
Options2({Key key, #required this.text, this.city}) : super(key: key);
#override
_Options2State createState() => _Options2State();
}
class _Options2State extends State<Options2> {
#override
Widget build(BuildContext context) {
TextEditingController controller = new TextEditingController();
return MaterialApp(
home: Scaffold(
body: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
alignment: Alignment.center,
padding: EdgeInsets.only(left: 20.0, right: 20.0),
width: 500,
height: 150,
child: Container(
decoration: BoxDecoration(
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.grey,
offset: Offset(1.0, 1.0),
blurRadius: 5.0,
),
],
color: Colors.white,
borderRadius: BorderRadius.circular(30.0),
),
child: Padding(
padding: EdgeInsets.all(10.0),
child: TextField(
controller: controller,
decoration: InputDecoration(
suffixIcon: Padding(
padding: EdgeInsetsDirectional.only(end: 12.0),
child: Icon(Icons.search),
),
hintText: "Porto Seguro - BA",
hintStyle: TextStyle(color: Colors.grey, fontSize: 15.0),
fillColor: Colors.grey,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(28.0),
borderSide: BorderSide(
width: 5.0,
color: Colors.grey,
),
),
),
),
),
),
),
Text("CATEGORIAS", style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold)),
Container(
padding: EdgeInsets.only(top: 8.0),
child: Row(
children: <Widget>[
Expanded(
child: RawMaterialButton(
onPressed: () {
if(controller.text != null){
if(testData("tours", controller.text)){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Options2(text: "tours", city: controller.text),
),
);
}
}
},
child: Icon(
Icons.restaurant,
color: Colors.white,
size: 30.0,
),
shape: CircleBorder(),
elevation: 2.0,
fillColor: Colors.red,
padding: EdgeInsets.all(8.0),
),
),
Expanded(
child: RawMaterialButton(
onPressed: () {
if(controller.text != null){
if(testData("restaurant", controller.text)){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Options2(text: "restaurant", city: controller.text),
),
);
}
}
},
child: Icon(
Icons.restaurant,
color: Colors.white,
size: 30.0,
),
shape: CircleBorder(),
elevation: 2.0,
fillColor: Colors.red,
padding: EdgeInsets.all(8.0),
),
),
Expanded(
child: RawMaterialButton(
onPressed: () {
if(controller.text != null){
if(testData("amusement", controller.text)){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Options2(text: "amusement", city: controller.text),
),
);
}
}
},
child: Icon(
Icons.restaurant,
color: Colors.white,
size: 30.0,
),
shape: CircleBorder(),
elevation: 2.0,
fillColor: Colors.red,
padding: EdgeInsets.all(8.0),
),
),
Expanded(
child: RawMaterialButton(
onPressed: () {
if(controller.text != null){
if(testData("tourism", controller.text)){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Options2(text: "tourism", city: controller.text),
),
);
}
}
},
child: Icon(
Icons.restaurant,
color: Colors.white,
size: 30.0,
),
shape: CircleBorder(),
elevation: 2.0,
fillColor: Colors.red,
padding: EdgeInsets.all(8.0),
),
),
],
),
),
Row(
children: <Widget>[
Expanded(
child: Padding(
padding: EdgeInsets.only(left: 18.0),
child: Text("Passeios"),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.only(left: 3.0),
child: Text("Restaurantes"),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.only(left: 14.0),
child: Text("Diversões"),
),
),
Expanded(
child: Padding(
padding: EdgeInsets.only(left: 18.0),
child: Text("Turismo"),
),
),
],
),
Container(
padding: EdgeInsets.all(10.0),
width: double.infinity,
child: Container(
decoration: BoxDecoration(
color: Colors.white,
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.grey,
offset: Offset(1.0, 1.0),
blurRadius: 10.0,
),
],
borderRadius: BorderRadius.circular(10.0),
),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(15.0),
child: Text("Sugestões", style: TextStyle(color: Colors.black)),
),
Container(
child: FutureBuilder<QuerySnapshot>(
future: Firestore.instance.collection(widget.text).where("city", isEqualTo: widget.city).getDocuments(),
builder: (context, snapshot){
if(!snapshot.hasData){
return Center(child: CircularProgressIndicator());
}else{
return snapshot.data.documents.isEmpty ? Center(child: Text("Sua busca não foi encontrada!")) : ListView.builder(
physics: const NeverScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index){
return buildCard(context, snapshot.data.documents[index], widget.text);
},
);
}
},
),
),
],
),
),
),
],
),
),
),
);
}
bool testData(String collection, String city){
try{
var data = Firestore.instance.collection(collection).where("city", isEqualTo: city).snapshots();
if(data != null){
return true;
}
}catch(error){
return false;
}
}
Widget buildCard(BuildContext context, DocumentSnapshot document, String collection){
return Material(
child: InkWell(
onTap: (){
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ChosenOption(document: document, option: collection),
),
);
},
child: Container(
padding: EdgeInsets.only(top: 127.0),
margin: EdgeInsets.only(right: 10.0, left: 10.0, bottom: 15.0),
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(document['image']),
fit: BoxFit.cover,
),
borderRadius: BorderRadius.circular(10.0),
),
width: double.infinity,
height: 200.0,
child: Column(
children: <Widget>[
Container(
alignment: Alignment.topLeft,
padding: EdgeInsets.only(left: 5.0),
child: Text(document['title'],
style: TextStyle(
fontSize: 16.0,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
Row(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 5.0),
child: Icon(Icons.star, size: 18.0, color: Colors.white),
),
Container(
padding: EdgeInsets.only(left: 5.0, right: 5.0),
child: RatingBar(
onRatingChanged: (rating) => setState(() => rating = document['rating']),
filledIcon: Icons.star,
emptyIcon: Icons.star_border,
halfFilledIcon: Icons.star_half,
isHalfAllowed: true,
filledColor: Colors.yellow,
emptyColor: Colors.grey,
halfFilledColor: Colors.yellow,
size: 18,
),
),
Container(
child: Text(document['avaliations'].toString(), style: TextStyle(color: Colors.white, fontSize: 9.0),),
),
Container(
child: Text(" | " + document['city'], style: TextStyle(color: Colors.white, fontSize: 9.0),),
),
],
),
Container(
height: 36.0,
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.grey,
offset: Offset(1.0, 1.0),
blurRadius: 10.0,
),
],
borderRadius: BorderRadius.only(
topLeft: Radius.zero, topRight: Radius.zero,
bottomLeft: Radius.circular(10.0), bottomRight: Radius.circular(10.0)),
),
child: Padding(
padding: EdgeInsets.all(5.0),
child: Text(document['text'],
style: TextStyle(fontSize: 10.0),),
),
),
],
),
),
),
);
}
}
please use package back_button_interceptor https://pub.dev/packages/back_button_interceptor
In simple cases, when you need to intercept the Android back-button, you usually add WillPopScope to your widget tree. However, when developing stateful widgets that interact with the back button, it's more convenient to use the BackButtonInterceptor
example usage
#override
void initState() {
super.initState();
BackButtonInterceptor.add(myInterceptor);
}
#override
void dispose() {
BackButtonInterceptor.remove(myInterceptor);
super.dispose();
}
bool myInterceptor(bool stopDefaultButtonEvent) {
print("BACK BUTTON!"); // Do some stuff.
return true;
}
similar question How to deactivate or override the Android "BACK" button, in Flutter?