rxget 0.1.2 copy "rxget: ^0.1.2" to clipboard
rxget: ^0.1.2 copied to clipboard

A lightweight reactive state management and dependency injection library for Dart and Flutter — pure and minimal.

example/lib/main.dart

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

import 'controller/counter_controller.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'rxget Counter Example',
      home: GetInWidget(
        dependencies: [GetIn(() => CounterController())],
        child: const Home(),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    // 2. Inject the controller into memory
    final controller = Get.find<CounterController>();
    return Scaffold(
      appBar: AppBar(
        title: const Text('rxget Counter App'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text('You have pushed the button this many times:'),
            // 3. Wrap the reactive part with Obx to automatically rebuild when count changes
            Obx(() {
              return Text(
                '${controller.state.count}',
                style: Theme.of(context).textTheme.headlineMedium,
              );
            }),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                // Navigate to another screen without context!
                Navigator.of(context).push(
                  MaterialPageRoute(builder: (context) => const OtherScreen()),
                );
              },
              child: const Text("Go to Other Screen"),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: controller.increment,
        child: const Icon(Icons.add),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    // 4. Find the existing controller in memory
    final controller = Get.find<CounterController>();

    return Scaffold(
      appBar: AppBar(
        title: const Text("Other Screen"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            const Text('The count from the previous screen is:'),
            Obx(
              () => Text(
                '${controller.state.count}',
                style: Theme.of(context).textTheme.headlineMedium,
              ),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: controller.increment,
        child: const Icon(Icons.add),
      ),
    );
  }
}
3
likes
150
points
92
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A lightweight reactive state management and dependency injection library for Dart and Flutter — pure and minimal.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter

More

Packages that depend on rxget