signals_flutter 5.2.1 copy "signals_flutter: ^5.2.1" to clipboard
signals_flutter: ^5.2.1 copied to clipboard

The signals library exposes four core functions which are the building blocks to model any business logic you can think of.

example/lib/main.dart

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

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

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

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

class Example extends StatefulWidget {
  const Example({super.key, this.title = 'Example'});

  final String title;

  @override
  State<Example> createState() => _ExampleState();
}

class _ExampleState extends State<Example> with SignalsAutoDisposeMixin {
  final _counter = signal(0, debugLabel: 'Counter');

  void _incrementCounter() => _counter.value++;

  @override
  void initState() {
    super.initState();
    effect(() {
      debugPrint('count: ${_counter()}');
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            Builder(builder: (context) {
              return Text(
                '${_counter.watch(context)}',
                style: Theme.of(context).textTheme.headlineMedium,
              );
            }),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
30
likes
0
pub points
88%
popularity

Publisher

verified publisherrodydavis.com

The signals library exposes four core functions which are the building blocks to model any business logic you can think of.

Homepage
Repository (GitHub)
View/report issues

Topics

#signal #reactive #state #signals #rx

Documentation

Documentation

License

unknown (license)

Dependencies

flutter, signals_core

More

Packages that depend on signals_flutter