Last active
February 7, 2020 21:21
-
-
Save shihaohong/14e8990fc6e8b52fcb7f8ff3bda8ecb7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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