Skip to content

Instantly share code, notes, and snippets.

@trunghieuvn
Created December 15, 2018 15:32
Show Gist options
  • Save trunghieuvn/48e12c9bfebd92dd9674050bc530b258 to your computer and use it in GitHub Desktop.
Save trunghieuvn/48e12c9bfebd92dd9674050bc530b258 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
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> {
int _counter = 0;
MediaQueryData queryData;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
queryData = MediaQuery.of(context);
double devicePixelRatio = queryData.devicePixelRatio;
TextStyle style38 = new TextStyle(
inherit: true,
// fontSize: 38.0 ,
fontSize: 38.0 / (queryData.textScaleFactor),
);
TextStyle style20 = new TextStyle(
inherit: true,
// fontSize: 20.0,
fontSize: 20.0/ (queryData.textScaleFactor),
);
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
body: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
new Text(
'Button tapped $_counter time${ _counter == 1 ? '' : 's' }.',
style: style38 ,
),
new Text(
'devicePixelRatio $devicePixelRatio ',
style: style38 ,
),
new Text(
'size (pixels): w=${queryData.size.width * devicePixelRatio}, h=${queryData.size.height * devicePixelRatio}',
style: style20,
),
new Text(
'devicePixelRatio: $devicePixelRatio',
style: style20,
),
new Text(
'size: w=${queryData.size.width}, h=${queryData.size.height}',
style: style20,
),
new Text(
'textScaleFactor: w=${queryData.textScaleFactor}',
style: style20,
),
],
),
floatingActionButton: new FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: new Icon(Icons.add),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment