bolter_flutter 7.0.7 copy "bolter_flutter: ^7.0.7" to clipboard
bolter_flutter: ^7.0.7 copied to clipboard

discontinuedreplaced by: bolter

based on bolter library extensions for manage widgets updates

example/lib/main.dart

import 'dart:async';
import 'dart:math';

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

void main() {
  kProfileBolterPerformanceLogging = true;
  runApp(const MyApp2());
}

class CounterPresenter extends Presenter<CounterPresenter> {
  int _counter = 0;

  int get counter => _counter;

  void incrementCounter() {
    perform(action: () => _counter++);
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Counter App',
      home: PresenterProvider<CounterPresenter>(
        presenter: CounterPresenter(),
        child: const MyHomePage(),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    final presenter = PresenterProvider.of<CounterPresenter>(context);

    return Scaffold(
      appBar: AppBar(title: const Text('Counter App')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('You have pushed the button this many times:'),
            BolterBuilder<int>(
              getter: () => presenter.counter,
              builder: (context, counter) => Text(
                '$counter',
                style: Theme.of(context).textTheme.headline4,
              ),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: presenter.incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}

//Performance
class GridPresenter extends Presenter<GridPresenter> {
  final grid = List.generate(
    10,
    (i) => List.generate(
      10,
      (j) => 0,
    ),
  );

  @override
  FutureOr<void> onLayout() {
    _startUpdatingGrid();
  }

  void _startUpdatingGrid() {
    Timer.periodic(
      const Duration(milliseconds: 100),
      (timer) {
        perform(action: () {
          for (int row = 0; row < 10; row++) {
            for (int col = 0; col < 10; col++) {
              grid[row][col] = Random().nextInt(1000);
            }
          }
        });
      },
    );
  }
}

class MyApp2 extends StatelessWidget {
  const MyApp2({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // showPerformanceOverlay: true,
      home: PresenterProvider(
        presenter: GridPresenter(),
        child: const MyHomePage2(),
      ),
    );
  }
}

class MyHomePage2 extends StatelessWidget {
  const MyHomePage2({super.key});

  @override
  Widget build(BuildContext context) {
    final presenter = context.presenter<GridPresenter>();

    return Scaffold(
      appBar: AppBar(
        title: const Text('Bolter Demo'),
      ),
      body: GridView.builder(
        addAutomaticKeepAlives: false,
        addRepaintBoundaries: false,
        addSemanticIndexes: false,
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
          crossAxisCount: 10,
          childAspectRatio: 1.0,
        ),
        itemCount: 100,
        itemBuilder: (context, index) {
          int row = index ~/ 10;
          int col = index % 10;

          return BolterBuilder<int>(
            getter: () => presenter.grid[row][col],
            builder: (context, value) {
              return GridTile(
                child: Card(
                  color: Colors.blue,
                  child: Center(
                    child: Text(
                      '$value',
                      style: const TextStyle(fontSize: 20, color: Colors.white),
                    ),
                  ),
                ),
              );
            },
          );
        },
      ),
    );
  }
}
4
likes
80
pub points
29%
popularity

Publisher

verified publisherrenesanse.net

based on bolter library extensions for manage widgets updates

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

bolter, flutter

More

Packages that depend on bolter_flutter