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

Flutter widgets that simplify the BLoC pattern implementation for REST APIs within an MVC architecture, significantly reducing boilerplate code.

example/lib/main.dart

import 'package:example/src/get/get.dart';
import 'package:example/src/post/post.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,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          for (int i = 0; i < 2; i++)
            Container(
              margin: const EdgeInsets.all(10.0),
              alignment: Alignment.center,
              color: Colors.blue,
              child: TextButton(
                onPressed: () =>
                    context.to(const [GetUserView(), CreateUserView()][i]),
                child: Text(
                  ["GET Request", "POST Request"][i],
                  textAlign: TextAlign.center,
                  style: const TextStyle(color: Colors.white),
                ),
              ),
            ),
        ],
      ),
    );
  }
}

extension SnackbarExtension on BuildContext {
  void alert(
    String message, {
    Color color = Colors.green,
  }) {
    ScaffoldMessenger.of(this)
      ..hideCurrentSnackBar()
      ..showSnackBar(
        SnackBar(
          content: Text(message),
          backgroundColor: color,
        ),
      );
  }

  Future<T?> to<T extends Object>(Widget child) {
    return Navigator.push<T>(
      this,
      MaterialPageRoute(builder: (context) => child),
    );
  }
}
8
likes
160
pub points
28%
popularity
screenshot

Publisher

verified publisherinidia.app

Flutter widgets that simplify the BLoC pattern implementation for REST APIs within an MVC architecture, significantly reducing boilerplate code.

Homepage
Repository (GitHub)
View/report issues

Topics

#bloc #rest-api #mvc #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