4

Greetings to all the devs who contribute their knowledge to beginners, I would like to know how I can make a button that will be hosted in the appBar and that when I touch it it shows some options, which have an icon and a text, and when I touch one of those options that I send to a new view, as shown in the following image.

enter image description here

3 Answers3

2

Learn more about DropdownButton

This is just a example, tested in DartPad:

import 'package:flutter/material.dart';

void main() =>
    runApp(MaterialApp(home: MyHomePage(), debugShowCheckedModeBanner: false));

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

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String dropdownValue = 'One';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("ExampleDropDown"),
        actions: [
          DropdownButton(
            icon: Icon(Icons.arrow_downward),
            onChanged: (String? newValue) {
              setState(() {
                dropdownValue = newValue!;
              });
            },
            items: <String>['One', 'Two', 'Free', 'Four']
                .map<DropdownMenuItem<String>>(
              (String value) {
                return DropdownMenuItem<String>(
                  value: value,
                  child: Text(value),
                );
              },
            ).toList(),
          ),
        ],
      ),
      body: Center(child: Text("Example")),
    );
  }
}

Lucas Josino
  • 820
  • 1
  • 4
  • 14
0

result here -> https://stackoverflow.com/a/66602001/17798537

Using PopupMenuButton

-1

Here is the example that you can replace with IconButton

DropdownButton(
        icon: Icon(Icons.more_vert_sharp),
        onChanged: (String? newValue) {
          setState(() {
            dropdownValue = newValue!;
          });
        },
        items: <String>['One', 'Two', 'Free', 'Four']
            .map<DropdownMenuItem<String>>(
          (String value) {
            return DropdownMenuItem<String>(
              value: value,
              child: Text(value),
            );
          },
        ).toList(),
      ),
Pratik Butani
  • 60,504
  • 58
  • 273
  • 437