record_result 1.0.1+2 copy "record_result: ^1.0.1+2" to clipboard
record_result: ^1.0.1+2 copied to clipboard

record_result is a package that provides a type called Result for handling the outcomes of operations.

example/lib/main.dart

import 'package:example/cubit/home_cubit.dart';
import 'package:example/repos/home_repo.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: BlocProvider(
          create: (context) => HomeCubit(homeRepo: HomeRepo()),
          child: BlocBuilder<HomeCubit, HomeState>(
            builder: (context, state) {
              return Center(
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    if (state is HomeInitial)
                      const Text('Click the button below to get a number'),
                    if (state is HomeLoaded)
                      Text(
                        'The call was succesful!!! The number '
                        'i got was: ${state.loadedNumber}',
                      ),
                    if (state is HomeError)
                      Padding(
                        padding: const EdgeInsets.all(8),
                        child: Text(
                          'The call was unsuccesful 😔 The error '
                          'i got was:\n${state.errorMessage}',
                          textAlign: TextAlign.center,
                        ),
                      ),
                    if (state is HomeLoading)
                      const CircularProgressIndicator.adaptive(),
                    if (state is! HomeLoading)
                      Padding(
                        padding: const EdgeInsets.all(8),
                        child: CupertinoButton.filled(
                          child: const Text('Get number'),
                          onPressed: () =>
                              context.read<HomeCubit>().getNumber(),
                        ),
                      ),
                  ],
                ),
              );
            },
          ),
        ),
      ),
    );
  }
}
5
likes
160
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

record_result is a package that provides a type called Result for handling the outcomes of operations.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

equatable

More

Packages that depend on record_result