eagle_provider 1.1.0 copy "eagle_provider: ^1.1.0" to clipboard
eagle_provider: ^1.1.0 copied to clipboard

outdated

A new Flutter package to simple manager state.Based on Cubit/Provider this package makes use of ValueNotifier only

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return ControllerProvider(
      controllers: [HomeController()],
      child: MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: const MyHomePage(),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    var controller = ControllerProvider.of<HomeController>(context);
    // Future.delayed(const Duration(seconds: 3)).then(
    //   (value) {
    //     controller.changeStatus();
    //   },
    // );

    return Scaffold(
      appBar: AppBar(
        title: const Text('Home page'),
      ),
      body: ControllerConsumer<HomeController, HomeState>(
        builderWhen: (before, after) {
          return before.name != after.name;
        },
        listenWhen: (before, after) {},
        builder: (context, state) {
          if (state.status == Status.loading) {
            return const Center(child: CircularProgressIndicator());
          }

          return Center(
            child: GestureDetector(
              onTap: () {
                controller.changeName('Lucas');
              },
              child: Text('Home completed loading, name: ${state.name}'),
            ),
          );
        },
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          controller.changeName('firmino');
        },
      ),
      // body: ControllerConsumer<HomeController, HomeState>(
      //   builderWhen: (before, after) {
      //     return before.status != after.status;
      //   },
      //   builder: (BuildContext context, state) {
      //     if (state.status == Status.loading) {
      //       return const Center(child: CircularProgressIndicator());
      //     }

      //     return const Center(
      //       child: Text('Home completed loading'),
      //     );
      //   },
      // ),
    );
  }
}

// State
class HomeState extends StateController {
  const HomeState({super.status, this.name});

  final String? name;

  @override
  copyWith({
    Status? status,
    String? name,
  }) {
    return HomeState(
      status: status ?? this.status,
      name: name ?? this.name,
    );
  }

  @override
  List<Object?> get props => [status, name];
}

// Controller
class HomeController extends Controller<HomeState> {
  HomeController() : super(const HomeState());

  changeStatus([Status? status]) {
    emit(state.copyWith(status: status ?? Status.success));
  }

  changeName(String name) {
    emit(state.copyWith(name: name, status: Status.success));
    print(state.toString());
  }
}
3
likes
0
points
57
downloads

Publisher

verified publisherappinventorbrasil.com.br

Weekly Downloads

A new Flutter package to simple manager state.Based on Cubit/Provider this package makes use of ValueNotifier only

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

equatable, flutter

More

Packages that depend on eagle_provider