flutter_apprun 0.8.0 copy "flutter_apprun: ^0.8.0" to clipboard
flutter_apprun: ^0.8.0 copied to clipboard

A lightweight, easy-to-use, event-driven state management system, highly inspired by AppRun JS

example/flutter_apprun_example.dart

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

int initialState = 0;
int add(int state, int delta) => state + delta;
Map update = {
  'add': add,
  '+1': (state) => add(state, 1),
  '-1': (state) => add(state, -1),
};

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter AppRun Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: HomePage(title: 'Flutter AppRun Demo Home Page'),
    );
  }
}

class HomePage extends AppRunWidget {
  final String title;

  HomePage({super.key, required this.title})
      : super(state: initialState, update: update);

  @override
  Widget build(BuildContext context, state) {
    return Scaffold(
      appBar: AppBar(
        title: Text(title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Text(
              '$state',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
          ],
        ),
      ),
      floatingActionButton: Column(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          FloatingActionButton(
            heroTag: 'minus',
            // onPressed: () => run('add', -1),
            onPressed: () => run('-1'),
            tooltip: 'Decrement',
            child: const Icon(Icons.remove),
          ),
          FloatingActionButton(
            heroTag: 'plus',
            // onPressed: () => run('add', 1),
            onPressed: () => run('+1'),
            tooltip: 'Increment',
            child: const Icon(Icons.add),
          ),
        ],
      ),
    );
  }
}
0
likes
150
pub points
14%
popularity

Publisher

unverified uploader

A lightweight, easy-to-use, event-driven state management system, highly inspired by AppRun JS

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on flutter_apprun