basic.dart 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import 'package:flutter/material.dart';
  2. import 'safe_state.dart';
  3. /// A platonic widget that both has state and calls a closure to obtain its child widget.
  4. ///
  5. /// See also:
  6. ///
  7. /// * [Builder], the platonic stateless widget.
  8. class SafeStatefulBuilder extends StatefulWidget {
  9. /// Creates a widget that both has state and delegates its build to a callback.
  10. ///
  11. /// The [builder] argument must not be null.
  12. const SafeStatefulBuilder({
  13. required this.builder,
  14. Key? key,
  15. }) : super(key: key);
  16. /// Called to obtain the child widget.
  17. ///
  18. /// This function is called whenever this widget is included in its parent's
  19. /// build and the old widget (if any) that it synchronizes with has a distinct
  20. /// object identity. Typically the parent's build method will construct
  21. /// a new tree of widgets and so a new Builder child will not be [identical]
  22. /// to the corresponding old one.
  23. final StatefulWidgetBuilder builder;
  24. @override
  25. _SafeStatefulBuilderState createState() => _SafeStatefulBuilderState();
  26. }
  27. class _SafeStatefulBuilderState extends State<SafeStatefulBuilder>
  28. with SafeStateMixin<SafeStatefulBuilder> {
  29. @override
  30. Widget build(BuildContext context) => widget.builder(context, setState);
  31. }