reactive_cubit 0.0.8 copy "reactive_cubit: ^0.0.8" to clipboard
reactive_cubit: ^0.0.8 copied to clipboard

State Management

example/lib/main.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:reactive_cubit/reactive_cubit.dart';


import 'multiple_cubit_provider_example.dart';
import 'single_cubit_provider_example.dart';

class MyObserver extends StateObserver {
  @override
  void onStateChanged<C extends RxCubit>(
      C cubit, dynamic previousState, dynamic newState) {
    if (kDebugMode) {
      print(
          '[${cubit.runtimeType}] State changed from $previousState to $newState');
    }
  }

  @override
  void onError<C extends RxCubit>(
      C cubit, Object error, StackTrace stackTrace) {
    if (kDebugMode) {
      print('[${cubit.runtimeType}] Error: $error');
    }
  }
}

void main() {
  runApp(
    RxCubitScope(
      observer: MyObserver(),
      child: const MyApp(),
    ),
  );
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

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

class HomeScreen extends StatefulWidget {
  const HomeScreen({Key? key}) : super(key: key);

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  int _currentIndex = 0;

  // Danh sách các màn hình mà BottomNavigationBar sẽ điều hướng tới
  final List<Widget> _pages = [
    const SingleCubitExample(),
    const MultiCubitExample(),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Navigation Example'),
      ),
      body: IndexedStack(
        index: _currentIndex,
        children: _pages,
      ),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex,
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
        items: const [
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            label: 'SSE',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.settings),
            label: 'MTS',
          ),
        ],
      ),
    );
  }
}
1
likes
150
points
37
downloads

Publisher

unverified uploader

Weekly Downloads

State Management

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, rxdart

More

Packages that depend on reactive_cubit