felangel / flow_builder

Flutter Flows made easy! A Flutter package which simplifies navigation flows with a flexible, declarative API.
https://pub.dev/packages/flow_builder
MIT License
390 stars 64 forks source link

Added onPop callback #11

Closed magicleon94 closed 3 years ago

magicleon94 commented 3 years ago

Status

READY

Breaking Changes

NO

Description

This callback gets called whenever a page is popped and can be used to notify the state manager that something has occurred. An example of how it can be used with bloc can be found here.

Type of Change

felangel commented 3 years ago

@magicleon94 closing this in favor of exposing a public FlowController which you can use to notify others of changes in the flow state

class _MyWidgetState extends State<MyWidget> {
  FlowController<MyFlowState> _controller;

  @override
  void initState() {
    super.initState();
    _controller = FlowController(MyFlowState.initial())..addListener(_onFlowStateChanged);
  }

  void _onFlowStateChanged() {
    final state = context.flow<MyFlowState>().state;
    // notify other components of a change in flow state
  }

  @override
  Widget build(BuildContext context) {
    return FlowBuilder(
      controller: _controller,
      onGeneratePages: ...,
    );
  }

  @override
  void dispose() {
    _controller
      ..removeListener(_onFlowStateChanged)
      ..dispose();
    super.dispose();
  }
}

Hope that helps ๐Ÿ‘

magicleon94 commented 3 years ago

I think this is gonna help for sure! Thank you a lot for this!