Related
How can I resolve this problem?.
The keyboard closes after being opened by clicking on the textfield of the dialogue box..
Actually, I want to set the valid text length to 10, but when I click on the text field, it automatically unfocuse.
I have used a code for doing this has been mentioned below.
import 'dart:ui';
import 'package:bonanza_flutter/Constants/constants.dart';
import 'package:bonanza_flutter/UIs/Dashboard/dashboard.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class AddNewMemberPage extends StatefulWidget {
#override
State<AddNewMemberPage> createState() => _AddNewMemberPageState();
}
class _AddNewMemberPageState extends State<AddNewMemberPage> {
#override
Widget build(BuildContext context) {
return Dialog(
insetPadding: EdgeInsets.all(35),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
elevation: 0.0,
backgroundColor: Colors.transparent,
child: dialogContent(context),
);
}
}
double t4Size = 14;
extension widgetExtension on _AddNewMemberPageState {
dialogContent(BuildContext context) {
GlobalKey<FormState> _formKey = GlobalKey();
TextEditingController addPanController = TextEditingController();
return SingleChildScrollView(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 3.3, sigmaY: 3.3),
child: Dialog(
insetPadding: EdgeInsets.only(top: 30, bottom: 30, left: 20, right: 20),
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
// backgroundColor: skyBlue,
child: Container(
padding: EdgeInsets.only(top: 30, bottom: 30),
decoration: new BoxDecoration(
color: Colors.white,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.black26,
blurRadius: 10.0,
offset: const Offset(0.0, 10.0),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
Text(
"Add New Member",
style: TextStyle(
fontSize: tSize26,
color: skyBlue,
fontWeight: FontWeight.w500),
textAlign: TextAlign.center,
),
Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding:
const EdgeInsets.only(left: 20.0, right: 20, bottom: 4,top: 20),
child: Text(
"PAN Card",
style: TextStyle(
fontSize: tSize14,
color: darkGreyColor,
fontWeight: FontWeight.w500,
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20, bottom: 20),
child: TextFormField(
onChanged: (value) {
if (value.length == 10) {
FocusScope.of(context).unfocus();
}
},
validator: (value) {
if (value!.length == 10) {
return null;
}
return "";
},
maxLength: 10,
textCapitalization: TextCapitalization.characters,
controller: addPanController,
cursorColor: Theme.of(context).cursorColor,
decoration: const InputDecoration(
counterText: "",
hintText: "Enter PAN number",
hintStyle: TextStyle(color: greyColor),
enabledBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: mediumGreyColor, width: 1.7),
),
contentPadding:
EdgeInsets.only(left: 12, right: 12, top: 12),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: mediumGreyColor, width: 1.7),
),
prefixIcon: Icon(
Icons.verified_user_rounded,
color: greyColor,
),
),
),
)
],
),
),
Padding(
padding: const EdgeInsets.all(20.0),
child: Text(
"Note: PAN number should be connected to same phone number by which you currently sign in.",
style: TextStyle(
fontSize: tSize14,
color: greyColor,
),
textAlign: TextAlign.center,
),
),
Padding(
padding: const EdgeInsets.only(
top: 00.0, bottom: 4, left: 30, right: 30),
child: SizedBox(
height: 45,
width: MediaQuery.of(context).size.width,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: skyBlue, shadowColor: Colors.transparent),
onPressed: () {
Navigator.pop(context);
Navigator.push(
context,
(MaterialPageRoute(
builder: (context) => Dashboard())));
},
child: Text(
'Add Member',
style: TextStyle(
fontSize: tSize16,
),
),
),
),
),
],
)),
),
),
);
}
}
this is my on click fuction
showDialog(
useRootNavigator: true,
barrierDismissible: false,
barrierColor: skyBlue.withOpacity(0.4),
context: context,
builder: (BuildContext context) {
return AddNewMemberPage();
});
I discovered an issue with your _formKey.
Use the below code to fix your issue :
class AddNewMemberPage extends StatefulWidget {
const AddNewMemberPage({Key? key}) : super(key: key);
#override
State<AddNewMemberPage> createState() => _AddNewMemberPageState();
}
class _AddNewMemberPageState extends State<AddNewMemberPage> {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
return Dialog(
insetPadding: const EdgeInsets.all(35),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
elevation: 0.0,
backgroundColor: Colors.transparent,
child: dialogContent(
context,
_formKey,
),
);
}
}
double t4Size = 14;
dialogContent(BuildContext context, GlobalKey _key) {
TextEditingController addPanController = TextEditingController();
return SingleChildScrollView(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 3.3, sigmaY: 3.3),
child: Dialog(
insetPadding:
const EdgeInsets.only(top: 30, bottom: 30, left: 20, right: 20),
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
// backgroundColor: skyBlue,
child: Container(
padding: const EdgeInsets.only(top: 30, bottom: 30),
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(10),
boxShadow: const [
BoxShadow(
color: Colors.black26,
blurRadius: 10.0,
offset: Offset(0.0, 10.0),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
const Text(
"Add New Member",
style: TextStyle(fontSize: 10, fontWeight: FontWeight.w500),
textAlign: TextAlign.center,
),
Form(
key: _key,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.only(
left: 20.0, right: 20, bottom: 4, top: 20),
child: Text(
"PAN Card",
style: TextStyle(
fontWeight: FontWeight.w500,
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20, bottom: 20),
child: TextFormField(
onChanged: (value) {
if (value.length == 10) {
FocusScope.of(context).unfocus();
}
},
validator: (value) {
if (value!.length == 10) {
return null;
}
return "";
},
maxLength: 10,
textCapitalization: TextCapitalization.characters,
controller: addPanController,
cursorColor: Theme.of(context).cursorColor,
decoration: const InputDecoration(
counterText: "",
hintText: "Enter PAN number",
hintStyle: TextStyle(color: Colors.red),
contentPadding:
EdgeInsets.only(left: 12, right: 12, top: 12),
prefixIcon: Icon(
Icons.verified_user_rounded,
),
),
),
)
],
),
),
const Padding(
padding: EdgeInsets.all(20.0),
child: Text(
"Note: PAN number should be connected to same phone number by which you currently sign in.",
style: TextStyle(),
textAlign: TextAlign.center,
),
),
Padding(
padding: const EdgeInsets.only(
top: 00.0, bottom: 4, left: 30, right: 30),
child: SizedBox(
height: 45,
width: MediaQuery.of(context).size.width,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
shadowColor: Colors.transparent),
onPressed: () {
Navigator.pop(context);
},
child: const Text(
'Add Member',
style: TextStyle(),
),
),
),
),
],
)),
),
),
);
}
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 create a todo app, but every time a new todo is made the value of the title and the description remains the same for all the todos,
I have tried every method but no difference pls tell me what's wrong with the code and how do I save the value of the title and description for each todo?
My code:
class _HomePageState extends State<HomePage> {
TextEditingController _titleController = TextEditingController();
TextEditingController _detailController = TextEditingController();
List todos = [];
#override
void initState() {
super.initState();
todos.add('');
}
#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(
key: Key(todos[index]),
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(
vertical: 20.0,
horizontal: 24.0
),
margin: const EdgeInsets.only(
bottom: 20.0,
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextField(
cursorColor: Colors.black,
autofocus: true,
controller: _titleController,
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,
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
),
),
),
],
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20.0)
),
),
);
},
),
)
],
),
Positioned(
bottom: 24.0,
right: 0.0,
child: GestureDetector(
onTap: () {
setState(() {
todos.add('');
});
},
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),
),
),
)
],
),
),
),
);
}
}
Hello and welcome to the world of flutter,
like you do for title and detail, every textfield needs it's own TextEditingController. So you could add a list of controllers for title and description.
List<TextEditingController> _titleController = [];
List<TextEditingController> _detailController = [];
and add an entry to both, when you add todo.
todo.add('')
_titleController.add(TextEditingController())
_detailController.add(TextEditingController())
At the TextFields you should reference by index:
...
child: TextField(controller: _detailController[index],
...
This should help with your problem.
I would recommend you to look at some tutorials and try to rebuild them.
Have fun!
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>[
])))
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?