Exception caught by gesture when trying login - Flutter, firebase, Getx #11599
Unanswered
manarbajafar
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am developing a app with Flutter and i using sign in with email/password by firebase- and i got this error when I clicked my login button, ════════ Exception caught by gesture ═══════════════════════════════════════════ type 'Null' is not a subtype of type 'AuthController' in type cast ════════════════════════════════════════════════════════════════════════════════:
This is my login_page.dart
`
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shaghaf_app/screens/homepage.dart';
import '../controllers/auth_controller.dart';
import '../widgets/custom_button.dart';
import '../widgets/custom_textForm.dart';
class Login extends GetWidget {
final GlobalKey _formKey = GlobalKey();
@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: const Color(0xffF6F2FA),
elevation: 0.0,
centerTitle: true,
title: Text(
"تسجيل الدخول",
style: Theme.of(context).textTheme.titleMedium,
),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 16),
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
"مرحبا بك",
style: Theme.of(context).textTheme.titleLarge,
),
Text(
"الرجاء إدخال عنوان البريد الإلكتروني وكلمة المرور لتسجيل الدخول",
style: Theme.of(context).textTheme.bodySmall),
CustomTextFormField(
hintText: "البريد الإلكتروني",
onSaved: (value) {
controller.email = value;
},
validator: (value) {
if (!controller.isEmail(value)) {
print("error");
}
},
),
CustomTextFormField(
hintText: "كلمة المرور",
onSaved: (value) {
controller.password = value;
},
validator: (value) {
if (value == null) {
print("error");
}
},
),
CustomButton(
text: "تسجيل الدخول",
onPressed: () {
_formKey.currentState!.save();
if (_formKey.currentState!.validate()) {
controller.login();
}
},
),
const SizedBox(
height: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
"لا تملك حساب؟",
style: TextStyle(color: Color(0xFF868D95)),
),
GestureDetector(
onTap: () {},
child: Text(
"سجل الآن",
style: Theme.of(context).textTheme.titleSmall,
),
)
],
)
],
),
),
),
),
);
}
}
`
AuthController.dart:
`import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../screens/homepage.dart';
class AuthController extends GetxController {
FirebaseAuth _auth = FirebaseAuth.instance;
late String email, password;
@OverRide
void onInit() {
// TODO: implement onInit
super.onInit();
}
@OverRide
void onReady() {
// TODO: implement onReady
super.onReady();
}
@OverRide
void onClose() {
// TODO: implement onClose
super.onClose();
}
Future login() async {
try {
await _auth.signInWithEmailAndPassword(
email: email.trim(), password: password.trim());
Get.offAll(Homepage());
} on FirebaseAuthException catch (e) {
print(e.message);
Get.snackbar("خطأ في تسجيل الدخول", e.message!,
colorText: Colors.black, snackPosition: SnackPosition.BOTTOM);
}
}
bool isEmail(String email) {
String p =
r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_
{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+"; RegExp regExp = new RegExp(p); print(regExp.hasMatch(email)); return regExp.hasMatch(email); } }
and main.dart
`import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shaghaf_app/auth.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:shaghaf_app/helper/binding.dart';
import 'screens/homepage.dart';
import 'screens/login.dart';
import 'screens/signup.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
return GetMaterialApp(
initialBinding: Binding(),
debugShowCheckedModeBanner: false,
title: 'shaghaf',
theme: ThemeData(
backgroundColor: const Color(0xffF6F2FA),
fontFamily: 'Tajawal',
primaryColor: const Color(0xFF030865),
textTheme: const TextTheme(
titleMedium: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Color(0xFF030865),
),
titleLarge: TextStyle(
fontSize: 25,
fontWeight: FontWeight.w900,
color: Color(0xFF030865),
),
bodySmall: TextStyle(
color: Color(0xFF868D95),
fontFamily: 'Poppins',
fontSize: 14,
),
titleSmall: TextStyle(
decoration: TextDecoration.underline,
fontFamily: 'Poppins',
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
// home: const Auth(),
routes: {
'/': ((context) => const Auth()),
'homepagescreen': ((context) => Homepage()),
'signupscreen': ((context) => const Signup()),
'loginscreen': ((context) => Login())
},
);
}
}
`
binding.dart
`import 'package:get/get.dart';
import '../controllers/auth_controller.dart';
class Binding extends Bindings {
@OverRide
void dependencies() {
Get.lazyPut(() => AuthController);
}
}
`
my code is connected to firebase and i set formKey to my form, any suggestions?
Beta Was this translation helpful? Give feedback.
All reactions