1

I tried using an answer to the same question but I am not sure what else I have to do in my case

import 'package:auduo/routes/routes.dart';
import 'package:auduo/opening_Screen.dart';
import 'package:firebase_core/firebase_core.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      routes: AppRoutes.define(),
      home: OpeningScreen(),
    );
  }
}

Let me know if you need to see other .dart files

Below is the Requested Code From The Comments

import 'package:flutter/material.dart';
import 'package:auduo/routes/routes.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';
// Bleyl Dev Vid 2 - 7:49

class Register extends StatefulWidget {
  @override
  _RegisterViewState createState() => _RegisterViewState();
}

class _RegisterViewState extends State<Register> {
  final _formKey = GlobalKey<FormState>();
  TextEditingController _usernameController = TextEditingController();
  TextEditingController _emailController = TextEditingController();
  TextEditingController _passwordController = TextEditingController();
  TextEditingController _repasswordController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    final mq = MediaQuery.of(context);

    final logo = Image.asset(
      "assets/Auduo Logo V 1.0.png",
      height: mq.size.height / 4,
    );

    final usernameField = TextFormField(
      controller: _usernameController,
      style: TextStyle(color: Colors.white),
      cursorColor: Colors.white,
      decoration: InputDecoration(
        focusedBorder: UnderlineInputBorder(
          borderSide: BorderSide(color: Colors.yellow),
        ),
        hintText: "NiceSound259",
        labelText: "Username",
        labelStyle: TextStyle(color: Colors.white),
        hintStyle: TextStyle(
          color: Colors.white,
        ),
      ),
    );

    final emailField = TextFormField(
      controller: _emailController,
      keyboardType: TextInputType.emailAddress,
      style: TextStyle(color: Colors.white),
      cursorColor: Colors.white,
      decoration: InputDecoration(
        focusedBorder: UnderlineInputBorder(
          borderSide: BorderSide(color: Colors.yellow),
        ),
        hintText: "Something@example.com",
        labelText: "Email",
        labelStyle: TextStyle(color: Colors.white),
        hintStyle: TextStyle(
          color: Colors.white,
        ),
      ),
    );

    final passwordField = TextFormField(
      obscureText: true,
      controller: _passwordController,
      style: TextStyle(color: Colors.white),
      cursorColor: Colors.white,
      decoration: InputDecoration(
        focusedBorder: UnderlineInputBorder(
          borderSide: BorderSide(color: Colors.yellow),
        ),
        hintText: "password",
        labelText: "Password",
        labelStyle: TextStyle(color: Colors.white),
        hintStyle: TextStyle(
          color: Colors.white,
        ),
      ),
    );

    final repasswordField = TextFormField(
      obscureText: true,
      controller: _repasswordController,
      style: TextStyle(color: Colors.white),
      cursorColor: Colors.white,
      decoration: InputDecoration(
        focusedBorder: UnderlineInputBorder(
          borderSide: BorderSide(color: Colors.yellow),
        ),
        hintText: "re-enter password",
        labelText: "Re-Enter Password",
        labelStyle: TextStyle(color: Colors.white),
        hintStyle: TextStyle(
          color: Colors.white,
        ),
      ),
    );

    final fields = Padding(
      padding: EdgeInsets.only(top: 10.0),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: <Widget>[
          usernameField,
          emailField,
          passwordField,
          repasswordField
        ],
      ),
    );

    final registerButton = Material(
      elevation: 5,
      borderRadius: BorderRadius.circular(25),
      color: Colors.white,
      child: MaterialButton(
        minWidth: mq.size.width / 1.2,
        padding: EdgeInsets.fromLTRB(10, 15, 10, 15),
        child: Text(
          "Register",
          textAlign: TextAlign.center,
          style: TextStyle(
            fontSize: 20,
            color: Colors.black,
            fontWeight: FontWeight.bold,
          ),
        ),
        onPressed: () async {
          try {
            User user =
                (await FirebaseAuth.instance.createUserWithEmailAndPassword(
              email: _emailController.text,
              password: _passwordController.text,
            )) as User;
            if (user != null) {
              user.updateDisplayName(_usernameController.text);
              Navigator.of(context).pushNamed(AppRoutes.home);
            }
          } catch (e) {
            print(e);
            _usernameController.text = "";
            _passwordController.text = "";
            _repasswordController.text = "";
            _emailController.text = "";
            //TODO alert dialog with error
          }
        },
      ),
    );

    final bottom = Column(
      mainAxisAlignment: MainAxisAlignment.start,
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: <Widget>[
        //loginButton,
        Padding(
          padding: EdgeInsets.all(8.0),
        ),
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            Text(
              "Already have an account?",
              style: Theme.of(context).textTheme.subtitle1?.copyWith(
                    color: Colors.white,
                  ),
            ),
            MaterialButton(
              onPressed: () {
                Navigator.of(context).pushNamed(AppRoutes.authLogin);
              },
              child: Text(
                "Sign In",
                style: Theme.of(context).textTheme.subtitle1?.copyWith(
                      color: Colors.white,
                      decoration: TextDecoration.underline,
                    ),
              ),
            ),
          ],
        ),
      ],
    );

    return Scaffold(
      backgroundColor: Colors.black,
      body: Form(
        key: _formKey,
        child: SingleChildScrollView(
          padding: EdgeInsets.all(36),
          child: Container(
            height: mq.size.height,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: <Widget>[
                logo,
                fields,
                registerButton,
                Padding(
                  padding: EdgeInsets.only(bottom: 150),
                  child: bottom,
                )
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Above is the Requested Code From The Comments, This is the register.dart code the functions are pretty similar to login.dart so hopefully this is enough.

  • Maybe we can start from here, I presume you created the app in your firebase and added the generated file from there to your android folder yes? – DARTender Feb 05 '22 at 21:43
  • Yes I followed the firebase setup for ios and android. Are you talking about the info.plist or something else. Btw am using visual studio – frootyloops Feb 05 '22 at 22:56
  • Which platform are you developing for? Android or iOS? – DARTender Feb 05 '22 at 23:01
  • Both but i primarily run the app on the ios emulator – frootyloops Feb 06 '22 at 01:26
  • Does this answer your question? [No Firebase App '\[DEFAULT\]' has been created - call Firebase.initializeApp() in Flutter and Firebase](https://stackoverflow.com/questions/63492211/no-firebase-app-default-has-been-created-call-firebase-initializeapp-in) – Tim Feb 06 '22 at 09:46
  • It Worked! but now i get a new error: – frootyloops Feb 06 '22 at 15:40
  • flutter: type 'UserCredential' is not a subtype of type 'User' in type cast – frootyloops Feb 06 '22 at 15:40
  • There's somewhere in your code where you have something like this or closely similar, final currentUser = Firebese.instance.currentUser!; . Share that screenshot or code – DARTender Feb 06 '22 at 16:39
  • I updated the code above to include the code you were asking for (I Put It In A MaterialButton) – frootyloops Feb 06 '22 at 23:52
  • @O'neya What should I replace Firebase.instance.currentUser with? – frootyloops Feb 07 '22 at 20:56
  • Share the code. That part is just fine. The error could be emanating from how you use it. But I'll need to see your code to pick it out. Edit your original post to include it or just add it as a new a new post below your original – DARTender Feb 07 '22 at 21:44
  • Code has been updated – frootyloops Feb 11 '22 at 17:43

1 Answers1

0

Try running flutter clean and run the app again. another known fix would be to add the optional parameters name and options to the

await Firebase.initializeApp(name: ....., options: .....)

You could also try to minimally reproduce the error by creating the default counter app, add firebase initializations and see if the error persists.

Tim
  • 152
  • 8