flutter_solidart 1.7.0 copy "flutter_solidart: ^1.7.0" to clipboard
flutter_solidart: ^1.7.0 copied to clipboard

A simple State Management solution for Flutter applications inspired by SolidJS

example/lib/main.dart

import 'dart:developer' as dev;

import 'package:example/pages/counter.dart';
import 'package:example/pages/derived_signal.dart';
import 'package:example/pages/dual_signal_builder.dart';
import 'package:example/pages/effects.dart';
import 'package:example/pages/map_signal.dart';
import 'package:example/pages/resource.dart';
import 'package:example/pages/set_signal.dart';
import 'package:example/pages/show.dart';
import 'package:example/pages/solid/solid.dart';
import 'package:example/pages/list_signal.dart';
import 'package:flutter/material.dart';
import 'package:flutter_solidart/flutter_solidart.dart';

/// Creating a logger that notifies when signals are created, disposed and updated.
///
class Logger implements SolidartObserver {
  @override
  void didCreateSignal(SignalBase<Object?> signal) {
    dev.log(
        'didCreateSignal(name: ${signal.options.name}, value: ${signal.value})');
  }

  @override
  void didDisposeSignal(SignalBase<Object?> signal) {
    dev.log('didDisposeSignal(name: ${signal.options.name})');
  }

  @override
  void didUpdateSignal(SignalBase<Object?> signal) {
    dev.log(
        'didUpdateSignal(name: ${signal.options.name}, previousValue: ${signal.previousValue}, value: ${signal.value})');
  }
}

void main() {
  SolidartConfig.observers.add(Logger());
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        useMaterial3: false,
        primarySwatch: Colors.blue,
      ),
      home: const HomePage(),
      routes: routes,
    );
  }
}

// Maps the routes to the specific widget page.
final routes = <String, WidgetBuilder>{
  '/counter': (_) => const CounterPage(),
  '/show': (_) => const ShowPage(),
  '/derived-signal': (_) => const DerivedSignalsPage(),
  '/effects': (_) => const EffectsPage(),
  '/dual-signal-builder': (_) => const DualSignalBuilderPage(),
  '/resource': (_) => const ResourcePage(),
  '/solid': (_) => const SolidPage(),
  '/list-signal': (_) => const ListSignalPage(),
  '/set-signal': (_) => const SetSignalPage(),
  '/map-signal': (_) => const MapSignalPage(),
};
final routeToNameRegex = RegExp('(?:^/|-)([a-z])');

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

  @override
  Widget build(BuildContext context) {
    final keys = routes.keys;
    return Scaffold(
      appBar: AppBar(title: const Text('Solidart showcase')),
      body: ListView.builder(
        itemCount: routes.length,
        itemBuilder: (BuildContext context, int index) {
          final route = keys.elementAt(index);

          final name = route.replaceAllMapped(
            routeToNameRegex,
            (match) => match.group(0)!.substring(1).toUpperCase(),
          );

          return ListTile(
            title: Text(name),
            onTap: () {
              Navigator.of(context).pushNamed(route);
            },
          );
        },
      ),
    );
  }
}
55
likes
150
pub points
83%
popularity

Publisher

verified publishermariuti.com

A simple State Management solution for Flutter applications inspired by SolidJS

Repository (GitHub)
View/report issues

Topics

#state-management #signals

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

collection, flutter, meta, solidart

More

Packages that depend on flutter_solidart