djinn_flutter 0.3.0

Flutter Android iOS web

Application state management, using class inheritance to create services.

example/lib/main.dart

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

import 'counter_service.dart';

void main() {
  Djinn().register(() => CounterService());
  Djinn().init();

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Counter'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final CounterService counter = Djinn().get();

  @override
  void initState() {
    super.initState();
    counter.listen(this);
  }

  @override
  void dispose() {
    counter.dispose(this);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '${counter.state.count}',
              style: Theme.of(context).textTheme.display1,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: counter.increment,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}
0
likes
80
pub points
0%
popularity

Application state management, using class inheritance to create services.

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

gilmarsquinelato@gmail.com

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on djinn_flutter