So it sound like a dumb question but I don’t get it. I have a Controller Class that has a method
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import '../utils.dart';
class UserController {
Future signMeIn(TextEditingController emailController,
TextEditingController passwordController, context, navigatorKey) async {
showDialog(
context: context,
barrierDismissible: false,
builder: (context) => Center(
child: CircularProgressIndicator(),
));
try {
await FirebaseAuth.instance.signInWithEmailAndPassword(
email: emailController.text.trim(),
password: passwordController.text.trim());
} on FirebaseAuthException catch (e) {
print(e);
Utils.showSnackBar(e.message);
}
navigatorKey.currentState!.popUntil((route) => route.isFirst);
}
}
and I simply want to reuse this method in a stateful widget
so Im importing the file where the method is defined
import "user_controller.dart";
and trying to call it here
ElevatedButton.icon(
style: ElevatedButton.styleFrom(minimumSize: Size.fromHeight(50)),
icon: Icon(Icons.lock_open, size: 32),
label: Text(
"Sign In",
style: TextStyle(fontSize: 24),
),
onPressed: signMeIn(parameters),
),
but I get the error that it isn’t defined
what am I doing wrong?
>Solution :
UserController controller = UserController();
ElevatedButton.icon(
style: ElevatedButton.styleFrom(minimumSize: Size.fromHeight(50)),
icon: Icon(Icons.lock_open, size: 32),
label: Text(
"Sign In",
style: TextStyle(fontSize: 24),
),
onPressed: controller.signMeIn(parameters),
),