mounted_state 1.0.1 copy "mounted_state: ^1.0.1" to clipboard
mounted_state: ^1.0.1 copied to clipboard

Easily check if a widget is mounted before calling setState.

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'mounted_state Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

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

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage>
    with MountedState, MountedStateOverride {
  void _setStateOverride() {
    setState(() {
      // This will use MountedStateOverride
    });
  }

  void _setState() {
    setMountedState(() {
      // This will use MountedState
    });
  }

  @override
  Widget build(BuildContext context) {
    return const SizedBox();
  }
}
0
likes
140
pub points
70%
popularity

Publisher

verified publisherglennruysschaert.com

Easily check if a widget is mounted before calling setState.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter

More

Packages that depend on mounted_state