0

How do I create the following layout in Flutter? . I tried to create it using the dropdown widget. However, I am not able to get this layout.

Is it possible to give me some hints on how active the same layout

Thanks

LAYOUT needed

enter image description here

on click

enter image description here

my Code snippet

Widget _buildHeading() {
    return Padding(
      padding: const EdgeInsets.only(top: 22.5),
      child: Container(
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height * 0.06,
        decoration: BoxDecoration(
          color: Palette.RANDSTAD_DARK_BLUE,
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Padding(
              padding:
                  const EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
              child: Text(
                "text bar",
                style: TextStyle(
                  color: Palette.WHITE,
                  height: 1.2,
                  fontSize: 20.0,
                ),
              ),
            ),

            //added
            Container(
                width: 130.0,
                child: DropdownButton<String>(
                  value: dropdownValue,
                  icon: Icon(Icons.arrow_downward),
                  iconSize: 24,
                  iconEnabledColor: Palette.WHITE,
                  dropdownColor: Palette.RANDSTAD_DARK_BLUE,
                  underline: SizedBox(),
                  onChanged: (String newValue) async {
                    setState(() {
                      dropdownValue = newValue;
                    });
                  },
                  items: <String>[
                    'English',
                    'Spanish',
                    'Dutch',
                    'Polish',
                    "French",
                    "German"
                  ].map<DropdownMenuItem<String>>((String value) {
                    return DropdownMenuItem<String>(
                      value: value,
                      child:
                          Text(value, style: TextStyle(color: Palette.WHITE)),
                    );
                  }).toList(),
                ))
            //end added
          ],
        ),
      ),
    );
  }

1 Answer 1

2

You can use PopUpMenuButton inside AppBar action. The functionality is achieved in my example code below. You can paste it in your main.dart file and run.

Working code:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
    
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Hello World'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);


  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  var language = 'english';

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(title: new Text(widget.title), actions: <Widget>[
        PopupMenuButton(
          child: Row(
            children: [
              Text('$language | '),
              Icon(
                Icons.keyboard_arrow_down,
                color: Colors.white,
              )
            ],
          ),
          onSelected: (value) {
            setState(() {
              language = value;
            });

            print(value);
          },
          itemBuilder: (_) {
            return [
              PopupMenuItem(
                  value: '',
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            'change language',
                            style: TextStyle(
                              fontFamily: 'Roboto',
                              fontWeight: FontWeight.w500,
                              fontSize: 14,
                            ),
                          ),
                          Icon(
                            Icons.keyboard_arrow_up,
                            color: Colors.black,
                          )
                        ],
                      ),
                      Divider(
                        color: Colors.grey,
                        thickness: 2,
                      ),
                    ],
                  )),
              PopupMenuItem(
                value: 'english',
                child: Text(
                  'english',
                  style: TextStyle(
                      fontFamily: 'Roboto',
                      fontWeight: FontWeight.w500,
                      fontSize: 14,
                      color:
                          language == 'english' ? Colors.blue : Colors.black),
                ),
              ),
              PopupMenuItem(
                value: 'espanol',
                child: Text(
                  'espanol',
                  style: TextStyle(
                      fontFamily: 'Roboto',
                      fontWeight: FontWeight.w500,
                      fontSize: 14,
                      color:
                          language == 'espanol' ? Colors.blue : Colors.black),
                ),
              ),
              PopupMenuItem(
                value: 'nederlands',
                child: Text(
                  'nederlands',
                  style: TextStyle(
                      fontFamily: 'Roboto',
                      fontWeight: FontWeight.w500,
                      fontSize: 14,
                      color: language == 'nederlands'
                          ? Colors.blue
                          : Colors.black),
                ),
              ),
              PopupMenuItem(
                value: 'polski',
                child: Text(
                  'polski',
                  style: TextStyle(
                      fontFamily: 'Roboto',
                      fontWeight: FontWeight.w500,
                      fontSize: 14,
                      color: language == 'polski' ? Colors.blue : Colors.black),
                ),
              ),
            ];
          },
        ),
        const SizedBox(
          width: 12,
        )
      ]),
      body: new Center(
        child: Text('DEMO'),
      ),
    );
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.