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

example/lib/main.dart

import 'package:bloc_with/bloc_with.dart';
import 'package:flutter/material.dart';

class BlocWith with Loading, Messages, Paging, Search<String> {
  BlocWith({required List<String> search}) {
    this.search(data: search);
  }
}

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)),
                      id: 1,
                      onError: (_) {},
                    ),
                    child: const Text('Loading'),
                  ),
                  const SizedBox(width: 10),
                  LoadingBuilder(
                    bloc,
                    id: 1,
                    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
158
downloads

Publisher

verified publisherhunghv.com

Weekly Downloads

2024.09.26 - 2025.04.10

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