this is my code
class _AdminLoginScreenState extends State<AdminLoginScreen> {
var _formkey = GlobalKey<FormState>();
var emailController = TextEditingController();
var passwordController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0XFFE4C9E5),
body: SafeArea(
child: CustomScrollView(
slivers: [
SliverFillRemaining(
hasScrollBody: false,
child: Form(
key: _formkey,
child: Stack(
children: [
Positioned(
left: -30,
right: 275,
top: -175,
bottom: 100,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(0XFFFEB06A),
),
)),
Positioned(
left: 275,
right: -40,
top: 100,
bottom: -350,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Color(0XFF36D6E7),
),
)),
Positioned(
left: 37,
right: 37,
top: 200,
bottom: 100,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(40),
color: Colors.white,
),
),
),
Column(
// children: [
// Flexible(
// child: Padding(
// padding: const EdgeInsets.symmetric(
// horizontal: 50,
// ),
// child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 300,
),
Text(
"LogIn ",
style: TextStyle(
fontSize: 35,
color: Colors.black26,
fontWeight: FontWeight.bold,
),
),
SizedBox(
height: 20,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Color(0XFFD3D3D3),
),
child: TextFormField(
controller: emailController,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
borderSide: BorderSide(color: Colors.black)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.black),
borderRadius: BorderRadius.circular(20),
),
labelText: 'Email',
labelStyle: TextStyle(
color: Color(0XFF4D4C4C),
),
),
validator: (value) {
if (value == null ||
value.isEmpty ||
!RegExp(r'[email protected]')
// r'^[w-,]+@([w-]+.)+[w]{2,4}'
.hasMatch(value!)) {
return 'Please enter correct email';
} else {
return null;
}
},
),
),
SizedBox(
height: 20,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Color(0XFFD3D3D3),
),
child: TextFormField(
controller: passwordController,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20),
borderSide:
BorderSide(color: Colors.black)),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.black),
borderRadius: BorderRadius.circular(20),
),
labelText: 'Password',
labelStyle: TextStyle(
color: Color(0XFF4D4C4C),
),
),
validator: (value) {
if (value!.isEmpty ||
!RegExp(r'^[a-z A-Z 0-9]+$')
.hasMatch(value!)) {
return 'Please enter correct password';
} else {
return null;
}
}),
),
SizedBox(
height: 20,
),
Center(
child: Container(
width: 300,
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Color(0XFFFEB06A),
),
child: TextButton(
onPressed: () {
if (_formkey.currentState!.validate()) {
Navigator.pushNamed(context, '/register');
/* LoginCubit.get(context)
.userLogin(
email: emailController.text,
password:
passwordController.text,
);*/
/*BlocProvider.of<LoginCubit>(
context)
.userLogin(
email:
emailController.text,
password:
password.text);*/
}
},
child: Text(
'LogIn',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
),
Center(
child: TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: ((context) => ForgotPass())));
},
child: Text(
'Forgot Your Password?',
style: TextStyle(
fontSize: 10,
color: Colors.black,
),
),
),
),
SizedBox(
height: 150,
),
],
),
// ),
// ),
],
),
// ],
),
),
// ),
],`
and this the exception
Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown while applying parent data.:
Incorrect use of ParentDataWidget.
The ParentDataWidget Flexible(flex: 1) wants to apply ParentData of type FlexParentData to a RenderObject, which has been set up to accept ParentData of incompatible type StackParentData.
Usually, this means that the Flexible widget has the wrong ancestor RenderObjectWidget. Typically, Flexible widgets are placed directly inside Flex widgets.
The offending Flexible is currently placed inside a Stack widget.
The ownership chain for the RenderObject that received the incompatible parent data was:
Padding ← Flexible ← Stack ← _FormScope ← WillPopScope ← Form-[LabeledGlobalKey<FormState>#ac9e2] ← _SliverFillRemainingWithoutScrollable ← SliverFillRemaining ← Viewport ← IgnorePointer-[GlobalKey#93db6] ← ⋯
When the exception was thrown, this was the stack
note that i alredy deleted flexible and padding widgets
2
Answers
You can wrap the
Column
widget withPositioned.fill
fill Column in stack widget.Use position widget
Align
orPositioned
as a stack child.This falls under one of the common flutter errors.
Incorrect use of ParentData widget