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

A bunch of widgets that helps you to easily works with puer with Flutter.

example/lib/main.dart

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

typedef CounterFeature = Feature<CounterState, CounterMessage, CounterEffect>;

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: FeatureProvider<CounterFeature>(
        create: (context) =>
            Feature<CounterState, CounterMessage, CounterEffect>(
          initialState: const CounterState(count: 0),
          update: counterUpdate,
        ),
        child: const CounterPage(),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final feature = FeatureProvider.of<CounterFeature>(context);

    return Scaffold(
      appBar: AppBar(title: const Text('puer_flutter example')),
      body: Center(
        child: FeatureBuilder<CounterFeature, CounterState>(
          builder: (context, state) => Text(
            '${state.count}',
            style: Theme.of(context).textTheme.displayLarge,
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => feature.add(Increment()),
        child: const Icon(Icons.add),
      ),
    );
  }
}

// --- Minimal feature implementation used by the example ---

sealed class CounterMessage {}

final class Increment extends CounterMessage {}

sealed class CounterEffect {}

final class CounterState {
  const CounterState({required this.count});

  final int count;
}

Next<CounterState, CounterEffect> counterUpdate(
  CounterState state,
  CounterMessage msg,
) {
  if (msg is Increment) {
    return next(
      state: CounterState(
        count: state.count + 1,
      ),
    );
  }
  return next();
}
1
likes
160
points
192
downloads

Documentation

API reference

Publisher

verified publishervorky.io

Weekly Downloads

A bunch of widgets that helps you to easily works with puer with Flutter.

Homepage
Repository (GitHub)
View/report issues

Topics

#state-management #architecture #unidirectional-data-flow #mvi

License

MIT (license)

Dependencies

flutter, meta, provider, puer

More

Packages that depend on puer_flutter