Skip to content

Samuelluango98/flutter-custom-errors-handler

Repository files navigation

custom_errors_handler

This package is a basic custom error handler with default error messages on three languages (english, french and spanish) in for firebase auth, storage and firestore error codes.

Example

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

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  void _throwException() {
    throw ServerException(code: 'weak-password');
  }

  void _cathException(BuildContext context) {
    try {
      _throwException();
    } on ServerException catch (e) {
      ServerFailure failure = ServerFailure.fromCode(code: e.code);
      final snackBar = SnackBar(content: Text(failure.error.message.en));
      ScaffoldMessenger.of(context).showSnackBar(snackBar);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: ElevatedButton(
          onPressed: () => _cathException(context),
          child: const Text('Throw Exception'),
        ),
      ),
    );
  }
}

About

This package is a basic custom error handler with default error messages on three languages (English, French and Spanish) in for firebase auth, storage and firestore error codes.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors