Incorrect use of ParentDataWidget when using TextField - flutter

I get Incorrect use of ParentDataWidget every time I try to type in my TextField or when I move from the signup page to the login page by pressing "You already have an account?" button.
This is the code that I used for the UI
import 'package:flutter/material.dart';
import 'package:tariffo/HomePage.dart';
import 'auth.dart';
import 'LoginPage.dart';
import 'LoginScreen.dart';
import 'package:firebase_auth/firebase_auth.dart';
class SignupPage extends StatefulWidget {
#override
_SignupPageState createState() => _SignupPageState();
}
class _SignupPageState extends State<SignupPage> {
final _formKey = GlobalKey<FormState>();
String email = '';
String password = '';
String error = '';
bool loading = false;
final Authentication authentication = Authentication();
#override
Widget build(BuildContext context) {
Widget _backButton() {
return InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 0, top: 10, bottom: 10),
child: Icon(Icons.keyboard_arrow_left, color: Colors.black),
),
Text('Back',
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500))
],
),
),
);
}
return loading
? Homepage()
: Scaffold(
resizeToAvoidBottomInset: false,
resizeToAvoidBottomPadding: false,
body: Container(
height: 900.0,
width: 500.0,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 50.0),
child: Row(
children: <Widget>[
IconButton(
icon: Icon(Icons.arrow_back_ios, color: Colors.white),
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => LoginScreen()));
},
)
],
),
),
Positioned(top: 40, left: 0, child: _backButton()),
Padding(
padding: const EdgeInsets.only(top: 40.0),
child: RichText(
text: TextSpan(
text: 'Tariffo',
style: TextStyle(
color: Colors.blue,
fontFamily: 'SignPainter',
fontSize: 60),
),
),
),
SizedBox(
height: 400.0,
child: Form(
key: _formKey,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
left: 80.0, right: 80.0, top: 40.0),
child: TextFormField(
validator: (val) =>
val.isEmpty ? 'enter email' : null,
onChanged: (val) {
setState(() => email = val);
},
style: TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: 'enter email',
hintStyle: TextStyle(
fontFamily: 'Antra',
fontSize: 12.0,
color: Colors.black)),
),
),
Padding(
padding: const EdgeInsets.only(
left: 80.0, right: 80.0, top: 40.0),
child: TextFormField(
validator: (val) => val.length < 8
? 'enter password > 8 digits'
: null,
onChanged: (val) {
setState(() => password = val);
},
style: TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: 'enter password',
hintStyle: TextStyle(
fontFamily: 'Antra',
fontSize: 12.0,
color: Colors.black)),
obscureText: true,
),
),
SizedBox(height: 50),
Padding(
padding: const EdgeInsets.only(top: 40.0),
child: MaterialButton(
color: Colors.blue,
onPressed: () async {
if (_formKey.currentState.validate()) {
setState(() => loading = true);
dynamic result = await authentication
.registerwithEmailAndPassword(
email, password);
if (result == null) {
setState(() => error =
'Sorry,These credentials will not work out');
loading = false;
}
}
},
child: Text(
'Sign up',
style: TextStyle(
fontFamily: 'Antra', color: Colors.white),
),
),
),
],
),
)),
_createAccountLabel(),
],
),
),
);
}
Widget _createAccountLabel() {
return InkWell(
onTap: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => LoginPage()));
},
child: Container(
margin: EdgeInsets.symmetric(vertical: 20),
padding: EdgeInsets.all(15),
alignment: Alignment.bottomCenter,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Do you have an account ?',
style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600),
),
SizedBox(
width: 10,
),
Text(
'Login',
style: TextStyle(
color: Colors.blue,
fontSize: 13,
fontWeight: FontWeight.w600),
),
],
),
),
);
}
}
import 'package:flutter/material.dart';
import 'SignUp.dart';
import 'brazierContainer.dart';
import 'package:google_fonts/google_fonts.dart';
import 'LoginScreen.dart';
import 'HomePage.dart';
import 'auth.dart';
class LoginPage extends StatefulWidget {
LoginPage({Key key, this.title}) : super(key: key);
final String title;
#override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
final _formKey = GlobalKey<FormState>();
String email = '';
String password = '';
String error = '';
bool loading = false;
final Authentication authentication = Authentication();
#override
Widget build(BuildContext context) {
Widget _backButton() {
return InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 0, top: 10, bottom: 10),
child: Icon(Icons.keyboard_arrow_left, color: Colors.black),
),
Text('Back',
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500))
],
),
),
);
}
return loading
? Homepage()
: Scaffold(
resizeToAvoidBottomInset: false,
resizeToAvoidBottomPadding: false,
body: Container(
height: 900.0,
width: 500.0,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 50.0),
child: Row(
children: <Widget>[
IconButton(
icon: Icon(Icons.arrow_back_ios, color: Colors.white),
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => LoginScreen()));
},
)
],
),
),
Positioned(top: 40, left: 0, child: _backButton()),
Padding(
padding: const EdgeInsets.only(top: 40.0),
child: RichText(
text: TextSpan(
text: 'Tariffo',
style: TextStyle(
color: Colors.blue,
fontFamily: 'SignPainter',
fontSize: 60),
),
),
),
SizedBox(
height: 400.0,
child: Form(
key: _formKey,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
left: 80.0, right: 80.0, top: 40.0),
child: TextFormField(
validator: (val) =>
val.isEmpty ? 'enter email' : null,
onChanged: (val) {
setState(() => email = val);
},
style: TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: 'enter email',
hintStyle: TextStyle(
fontFamily: 'Antra',
fontSize: 12.0,
color: Colors.black)),
),
),
Padding(
padding: const EdgeInsets.only(
left: 80.0, right: 80.0, top: 40.0),
child: TextFormField(
validator: (val) => val.length < 8
? 'enter password > 8 digits'
: null,
onChanged: (val) {
setState(() => password = val);
},
style: TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: 'enter password',
hintStyle: TextStyle(
fontFamily: 'Antra',
fontSize: 12.0,
color: Colors.black)),
obscureText: true,
),
),
SizedBox(height: 50),
Padding(
padding: const EdgeInsets.only(top: 40.0),
child: MaterialButton(
color: Colors.blue,
onPressed: () async {
if (_formKey.currentState.validate()) {
setState(() => loading = true);
dynamic result = await authentication
.signUpWithEmailAndPassword(
email, password);
if (result == null) {
setState(() => error =
'Sorry,These credentials will not work out');
loading = false;
}
}
},
child: Text(
'Sign in',
style: TextStyle(
fontFamily: 'Antra', color: Colors.white),
),
),
),
Container(
padding: EdgeInsets.symmetric(vertical: 10),
alignment: Alignment.centerRight,
child: Text('Forgot Password ?',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500)),
),
],
),
)),
_createAccountLabel(),
],
),
),
);
}
Widget _createAccountLabel() {
return InkWell(
onTap: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => SignupPage()));
},
child: Container(
margin: EdgeInsets.symmetric(vertical: 20),
padding: EdgeInsets.all(15),
alignment: Alignment.bottomCenter,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Don/t you have an account ?',
style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600),
),
SizedBox(
width: 10,
),
Text(
'Register',
style: TextStyle(
color: Colors.blue,
fontSize: 13,
fontWeight: FontWeight.w600),
),
],
),
),
);
}
}
And this is the error:
════════ Exception caught by widgets library ═══════════════════════════════════
Incorrect use of ParentDataWidget.
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget Positioned(left: 0.0, top: 40.0) wants to apply ParentData of type StackParentData to a RenderObject, which has been set up to accept ParentData of incompatible type FlexParentData.
Usually, this means that the Positioned widget has the wrong ancestor RenderObjectWidget. Typically, Positioned widgets are placed directly inside Stack widgets.
The offending Positioned is currently placed inside a Column widget.

You are using Positioned in a Column. Positioned can only be used in a Stack. So consider replacing your Column with a Stack or use Alignment(x,y) to align it

Related

Flutter: Navigator Push changes position of my Background Image

Two Files:
account_page.dart
& cart_page.dart
I used Navigator.push to embed AccountPage() [from account_page.dart] within CartPage() (inside cart_page.dart). When I check the simulation, the background image widget within the Stack() changes position.
How can I make the NavigationPage identical to the original? Is this a bug?
I've tried many things including wrapping the Container() that holds the image in a Positioned(), SizedBox(), 'alignment: Alignment(x,y)', adding a column that shifts the image down. Most of these end with the picture completely disappearing, I erased parameters to make the image free as possible and then tried again to no avail.
Initially, I used 'alignment: Alignment(0.0, -7.0)' to position the image. However, when the page is called using Navigator, the image alignment changes from a negative to a positive causing the position to move the opposite direction.
The other solutions I've thought of require some photoshop, but I don't want to mess with the image unless I really have to.
I believe it has something to do with the image being in a stack and causing some overflow.
Any suggestions would be helpful.
Code:
account_page.dart
import 'package:email_validator/email_validator.dart';
import 'package:flutter/material.dart';
class AccountPage extends StatefulWidget {
const AccountPage({Key? key}) : super(key: key);
#override
_AccountPageState createState() => _AccountPageState();
}
class _AccountPageState extends State<AccountPage> {
bool _obscureText = true;
bool _passswordVisible = false;
void _toggleObscureText() {
setState(() {
_obscureText = !_obscureText;
_passswordVisible = !_passswordVisible;
});
}
String? get _showHideString {
if (!_passswordVisible) {
return "Show";
} else {
return "Hide";
}
}
#override
Widget build(BuildContext context) {
// create a global key that can provide validation
final _formKey = GlobalKey<FormState>();
return Form(
key: _formKey,
child: Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
foregroundColor: Colors.black,
elevation: 0,
),
body: Stack(
children: [
Container(
//*****************AREA OF PROBLEM**************************
width: MediaQuery.of(context).size.width,
decoration: const BoxDecoration(
color: Colors.white,
image: DecorationImage(
image: AssetImage("images/background.jpeg"),
fit: BoxFit.fitWidth,
//---------sets the position of image------------
alignment: Alignment(0.0, -7.0),
),
),
),
SingleChildScrollView(
child: Column(
children: <Widget>[
const Padding(
padding: EdgeInsets.all(30.0),
child: Text(
"Sign in",
style: TextStyle(
fontFamily: "RaleWay",
fontSize: 30,
fontWeight: FontWeight.bold),
),
),
const Padding(
padding: EdgeInsets.only(left: 20, right: 20, bottom: 30),
child: Text(
"Become a member to enjoy exclusive savings on your favorite items.",
style: TextStyle(
fontSize: 16,
),
textAlign: TextAlign.center,
),
),
Stack(
children: <Widget>[
SingleChildScrollView(
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 10),
child: Column(
children: [
TextFormField(
validator: (value) {
if (EmailValidator.validate(value!)) {
return null;
} else {
return "Please enter a valid Username";
}
},
autocorrect: false,
autofocus: false,
style: const TextStyle(fontSize: 18),
decoration: InputDecoration(
hintText: 'UserName',
border: InputBorder.none,
filled: true,
fillColor: Colors.grey[200],
contentPadding: const EdgeInsets.all(10.0),
),
),
Padding(
padding: const EdgeInsets.symmetric(
vertical: 25,
),
child: Stack(children: <Widget>[
TextFormField(
autocorrect: false,
autofocus: false,
obscureText: _obscureText,
style: const TextStyle(fontSize: 18),
decoration: InputDecoration(
hintText: "Password",
filled: true,
fillColor: Colors.grey[200],
contentPadding:
const EdgeInsets.all(10.0),
),
),
Container(
alignment: Alignment.bottomRight,
child: TextButton(
onPressed: () {
_toggleObscureText();
},
child: Text(_showHideString!),
style: ButtonStyle(
overlayColor:
MaterialStateProperty.all(
Colors.transparent)
// MaterialStateProperty
// .resolveWith<Color?>(
// (Set<MaterialState> states) {
// if (states.contains(
// MaterialState.pressed)) {
// return Theme.of(context)
// .colorScheme
// .primary
// .withOpacity(0);
// }
// }),
),
))
]),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
child: const Text(
"Forgot Password?",
style: TextStyle(
decoration: TextDecoration.underline,
),
),
onPressed: () {},
style: ButtonStyle(
overlayColor:
MaterialStateProperty.all<Color>(
Colors.transparent,
)),
),
],
),
RawMaterialButton(
onPressed: () {
// ignore: todo
// TODO: Checks if username and password is in the system, this will bring to real account page
// if not, replies, please enter a valid username and password
if (_formKey.currentState!.validate()) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text("Submitted!"),
),
);
}
},
constraints:
const BoxConstraints(minWidth: 300),
splashColor: Colors.black12,
fillColor: Colors.black,
padding:
const EdgeInsets.symmetric(vertical: 12),
child: const Text(
"Login",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold),
),
),
],
),
),
),
],
)
],
),
),
],
),
),
);
}
}
cart_page.dart
import 'package:flutter/material.dart';
import 'package:flutter_mobile_sim_test_1/account_page.dart';
class CartPage extends StatefulWidget {
const CartPage({Key? key}) : super(key: key);
#override
_CartPageState createState() => _CartPageState();
}
class _CartPageState extends State<CartPage> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: const Text(
"Your Cart",
style: TextStyle(fontSize: 24, color: Colors.black),
),
elevation: 0,
backgroundColor: Colors.white,
),
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: MediaQuery.of(context).size.width,
height: 100,
alignment: Alignment.center,
padding: const EdgeInsets.all(10.0),
child: const Text(
"Your Shopping Bag is Empty",
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
),
RawMaterialButton(
child: const Text("Sign In",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold)),
//*****************NAVIGATOR PUSH**************************
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const AccountPage()),
);
},
constraints: BoxConstraints(
minWidth: MediaQuery.of(context).size.width,
minHeight: 20),
padding: const EdgeInsets.all(12.0),
fillColor: Colors.black,
),
Stack(
children: [
Padding(
padding: const EdgeInsets.all(10.0),
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: const Divider(
color: Colors.grey,
thickness: 2,
),
),
),
Container(
color: Colors.transparent,
width: (MediaQuery.of(context).size.width),
alignment: Alignment.topCenter,
padding: const EdgeInsets.all(8.0),
child: Container(
color: Colors.white,
width: 40,
child: const Text(
"or",
style: TextStyle(
fontSize: 18,
color: Colors.grey,
),
textAlign: TextAlign.center,
),
),
),
],
),
RawMaterialButton(
onPressed: () {},
child: const Text("Create Account",
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold)),
fillColor: Colors.white,
shape: const ContinuousRectangleBorder(
side: BorderSide(color: Colors.black, width: 2),
),
constraints: BoxConstraints(
minWidth: MediaQuery.of(context).size.width,
minHeight: 20.0),
padding: const EdgeInsets.all(12.0)),
Container(
color: Colors.blue,
width: MediaQuery.of(context).size.width,
height: 200,
alignment: Alignment.center,
padding: const EdgeInsets.all(20.0),
// child: ,
),
const Text(
"hello",
style: TextStyle(fontSize: 50),
textAlign: TextAlign.center,
),
Container(
color: Colors.blue,
width: MediaQuery.of(context).size.width,
height: 200,
alignment: Alignment.center,
padding: const EdgeInsets.all(20.0),
// child: ,
),
],
),
),
));
}
}
Correctly positioned background image(the black infinity)
Incorrectly positioned background image within a NavigatorPage(the black infinity)

how to validate entered password and confirm password are same in flutter

I am trying to validate the values of password field and confirm password field.
how to validate entered password and confirm password are same in flutter.
The edited text value could not be taken as value so couldn't find the solution.
import 'package:flutter/material.dart';
import 'package:form_field_validator/form_field_validator.dart';
import 'package:loginform_validation_demo/LoginFormWithValidation.dart';
import 'validation.dart';
import 'HomePage.dart';
class SignupPage extends StatelessWidget {
GlobalKey<FormState> formkey = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
elevation: 0,
brightness: Brightness.light,
backgroundColor: Colors.white,
leading: IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(
Icons.arrow_back_ios,
size: 20,
color: Colors.black,
)),
),
body: SafeArea(
child: Form(
autovalidateMode: AutovalidateMode.always,
key: formkey,
child: SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height,
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
children: [
Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
SizedBox(
height: 40,
),
Text(
"Sign up",
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
),
),
SizedBox(
height: 20,
),
Text(
"Create an Account,Its free",
style: TextStyle(
fontSize: 15,
color: Colors.grey[700],
),
),
SizedBox(
height: 30,
)
],
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 40),
child: Column(
children: [
usernameMakeInput(label: "User Name"),
passwordMakeInput(label: "Password", obsureText: true),
passwordMakeInput(label: "Confirm Password", obsureText: true)
],
),
),
Padding(
padding: EdgeInsets.symmetric(horizontal: 40),
child: Container(
height: 50,
width: 200,
child: MaterialButton(
minWidth: double.infinity,
height: 50,
onPressed: () {
if (formkey.currentState.validate()) {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => HomePage()));
print("Validated");
} else {
print("Not Validated");
}
},
color: Colors.blue,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
child: Text(
"Sign Up",
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 18,
color: Colors.white),
),
),
),
),
SizedBox(
height: 20,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Already have an account?",
style: TextStyle(fontSize: 15),
),
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
LoginFormValidation()),
);
},
child: Text(
'Login',
style:
TextStyle(color: Colors.blue, fontSize: 18),
),
),
],
)
],
),
],
),
),
),
),
),
);
}
}
validation:
This is the part where I try to pass the edit text value
Widget passwordMakeInput({label, obsureText = false}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: TextStyle(
fontSize: 15, fontWeight: FontWeight.w400, color: Colors.black87),
),
SizedBox(
height: 5,
),
TextFormField(
onChanged: (value){
},
maxLength: 6,
obscureText: obsureText,
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(vertical: 0, horizontal: 10),
border: OutlineInputBorder(),
),
validator: MultiValidator([
RequiredValidator(errorText: "* Required"),
MinLengthValidator(6,
errorText: "Password should contain 6 characters"),
])),
SizedBox(
height: 30,
)
],
);
}

Flutter where i can find the orange thing in this code please

i have this login page
here is the code `import 'package:flutter/material.dart';
import 'package:pharmaciemobile/src/homePage.dart';
import 'package:pharmaciemobile/src/pages/home.dart';
import 'package:pharmaciemobile/src/signup.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'Widget/bezierContainer.dart';
class LoginPage extends StatefulWidget {
LoginPage({Key key, this.title}) : super(key: key);
final String title;
#override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
String _email, _password;
final GlobalKey<FormState> _formKey=GlobalKey<FormState>();
Widget _backButton() {
return InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 0, top: 10, bottom: 10),
child: Icon(Icons.arrow_back_ios, color: Color(0xff48fb51)/*Colors.black*/),
),
/* Text('Back',
style: TextStyle(fontSize: 12, fontWeight: FontWeight.w500))*/
],
),
),
);
}
Widget _divider() {
return Container(
margin: EdgeInsets.symmetric(vertical: 10),
child: Row(
children: <Widget>[
SizedBox(
width: 20,
),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Divider(
thickness: 1,
),
),
),
Text('or'),
Expanded(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Divider(
thickness: 1,
),
),
),
SizedBox(
width: 20,
),
],
),
);
}
Widget _createAccountLabel() {
return InkWell(
onTap: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => SignUpPage()));
},
child: Container(
margin: EdgeInsets.symmetric(vertical: 10),
padding: EdgeInsets.all(15),
alignment: Alignment.bottomCenter,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Don\'t have an account ?',
style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600),
),
SizedBox(
width: 10,
),
Text(
'Register',
style: TextStyle(
color: Color(0xff48fb51),
fontSize: 15,
fontWeight: FontWeight.w600),
),
],
),
),
);
}
Widget _title() {
return RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: 'Geolocalisation',
style: GoogleFonts.portLligatSans(
textStyle: Theme.of(context).textTheme.display1,
fontSize: 25,
fontWeight: FontWeight.w700,
color: Colors.white,
),
children: [
TextSpan(
text: 'des',
style: TextStyle(color: Colors.black, fontSize: 30),
),
TextSpan(
text: 'Pharmacies',
style: TextStyle(color: Colors.white, fontSize: 25),
),
]),
);
}
#override
Widget build(BuildContext context) {
final height = MediaQuery.of(context).size.height;
return Scaffold(
body: Container(
height: height,
child: Stack(
children: <Widget>[
Positioned(
top: -height * .15,
right: -MediaQuery.of(context).size.width * .4,
child: BezierContainer()),
Container(
padding: EdgeInsets.symmetric(horizontal: 20),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
SizedBox(height: height * .2),
_title(),
SizedBox(height: 30),
//_emailPasswordWidget(),
Form(
key : _formKey,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Email',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
),
SizedBox(
height: 10,
),
TextFormField(
validator : (input){
if(input.isEmpty){
return 'Please type an Email';
}
},
onSaved: (input) => _email = input,
decoration: InputDecoration(
border: InputBorder.none,
fillColor: Color(0xfff3f3f4),
filled: true)
),
],
),
),
Container(
margin: EdgeInsets.symmetric(vertical: 10),
child : Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
'Password',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
),
SizedBox(
height: 10,
),
TextFormField(
validator : (input){
if(input.length<6){
return 'Your Password is week';
}
},
onSaved: (input) => _password = input,
obscureText: true,
decoration: InputDecoration(
border: InputBorder.none,
fillColor: Color(0xfff3f3f4),
filled: true)),
SizedBox(height: 20),
],
),
),
RaisedButton(
padding: EdgeInsets.symmetric(vertical: 0),
onPressed: signIn,
child: Container(
width: MediaQuery.of(context).size.width,
padding: EdgeInsets.symmetric(vertical: 15),
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.grey.shade200,
offset: Offset(2, 4),
blurRadius: 5,
spreadRadius: 2)
],
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [Color(0xff48fb51), Color(0xff10d2e4)])),
child: Text(
'se connecter',
style: TextStyle(fontSize: 20, color: Colors.white),
),
) ,
),
],
),
),
Container(
padding: EdgeInsets.symmetric(vertical: 10),
alignment: Alignment.centerRight,
child: Text('Mot de passe oublié',
style: TextStyle(
fontSize: 14, fontWeight: FontWeight.w500)),
),
_divider(),
//_facebookButton(),
//SizedBox(height: height * .055),
_createAccountLabel(),
],
),
),
),
Positioned(top: 40, left: 0, child: _backButton()),
],
),
));
}
Future<void> signIn() async {
final formState = _formKey.currentState;
if(formState.validate()){
formState.save();
try{
AuthResult result = await FirebaseAuth.instance.signInWithEmailAndPassword(email: _email, password: _password);
FirebaseUser user = result.user;
Navigator.push(context, MaterialPageRoute(builder: (context) =>HomePage()));
}catch(e){
print(e.message);
}
}
}
}
**i' am new in flutter i found a project in github , now i want just to delete the orange thing somoene can help me please,i just want to delete the orange thing in the top somone can tell me were i can find it in the code please
**
the orange widget is this
Positioned(
top: -height * .15,
right: -MediaQuery.of(context).size.width * .4,
child: BezierContainer()),
in the future, if you want to inspect flutter widgets i recommend using Flutter inspector
https://flutter.dev/docs/development/tools/devtools/inspector

Expanded textfield strach a lot

and at the signup screen I got some problems when I run my app on the device. This happens with the screen : photo with textfields. What I should change to my code to everything to be in place? The app is made with flutter , should I add a height and width to containers? Or should I erase the Expanded and try something else
class SignupPage extends StatefulWidget {
#override
_SignupPageState createState() => _SignupPageState();
}
class _SignupPageState extends State<SignupPage> {
final _formKey = GlobalKey<FormState>();
String email = '';
String password = '';
String error = '';
String _selectedRole = 'Select a User Role';
String get selectedRole => _selectedRole;
int selectedValue;
String selectedString;
// void setSelectedRole(String role) {
// _selectedRole = role;
// }
bool loading = false;
final Authentication authentication = Authentication();
int selectedIndex1 = 0;
final elements1 = [
"Customer",
"Business",
];
List<Widget> _buildItems1() {
return elements1
.map((val) => MySelectionItem(
title: val,
))
.toList();
}
#override
Widget build(BuildContext context) {
return Scaffold(
// resizeToAvoidBottomInset: false,
// resizeToAvoidBottomPadding: false,
body: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Column(
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 30.0),
child: Row(
children: <Widget>[
IconButton(
icon: Icon(Icons.arrow_back_ios, color: Colors.blue),
onPressed: () {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (context) => LoginScreen()));
},
)
],
),
),
Padding(
padding: const EdgeInsets.only(top: 20.0),
child: RichText(
text: TextSpan(
text: 'Tariffo',
style: TextStyle(
color: Colors.blue,
fontFamily: 'SignPainter',
fontSize: 60),
),
),
),
Expanded(
child: Container(
child: Form(
key: _formKey,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
left: 40.0, right: 40.0, top: 30.0),
child: TextFormField(
validator: (val) => val.isEmpty ? 'enter name' : null,
onChanged: (val) {
setState(() => name = val);
},
style: TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: 'Enter Name',
hintStyle: TextStyle(
fontFamily: 'Antra',
fontSize: 12.0,
color: Colors.black)),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 40.0, right: 40.0, top: 40.0),
child: TextFormField(
validator: (val) =>
val.isEmpty ? 'Enter Email' : null,
onChanged: (val) {
setState(() => email = val);
},
style: TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: 'Enter email',
hintStyle: TextStyle(
fontFamily: 'Antra',
fontSize: 12.0,
color: Colors.black)),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(
left: 40.0, right: 40.0, top: 10.0),
child: TextFormField(
validator: (val) => val.length < 8
? 'enter password > 8 digits'
: null,
onChanged: (val) {
setState(() => password = val);
},
style: TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: 'Enter Password',
hintStyle: TextStyle(
fontFamily: 'Antra',
fontSize: 12.0,
color: Colors.black)),
obscureText: true,
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(vertical:10.0),
child: DirectSelect(
itemExtent: 50.0,
selectedIndex: selectedIndex1,
backgroundColor: Colors.white30,
child: MySelectionItem(
isForList: false,
title: elements1[selectedIndex1],
),
onSelectedItemChanged: (index) {
setState(() {
selectedIndex1 = index;
});
},
items: _buildItems1()),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(vertical:40.0),
child: MaterialButton(
color: Colors.blue,
height: 30,
minWidth: 300,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
onPressed: () async {
if (_formKey.currentState.validate()) {
setState(() => loading = true);
dynamic result = await authentication
.createUserWithEmailAndPassword(email, password,
name, elements1[selectedIndex1]);
if (elements1[selectedIndex1] == 'Business') {
Navigator.push(
context,
new MaterialPageRoute(
builder: (_) => BusinessPage()));
} else {
Navigator.push(
context,
new MaterialPageRoute(
builder: (_) => Homepage()));
}
if (result == null) {
setState(() => error =
'Sorry,These credentials will not work out');
loading = false;
}
}
},
child: Text(
'Sign up',
style: TextStyle(
fontFamily: 'Antra', color: Colors.white),
),
),
),
),
],
),
),
),
),
_createAccountLabel(),
],
),
),
);
}
Widget _createAccountLabel() {
return InkWell(
onTap: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => LoginPage()));
},
child: Container(
margin: EdgeInsets.symmetric(vertical: 20),
padding: EdgeInsets.all(15),
alignment: Alignment.bottomCenter,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Do you have an account ?',
style: TextStyle(fontSize: 13, fontWeight: FontWeight.w600),
),
SizedBox(
width: 10,
),
Text(
'Login',
style: TextStyle(
color: Colors.blue,
fontSize: 13,
fontWeight: FontWeight.w600),
),
],
),
),
);
}
}

Showing a snackbar in Flutter

i am working on signin part of my project and i had a form with email and password and a sign in button and everything is working it is connecting to the firebase. It's sending me the result either success or an error. What i want to ask is that i would like to show the error in snack bar and i have been trying all day but it doesnt work. Can any one please help!! the error message am getting is below,
FlutterError (Looking up a deactivated widget's ancestor is unsafe.
At this point the state of the widget's element tree is no longer stable.
To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling inheritFromWidgetOfExactType() in the widget's didChangeDependencies() method.)
and here's the code
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:inclass/screens/authentication/signup.dart';
import 'package:inclass/screens/home/dashboard.dart';
import 'package:inclass/services/auth.dart';
import 'package:inclass/shared/loading.dart';
import 'package:inclass/widgets/logo.dart';
class Signin extends StatefulWidget {
#override
_SigninState createState() => _SigninState();
}
class _SigninState extends State<Signin> {
bool _obscureText = true;
final AuthService _auth = AuthService();
final _formkey = GlobalKey<FormState>();
bool loading = false;
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
String email = '';
String password = '';
String error = '';
#override
Widget build(BuildContext context) {
return loading
? Loading()
: Scaffold(
key: _scaffoldKey,
backgroundColor: Colors.white,
body: Builder(
builder: (context) => ListView(children: <Widget>[
Form(
key: _formkey,
child: Column(
children: <Widget>[
Logo(),
SizedBox(
height: 20.0,
),
Stack(children: <Widget>[
Image(
height: 200.0,
width: MediaQuery.of(context).size.width,
image: AssetImage("assets/images/move.png"),
fit: BoxFit.cover,
),
Positioned(
bottom: 20.0,
right: 60.0,
child: Text(
'Sign In',
style: TextStyle(
color: Color(0xff7E8E9D),
fontSize: 22.0,
fontFamily: 'Poppins'),
textAlign: TextAlign.center,
)),
Positioned(
bottom: 5.0,
right: 80.0,
child: Text(
"As",
style: TextStyle(
color: Color(0xff7E8E9D),
fontSize: 15.0,
fontFamily: 'Poppins'),
textAlign: TextAlign.center,
),
)
]),
Padding(
padding: const EdgeInsets.only(
top: 20.0, left: 15.0, right: 15.0),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
width: MediaQuery.of(context).size.width / 3,
height: 80.0,
decoration: new BoxDecoration(
//border: new Border.all(width: 1.0, color: Colors.black),
//shape: BoxShape.circle,
color: Colors.white,
boxShadow: <BoxShadow>[
// BoxShadow(
// color: Colors.grey,
// offset: Offset(1.0, 15.0),
// blurRadius: 64.0,
// ),
],
),
// color: Colors.blue,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
FontAwesomeIcons.graduationCap,
color: Color(0xffB57E20),
size: 22.0,
),
Padding(
padding:
const EdgeInsets.only(left: 15.0),
child: Text(
"Student",
style: TextStyle(
color: Color(0xffB57E20),
fontSize: 17.0,
fontFamily: 'Poppins'),
),
)
],
),
),
Container(
width: 1.0,
height: 60.0,
decoration: BoxDecoration(
border: Border(
right: BorderSide(color: Colors.black54),
),
),
),
Container(
width: MediaQuery.of(context).size.width / 3,
height: 80.0,
decoration: new BoxDecoration(
//border: new Border.all(width: 1.0, color: Colors.black),
//shape: BoxShape.circle,
color: Colors.white,
boxShadow: <BoxShadow>[
// BoxShadow(
// color: Colors.grey,
// offset: Offset(1.0, 15.0),
// blurRadius: 64.0,
// ),
],
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
FontAwesomeIcons.chalkboardTeacher,
color: Color(0xff00315C),
size: 22.0,
),
Padding(
padding:
const EdgeInsets.only(left: 15.0),
child: Text(
"Teacher",
style: TextStyle(
color: Color(0xff00315C),
fontSize: 17.0,
fontFamily: 'Poppins'),
),
)
],
),
)
],
),
),
),
Container(
child: Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20.0, top: 40.0),
child: TextFormField(
onChanged: (val) {
setState(() => email = val);
},
validator: (val) =>
val.isEmpty ? "Email can't be Empty" : null,
// textAlign: TextAlign.center,
keyboardType: TextInputType.emailAddress,
// autofocus: true,
decoration: InputDecoration(
labelText: "Email",
contentPadding:
EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12.0),
borderSide:
BorderSide(color: Color(0xff00315C))),
suffixIcon: Icon(Icons.mail)),
),
),
),
Padding(
padding: const EdgeInsets.only(
top: 15.0, left: 20.0, right: 20.0, bottom: 20.0),
child: TextFormField(
obscureText: _obscureText,
onChanged: (val) {
setState(() => password = val);
},
validator: (val) => val.length < 6
? "Password Must be 6+ Char"
: null,
// textAlign: TextAlign.center,
// autofocus: true,
decoration: InputDecoration(
labelText: "Password",
contentPadding:
EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12.0),
borderSide:
BorderSide(color: Color(0xff00315C))),
suffixIcon: GestureDetector(
onTap: () {
setState(() {
_obscureText = !_obscureText;
});
},
child: Icon(
_obscureText
? Icons.visibility
: Icons.visibility_off,
semanticLabel: _obscureText
? 'show password'
: 'hide password',
),
)),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 20.0),
child: FlatButton(
child: Text("Forgot Password?",
style: TextStyle(color: Colors.grey)),
onPressed: () {},
),
),
Padding(
padding: const EdgeInsets.only(right: 25.0),
child: OutlineButton(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
highlightedBorderColor: Color(0xffB57E20),
borderSide: BorderSide(color: Color(0xffB57E20)),
onPressed: () async {
if (_formkey.currentState.validate()) {
setState(() => loading = true);
dynamic result =
await _auth.signInWithEmailAndPassword(
email, password);
if (result == null) {
setState(() {
error = 'Could not sign in';
loading = false;
});
_showToast(context,error);
print(error);
} else {
// Navigator.push(
// context,
// MaterialPageRoute(
// builder: (_) => DashBoard()));
print("Succeed");
}
}
},
padding: EdgeInsets.only(
left: 30.0,
right: 15.0,
top: 12.0,
bottom: 12.0),
color: Colors.white,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text(
"Next",
style: TextStyle(
color: Color(0xffB57E20),
fontSize: 17.0,
fontFamily: 'Poppins'),
),
Padding(
padding: const EdgeInsets.only(
left: 10.0, top: 2.0),
child: Icon(Icons.navigate_next,
color: Color(0xffB57E20), size: 30.0),
)
],
),
),
)
],
),
Padding(
padding: const EdgeInsets.all(28.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Not Registered Yet?",
style: TextStyle(
color: Colors.grey,
fontSize: 15.0,
fontFamily: 'Poppins')),
SizedBox(
width: 10.0,
),
GestureDetector(
onTap: () => Navigator.push(context,
MaterialPageRoute(builder: (_) => SignUp())),
child: Text("Sign Up",
style: TextStyle(
color: Color(0xff00315C),
fontSize: 15.0,
fontFamily: 'Poppins')),
),
],
),
)
],
),
),
]),
),
);
}
void _showToast(BuildContext context,String error) {
final scaffold = Scaffold.of(context);
scaffold.showSnackBar(SnackBar(
content: Text(error),
duration: Duration(seconds: 2),
action: SnackBarAction(
onPressed: () {
scaffold.hideCurrentSnackBar();
},
label: 'Okay',
),
));
}
}
My code is a little bit messy i didn't refactor it yet
It is related to this part of your code
return
loading
? Loading()
: Scaffold(
when you tap on Next button, you put code like this for loading
setState(() => loading = true);
and it removes Scaffold from Widget tree. and when you are trying to use _showToast function, though you called setState loading = false again, the Scaffold is not ready and moved into Widget tree, so Scaffold.of cannot make proper result you want.
So I offer you if you want to show loading screen, you should use Dialog or IndexedStack.
Hope this can solve your problem.