quick_change 1.0.0 copy "quick_change: ^1.0.0" to clipboard
quick_change: ^1.0.0 copied to clipboard

A simple, lightweight quick state-management package for Flutter.

example/lib/main.dart

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

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: CounterScreen(),
    );
  }
}

class CounterScreen extends StatefulWidget {
  const CounterScreen({super.key});

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

class CounterScreenState extends State<CounterScreen> {
  final QuickChangeController<int> counterController = QuickChangeController<int>();


  @override
  void initState() {
  super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Quick_State Example'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            QuickChangeBuilder<int>(
              controller: counterController,
              onLoading: (context) => const CircularProgressIndicator(),
              onData: (context, data) => Text('Counter: $data', style: const TextStyle(fontSize: 24)),
              onError: (context, message) => Text('Error: $message'),
            ),
            ElevatedButton(
              onPressed: () {
                final currentValue = counterController.getCurrentData() ?? 0;
                counterController.setData(currentValue + 1);
               ///test with loading
                //counterController.setLoading();
               //  Future.delayed(const Duration(seconds: 1), () {
               //    final currentValue = counterController.getCurrentData() ?? 0;
               //    counterController.setData(currentValue + 1);
               //  });
              },
              child: const Text('Increment Counter'),
            ),
          ],
        ).quickListen<int>(
          controller: counterController,
          listener: (context, state) {
            if (state is QuickData) {
              ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text('Counter: ${state.data}')),
              );
            }
            if (state is QuickError) {
              ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(content: Text(state.message)),
              );
            }
          },
        ),
      ),
    );
  }
}
1
likes
0
points
27
downloads

Publisher

unverified uploader

Weekly Downloads

A simple, lightweight quick state-management package for Flutter.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on quick_change