Home > Back-end >  flutter, how to return from List<Widget> for AppBar actions
flutter, how to return from List<Widget> for AppBar actions

Time:12-07

im learning flutter, could you please tell me how to return a Widget from List for two actions of Appbar, thanks a lot!

List<Widget> buildViewingActions(BuildContext context, Event event){
    IconButton(
      icon: const Icon(Icons.edit),
      onPressed: (){
        Get.to(EventCreatingPage(event: event,));
      },
    );
    IconButton(
      icon: const Icon(Icons.delete),
      onPressed: (){
        Get.offAll(CalendarPage());
      },
    );
  //what should I write here?
  }

CodePudding user response:

In order to return the two actions as a list:

List<Widget> buildViewingActions(BuildContext context, Event event){
    return [
      IconButton(
        icon: const Icon(Icons.edit),
        onPressed: (){
          Get.to(EventCreatingPage(event: event,));
        },
      ),
      IconButton(
        icon: const Icon(Icons.delete),
        onPressed: (){
          Get.offAll(CalendarPage());
        },
      ),
    ];
  }

We just surround the items with [] to make them into a list and then we put a return statement before the list

  • Related