Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[firebase_auth]: <windows firebase flutter failure> #13340

Open
1 task done
NajdKarajeh opened this issue Sep 16, 2024 · 10 comments
Open
1 task done

[firebase_auth]: <windows firebase flutter failure> #13340

NajdKarajeh opened this issue Sep 16, 2024 · 10 comments
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. Needs Attention This issue needs maintainer attention. platform: windows Issues / PRs which are specifically for Windows. plugin: auth Stale Issue with no recent activity type: bug Something isn't working

Comments

@NajdKarajeh
Copy link

NajdKarajeh commented Sep 16, 2024

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

Auth

Which platforms are affected?

Windows

Description

[ERROR:flutter/shell/common/shell.cc(1065)] The 'firebase_auth_plugin/auth-state/[DEFAULT]' channel sent a message from native to Flutter on a non-platform thread. Platform channel messages must be sent on the platform thread. Failure to do so may result in data loss or crashes, and must be fixed in the plugin or application code creating that channel.

Reproducing the issue

the description i provided says that channel sent a message from native to flutter on an non-platform channel messages..i do handle this on my code correct but i still get this warrning

Firebase Core version

3.4.1

Flutter Version

3.24.0

Relevant Log Output

No response

Flutter dependencies

n
flutter:
sdk: flutter
http: ^1.2.2
provider: ^6.0.0
image_picker: ^1.1.2
cloud_firestore: 5.4.1
firebase_analytics : 11.3.1
firebase_auth : 5.2.1
firebase_core : 3.4.1
intl : 0.19.0

shared_preferences : 2.3.2
connectivity_plus: 6.0.5
fluttertoast: 8.2.8
font_awesome_flutter: 10.7.0
google_sign_in: 6.2.1

@NajdKarajeh NajdKarajeh added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Sep 16, 2024
@SelaseKay
Copy link
Contributor

Kindly share a sample reproducible code

@SelaseKay SelaseKay added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Sep 17, 2024
@NajdKarajeh
Copy link
Author

NajdKarajeh commented Sep 17, 2024

@google-oss-bot google-oss-bot removed the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Sep 17, 2024
@SelaseKay
Copy link
Contributor

Kindly share the code in the comment rather than sharing it as a file.

@SelaseKay SelaseKay added blocked: customer-response Waiting for customer response, e.g. more information was requested. plugin: auth platform: windows Issues / PRs which are specifically for Windows. labels Sep 17, 2024
@NajdKarajeh
Copy link
Author


import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';

import 'package:cashgo/toast.dart';

class FirebaseAuthService {
FirebaseAuth _auth = FirebaseAuth.instance;

Future<User?> signUpWithEmailAndPassword(BuildContext context, String email, String password) async {
try {
UserCredential credential = await _auth.createUserWithEmailAndPassword(email: email, password: password);

  // Ensure UI updates happen on the main thread
  WidgetsBinding.instance.addPostFrameCallback((_) {
    showCustomSnackBar(context, 'User is successfully created.');
  });
  return credential.user;
} on FirebaseAuthException catch (e) {
  WidgetsBinding.instance.addPostFrameCallback((_) {
    if (e.code == 'email-already-in-use') {
      showCustomSnackBar(context, 'The email address is already in use.');
    } else {
      showCustomSnackBar(context, 'An error occurred: ${e.code}');
    }
  });
}
return null;

}

Future<User?> signInWithEmailAndPassword(BuildContext context, String email, String password) async {
try {
UserCredential credential = await _auth.signInWithEmailAndPassword(email: email, password: password);

  // Ensure UI updates happen on the main thread
  WidgetsBinding.instance.addPostFrameCallback((_) {
    showCustomSnackBar(context, 'User is successfully signed in.');
  });
  return credential.user;
} on FirebaseAuthException catch (e) {
  WidgetsBinding.instance.addPostFrameCallback((_) {
    if (e.code == 'user-not-found' || e.code == 'wrong-password') {
      showCustomSnackBar(context, 'Invalid email or password.');
    } else {
      showCustomSnackBar(context, 'An error occurred: ${e.code}');
    }
  });
}
return null;

}
}


import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
import 'screens/supermarket_cashier_screen.dart';
import 'package:flutter/foundation.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:cashgo/Other/splashscreen.dart';
import 'package:cashgo/LoginPage/LoginPage.dart';
import 'package:cloud_firestore/cloud_firestore.dart'; // Import Firestore

Future main() async {
WidgetsFlutterBinding.ensureInitialized();

// Initialize Firebase and handle errors
bool firebaseInitialized = false;
String firebaseErrorMessage = '';

try {
// Initialize Firebase using platform-specific options from firebase_options.dart
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);

// Enable Firestore offline persistence
FirebaseFirestore.instance.settings = const Settings(
  persistenceEnabled: true,
);

// Listen to Firebase Auth changes and ensure it runs on the UI thread
FirebaseAuth.instance.idTokenChanges().listen((User? user) {
  WidgetsBinding.instance.addPostFrameCallback((_) {
    // Handle auth changes, ensure it's on the main thread
    if (user != null) {
      print("User is logged in: ${user.email}");
    } else {
      print("User is logged out.");
    }
  });
});

firebaseInitialized = true;

} catch (e) {
firebaseErrorMessage = e.toString();
}

runApp(MyApp(
firebaseInitialized: firebaseInitialized,
firebaseErrorMessage: firebaseErrorMessage,
));
}

class MyApp extends StatelessWidget {
final bool firebaseInitialized;
final String firebaseErrorMessage;

const MyApp({
super.key,
required this.firebaseInitialized,
required this.firebaseErrorMessage,
});

@OverRide
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Supermarket Cashier System',
routes: {
'/': (context) => SplashScreen(
child: _buildInitialScreen(), // Build the initial screen based on user auth
),
'/login': (context) => LoginPage(),
'/cashier': (context) => SupermarketCashierScreen(
firebaseInitialized: firebaseInitialized,
firebaseErrorMessage: firebaseErrorMessage,
),
},
);
}

// This function decides what the initial screen is based on authentication state
Widget _buildInitialScreen() {
if (!firebaseInitialized) {
// If Firebase is not initialized, show a loading spinner
return const Center(
child: CircularProgressIndicator(),
);
}

final user = FirebaseAuth.instance.currentUser;

if (user != null) {
  // If the user is already logged in, navigate to the cashier screen
  return SupermarketCashierScreen(
    firebaseInitialized: firebaseInitialized,
    firebaseErrorMessage: firebaseErrorMessage,
  );
} else {
  // If the user is not logged in, navigate to the login page
  return LoginPage();
}

}
}


import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:cashgo/Other/FormContainerWidget.dart';
import 'package:cashgo/toast.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:cashgo/firebase_auth/firebase_auth_services.dart';

class LoginPage extends StatefulWidget {
const LoginPage({super.key});

@OverRide
State createState() => _LoginPageState();
}

class _LoginPageState extends State {
bool _isSigning = false;
final FirebaseAuthService _auth = FirebaseAuthService();
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
TextEditingController _emailController = TextEditingController();
TextEditingController _passwordController = TextEditingController();

@OverRide
void dispose() {
_emailController.dispose();
_passwordController.dispose();
super.dispose();
}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
title: const Text(""),
),
body: Center(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text(
"Login",
style: TextStyle(fontSize: 27, fontWeight: FontWeight.bold),
),
const SizedBox(height: 30),
FormContainerWidget(
controller: _emailController,
hintText: "Email",
isPasswordField: false,
),
const SizedBox(height: 10),
FormContainerWidget(
controller: _passwordController,
hintText: "Password",
isPasswordField: true,
),
const SizedBox(height: 30),
GestureDetector(
onTap: () {
_signIn();
},
child: Container(
width: double.infinity,
height: 45,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(10),
),
child: Center(
child: _isSigning
? const CircularProgressIndicator(
color: Colors.white,
)
: const Text(
"Login",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
),
),
const SizedBox(height: 10),
GestureDetector(
child: Container(
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
],
),
),
),
),
const SizedBox(height: 20),

        ],
      ),
    ),
  ),
);

}

void _signIn() async {
setState(() {
_isSigning = true;
});

String email = _emailController.text;
String password = _passwordController.text;

User? user = await _auth.signInWithEmailAndPassword(context, email, password);

setState(() {
  _isSigning = false;
});

if (user != null) {
  showCustomSnackBar(context, "User successfully signed in!");
  Navigator.pushReplacementNamed(context, '/cashier'); // Navigate to the cashier screen
} else {
  showCustomSnackBar(context, "An error occurred during login");
}

}

}


import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';

void showCustomSnackBar(BuildContext context, String message) {
final snackBar = SnackBar(
content: Text(message),
duration: Duration(seconds: 2), // The duration for how long the message will stay
backgroundColor: Colors.blue,
behavior: SnackBarBehavior.floating, // Makes it float over the content
);

ScaffoldMessenger.of(context).showSnackBar(snackBar);
}

@SelaseKay

@google-oss-bot google-oss-bot removed the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Sep 17, 2024
@SelaseKay
Copy link
Contributor

This could be an OS issue rather than FF plugin issue. Kindly try running the firebase_auth example on windows and provide feedback.

@SelaseKay SelaseKay added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Sep 17, 2024
@NajdKarajeh
Copy link
Author

NajdKarajeh commented Sep 17, 2024

@SelaseKay
all of my system is working perfectly i just want to know what's wrong with this warning note that's it and my firebase is working 100% with my flutter app

testing for now on windows I'm plaining to do the app to work for android/iOS and windows.

@google-oss-bot google-oss-bot removed the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Sep 17, 2024
@SelaseKay
Copy link
Contributor

I understand. Could you please try running the firebase_auth example app to see if the same warning message appears on your end?

@SelaseKay SelaseKay added the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Sep 17, 2024
@NajdKarajeh
Copy link
Author

aah i see that will prove it okey,,,where i find this example app?

@google-oss-bot google-oss-bot removed the blocked: customer-response Waiting for customer response, e.g. more information was requested. label Sep 17, 2024
@SelaseKay
Copy link
Contributor

@SelaseKay SelaseKay added blocked: customer-response Waiting for customer response, e.g. more information was requested. labels Sep 18, 2024
@google-oss-bot google-oss-bot added the Stale Issue with no recent activity label Sep 27, 2024
@google-oss-bot
Copy link

Hey @NajdKarajeh. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. Needs Attention This issue needs maintainer attention. platform: windows Issues / PRs which are specifically for Windows. plugin: auth Stale Issue with no recent activity type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants