arctium 0.2.0
arctium: ^0.2.0 copied to clipboard

Reliable UI-oriented service locator with great performance, Widget lifecycle bindings, queued auto disposal and useful UI integrations.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) => MaterialApp(
        home: CounterScreen(),
      );
}

abstract class CounterService extends Disposable {
  ValueNotifier<int> get counterValue;
}

class CounterServiceImplementation extends CounterService {
  @override
  final counterValue = ValueNotifier(0);

  @override
  void onDispose() => counterValue.dispose();
}

class CounterScreen extends StatelessWidget {
  @override
  Widget build(BuildContext context) => Injector<CounterService>(
        service: () => CounterServiceImplementation(),
        builder: (context, service) => CounterBody(),
      );
}

class CounterBody extends LocatorWidget<CounterService> {
  const CounterBody();
  @override
  Widget build(BuildContext context, CounterService service) => Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              ValueListenableBuilder(
                valueListenable: service.counterValue,
                builder: (_, value, __) => Text(value.toString()),
              ),
              OutlinedButton(
                onPressed: () => service.counterValue.value++,
                child: Text("Increment"),
              ),
            ],
          ),
        ),
      );
}
5
likes
120
pub points
59%
popularity

Publisher

looksgood.app

Reliable UI-oriented service locator with great performance, Widget lifecycle bindings, queued auto disposal and useful UI integrations.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on arctium