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

A reactive state management library for Flutter that adds magic to any Widget with signals, computed values, and effects powered by alien_signals.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Oref Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const Counter(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final count = useSignal(context, 0);
    final doubleCount = useComputed(context, (_) => count * 2);

    void increment() => count(count + 1);

    useEffect(context, () {
      debugPrint('useEffect 1, count: ${count()}');
    });

    useEffect(context, () {
      debugPrint('useEffect 2, count: ${doubleCount()}');
    });

    return Scaffold(
      appBar: AppBar(title: const Text("Oref Example")),
      body: Center(
        child: Text(
          "Count: ${count()}, Double: ${doubleCount()}",
          style: TextStyle(fontSize: 36),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: increment,
        child: const Icon(Icons.plus_one),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final count = useSignal(context, 0);
    final doubleCount = useComputed(context, (_) => count * 2);

    void increment() => count(count + 1);

    useEffect(context, () {
      debugPrint('useEffect 1, count: ${count()}');
    });

    useEffect(context, () {
      debugPrint('useEffect 2, count: ${doubleCount()}');
    });

    return Center(
      child: Column(
        children: [
          Text("Count: ${count()}"),
          FilledButton(onPressed: increment, child: const Text('Increment')),
        ],
      ),
    );
  }
}
8
likes
0
points
732
downloads

Publisher

verified publishermedz.dev

Weekly Downloads

A reactive state management library for Flutter that adds magic to any Widget with signals, computed values, and effects powered by alien_signals.

Repository (GitHub)
View/report issues

Topics

#signal #reactive #state

Funding

Consider supporting this project:

github.com
opencollective.com

License

unknown (license)

Dependencies

alien_signals, flutter

More

Packages that depend on oref