inherited_builder 1.0.1+8
inherited_builder: ^1.0.1+8

Autogenerated state management and dependency inhection with inherited widgets

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:inherited_builder/annotations.dart';

part 'main.g.dart';

void main() => runApp(MyApp());

@Inherited()
class AppState {
  final int count;

  AppState({this.count});
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return AppStateBuilder(
      count: 0,
      child: MaterialApp(
        title: 'Inherited Builder demo',
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: MyHomePage(title: 'Inherited Builder demo'),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final String title;

  const MyHomePage({Key key, this.title}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final appStateProvider = AppStateProvider.of(context);
    final count = appStateProvider.count;

    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '$count',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          appStateProvider.setCount(appStateProvider.count + 1);
        },
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}
1
likes
70
pub points
72%
popularity

Publisher

lesnitsky.dev

Autogenerated state management and dependency inhection with inherited widgets

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

analyzer, build, build_config, code_builder, dart_style, flutter, source_gen

More

Packages that depend on inherited_builder