folivora_error_handler 0.0.2 copy "folivora_error_handler: ^0.0.2" to clipboard
folivora_error_handler: ^0.0.2 copied to clipboard

A useful error handler

example/lib/main.dart

import 'package:folivora_error_handler/folivora_error_handler.dart';
import 'package:flutter/material.dart';
import 'package:twostrings_palette/twostrings_palette.dart';

import 'custom_error.dart';
import 'custom_exception.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Two Strings Package Test App',
      theme: ThemeData(
        primarySwatch: MaterialColor(TwoStringsColor.primaryMaterialColor.colorHex, TwoStringsColor.primaryMaterialColor.swatch),
      ),
      home: const MyHomePage(title: 'Two Strings Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            ElevatedButton(
              onPressed: () {
                try {
                  FvError fvError = FvErrors.conflict();
                  throw FvException(fvError);
                } on FvException {
                  FvErrorMessageHandler.showError(context: context, widgetType: WidgetType.dialog);
                }
              },
              child: const Text("Folivora Exception"),
            ),
            ElevatedButton(
              onPressed: () {
                try {
                  FvError fvError = CustomError("Custom Error");
                  throw CustomException(fvError);
                } on CustomException {
                  FvErrorMessageHandler.showError(context: context, widgetType: WidgetType.dialog);
                }
              },
              child: const Text("Custom Exception"),
            ),
          ],
        ),
      ),
    );
  }
}