signals_flutter 5.0.0-beta.13 copy "signals_flutter: ^5.0.0-beta.13" to clipboard
signals_flutter: ^5.0.0-beta.13 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 MyHomePage(title: 'Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with SignalsAutoDisposeMixin {
  late final _counter = createSignal(context, 0);

  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:',
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
19
likes
0
pub points
85%
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