Skip to content

External control

Ismael Shakverdiev edited this page Mar 15, 2022 · 3 revisions

The one of the best feature of the FieldSuggestion widget is that, you can control it externally.

  • Create the box controller instance.
final _boxController = BoxController();
  • Then pass it to your FieldSuggestion.
FieldSuggestion(
  boxController: _boxController,
  ...
),      
  • Now you can use boxController as the way you want. you can open the box or close the box or even refresh the state of the box.

Here we just wrapped our Scaffold with GestureDetector to handle random gestures on the screen. So, now we can close the box when we tap on the screen.

 class Example extends StatelessWidget {
   final _boxController = BoxController();
 
   @override
   Widget build(BuildContext context) {
     return GestureDetector(
       onTap: () => _boxController.close?.call(),
       child: Scaffold( 
         body: Center(
           child: FieldSuggestion(
             boxController: _boxController,
             ...
           ),
         ),
       ),
     );
   }
 }
Clone this wiki locally