inherited_builder 1.0.1+8 copy "inherited_builder: ^1.0.1+8" to clipboard
inherited_builder: ^1.0.1+8 copied to clipboard

discontinued

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
40
pub points
0%
popularity

Publisher

verified publisherlesnitsky.dev

Autogenerated state management and dependency inhection with inherited widgets

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

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

More

Packages that depend on inherited_builder