api_bloc 2.0.1 copy "api_bloc: ^2.0.1" to clipboard
api_bloc: ^2.0.1 copied to clipboard

Significantly reducing boilerplate code of BLoC pattern to efficiently handle Rest API interactions.

example/lib/main.dart

import 'package:example/fetch/get_page.dart';
import 'package:example/submit/post_page.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MaterialApp(home: HomePage()));
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: const Text("API Bloc"),
        ),
        body: Column(
            mainAxisSize: MainAxisSize.max,
            mainAxisAlignment: MainAxisAlignment.center,
            children: List.generate(
                2,
                (x) => Padding(
                    padding: const EdgeInsets.all(10.0),
                    child: Center(
                        child: ColoredBox(
                            color: Colors.blue,
                            child: TextButton(
                                onPressed: () {
                                  Navigator.push(
                                      context,
                                      MaterialPageRoute(
                                          builder: (context) => [
                                                GetPage(),
                                                const PostPage()
                                              ][x]));
                                },
                                child: Text(
                                    ["Fetch Sample", "Submit Sample"][x],
                                    textAlign: TextAlign.center,
                                    style: const TextStyle(
                                        color: Colors.white)))))))));
  }
}

void snackbar(BuildContext context,
        {required String message, Color color = Colors.green}) =>
    ScaffoldMessenger.of(context)
        .showSnackBar(SnackBar(content: Text(message), backgroundColor: color));
9
likes
160
pub points
30%
popularity
screenshot

Publisher

verified publisherinidia.app

Significantly reducing boilerplate code of BLoC pattern to efficiently handle Rest API interactions.

Homepage
Repository (GitHub)
View/report issues

Topics

#bloc #api

Documentation

API reference

Funding

Consider supporting this project:

ko-fi.com

License

MIT (license)

Dependencies

args, equatable, flutter

More

Packages that depend on api_bloc