Skip to content

Instantly share code, notes, and snippets.

@atreeon
Created July 26, 2018 08:07
Show Gist options
  • Save atreeon/dcf5079d3438952d68de38aecc9a97af to your computer and use it in GitHub Desktop.
Save atreeon/dcf5079d3438952d68de38aecc9a97af to your computer and use it in GitHub Desktop.
Text and Dropdown, changing focus
import 'package:flutter/material.dart';
class TextAndDropdown extends StatefulWidget {
@override
_TextAndDropdownState createState() => _TextAndDropdownState();
}
class _TextAndDropdownState extends State<TextAndDropdown> {
int selectedDropdown;
String selectedText;
final textController = new TextEditingController();
@override
void initState() {
super.initState();
selectedDropdown = 1;
textController.addListener(() => print(''));
}
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Text and dropdown'),
),
body: Container(
child: Column(
children: [
Padding(
padding: EdgeInsets.all(10.0),
),
DropdownButton(value: selectedDropdown, onChanged: _dropdownChange, items: [
DropdownMenuItem(
child: Text('First'),
value: 1,
),
DropdownMenuItem(child: Text('Seconds')),
]),
TextField(controller: textController),
],
),
),
);
}
void _dropdownChange(val) {
setState(() {
selectedDropdown = val;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment