Skip to content

Instantly share code, notes, and snippets.

@shihaohong
Last active February 7, 2020 21:21
Show Gist options
  • Save shihaohong/14e8990fc6e8b52fcb7f8ff3bda8ecb7 to your computer and use it in GitHub Desktop.
Save shihaohong/14e8990fc6e8b52fcb7f8ff3bda8ecb7 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
const List<String> items = <String>[
'one',
'two',
'three',
];
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
MediaQueryData mediaQuery;
String item = items[0];
@override
Widget build(BuildContext context) {
return MaterialApp(
builder: (BuildContext context, Widget child) {
if (mediaQuery == null)
mediaQuery = MediaQuery.of(context);
return MediaQuery(
data: mediaQuery,
child: child,
);
},
home: Scaffold(
appBar: AppBar(title: Text('My App')),
body: DropdownButton(
value: item,
items: items.map((String item) => DropdownMenuItem(
value: item,
child: Text(item),
)).toList(),
onChanged: (String newItem) {
setState(() {
item = newItem;
mediaQuery = mediaQuery.copyWith(
textScaleFactor: mediaQuery.textScaleFactor + 0.1,
);
});
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment