arctium 0.2.0 copy "arctium: ^0.2.0" to clipboard
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"),
              ),
            ],
          ),
        ),
      );
}
4
likes
140
points
48
downloads

Publisher

verified publisherlooksgood.app

Weekly Downloads

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

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on arctium