Skip to content

Instantly share code, notes, and snippets.

@maheshmnj
Last active May 31, 2023 11:53
Show Gist options
  • Save maheshmnj/05c40d6ec34b3dce935bd984c5bda199 to your computer and use it in GitHub Desktop.
Save maheshmnj/05c40d6ec34b3dce935bd984c5bda199 to your computer and use it in GitHub Desktop.
workaround show hint and selectedItemBuilder together
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
void _incrementCounter() {
setState(() {});
}
List<String> options = <String>['One', 'Two', 'Free', 'Four'];
String? dropdownValue;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
DropdownButton<String>(
value: dropdownValue,
style: const TextStyle(color: Colors.grey, fontSize: 15),
hint: dropdownValue != null
? null
: const Text(
'Select Value',
style: TextStyle(color: Colors.black),
),
onChanged: (value) => setState(() => dropdownValue = value),
selectedItemBuilder: dropdownValue == null
? null
: (BuildContext context) {
return ['ONE', 'TWO.', 'THREE'].map((String value) {
return Text(
dropdownValue!,
style: const TextStyle(color: Colors.green),
);
}).toList();
},
items: ['ONE', 'TWO.', 'THREE']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value,
style:
const TextStyle(inherit: false, color: Colors.red)),
);
}).toList(),
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment