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

outdated

A new Flutter package to simple manager state.

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>();
    Future.delayed(const Duration(seconds: 3)).then(
      (value) {
        controller.changeStatus();
      },
    );

    return Scaffold(
      appBar: AppBar(
        title: const Text('Home page'),
      ),
      body: ControllerBuilder<HomeController, HomeState>(
        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 {
  HomeState({super.status});

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

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

  changeStatus() {
    emit(state.copyWith(status: Status.success));
  }
}
3
likes
0
points
57
downloads

Publisher

verified publisherappinventorbrasil.com.br

Weekly Downloads

A new Flutter package to simple manager state.

Homepage
Repository (GitLab)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on eagle_provider