bloc_with 1.2.0 copy "bloc_with: ^1.2.0" to clipboard
bloc_with: ^1.2.0 copied to clipboard

A library that adds some commonly used features to your project

A library that adds some commonly used features to your project

bloc_with.png

Getting started #

To install, add it to your pubspec.yaml file:

dependencies:
    bloc_with:
copied to clipboard

To import it:

import 'package:bloc_with/bloc_with.dart';
copied to clipboard

Usage #

Use as a mixin to help you write cleaner code

class BlocWith with Loading, Messages, Paging, Search<String> {
  BlocWith({required List<String> search}) {
    init(data: search);
  }
}
copied to clipboard

Implementation in main():

void main() {
  final bloc = BlocWith(search: ['one', 'two', 'three', 'four']);
  final receiver = ValueNotifier<String>('');
  runApp(MaterialApp(
    debugShowCheckedModeBanner: false,
    home: Scaffold(
      body: SafeArea(
        child: Column(
          children: [
            SizedBox(
              height: 100,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  ElevatedButton(
                    onPressed: () =>
                        bloc.loading(
                                () => Future.delayed(const Duration(seconds: 3)),
                            onError: (_) {}),
                    child: const Text('Loading'),
                  ),
                  const SizedBox(width: 10),
                  LoadingBuilder(
                    bloc,
                    loading: const Center(child: CircularProgressIndicator()),
                    stack: false,
                    child: const Center(child: Text('Data')),
                  ),
                ],
              ),
            ),
            Container(
              color: Colors.grey.shade500,
              padding: const EdgeInsets.all(10),
              child: Row(
                children: [
                  ElevatedButton(
                    onPressed: () =>
                        bloc.send(
                            const Message(type: 'message', content: 'Message')),
                    child: const Text('Send Message'),
                  ),
                  const Expanded(child: Divider()),
                  MessageListener(
                    bloc,
                    message: {'message': (content) => receiver.value = content},
                    child: ValueListenableBuilder(
                      valueListenable: receiver,
                      builder: (_, value, __) =>
                          CircleAvatar(radius: 40, child: Text(value)),
                    ),
                  ),
                ],
              ),
            ),
            Expanded(
              child: Container(
                padding: const EdgeInsets.all(10),
                child: Column(
                  children: [
                    TextFormField(controller: bloc.controller),
                    Expanded(
                        child: SearchBuilder(
                          bloc,
                          filterEmpty: const Center(child: Text('No result')),
                        )),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    ),
  ));
}
copied to clipboard
0
likes
160
points
166
downloads

Publisher

verified publisherhunghv.com

Weekly Downloads

2024.09.16 - 2025.03.31

A library that adds some commonly used features to your project

Repository (GitHub)

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter

More

Packages that depend on bloc_with