Xelame / firebase

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flutter Firebase Project

This Flutter project integrates Firebase services for authentication, database, and storage. It's built using the FlutterFire plugins for Firebase.

Table of Contents

Getting Started

Prerequisites

  • Flutter SDK
  • Firebase Project: Create a new project on the Firebase Console.
  • Firebase Configuration Files: Download google-services.json (Android) and GoogleService-Info.plist (iOS) from Firebase Console and place them in the respective folders.

Installation

  1. Clone the repository:

    git clone https://github.com/Xelame/firebase.git
  2. Navigate to the project directory:

    cd firebase
  3. Install dependencies:

    flutter pub get

Firebase Configuration

Authentication

  1. Enable the Authentication service in the Firebase Console.
  2. Follow the setup instructions to configure authentication providers.

Cloud Firestore

  1. Enable Cloud Firestore in the Firebase Console.
  2. Set up your Firestore database and collections.

Firebase Storage

  1. Enable Firebase Storage in the Firebase Console.
  2. Set up your storage buckets and permissions.

Usage

Authentication Usage

// Sign in 
await FirebaseAuth.instance.signInWithEmailAndPassword(
    email: _emailController.text,
    password: _passwordController.text,
);

// Sign up
await FirebaseAuth.instance.createUserWithEmailAndPassword(
    email: _emailController.text,
    password: _passwordController.text,
);

Cloud Firestore Usage

// Writing Data
final notes = FirebaseFirestore.instance.collection('notes');

notes.add({
          'title': taskTitle,
          'content': taskDescription,
          'done': false,
          'file': 'file/${_file!.name}',
        }
);

// Reading Data
StreamBuilder<QuerySnapshot>(
        stream: notes.snapshots(),
        ...
        children: snapshot.data!.docs.map((DocumentSnapshot document) {
              Map<String, dynamic> data =
                  document.data()! as Map<String, dynamic>;
              return ListTile(
                ...
                title: Text(data['title']),
                subtitle: Text(data['content']),
                ...

Firebase Storage Usage

// Upload File
Future _uploadFile() async {
    final path = 'file/${_file!.name}';
    final file = File(_file!.path!);

    final ref = FirebaseStorage.instance.ref().child(path);
    setState(() {
      _task = ref.putFile(file);
    });

    await _task!.whenComplete(() async {
      _urlDownload = await ref.getDownloadURL();
    });
    
    setState(() {
      _task = null;
    });
  }

Contributing

Contributions are welcome! See the Contributing Guidelines for more details.

License

This project is licensed under the MIT License.

About


Languages

Language:Dart 38.3%Language:C++ 29.9%Language:CMake 23.7%Language:Swift 2.9%Language:HTML 2.4%Language:C 1.8%Language:Java 0.8%Language:Kotlin 0.2%Language:Objective-C 0.0%