Last active
May 3, 2023 12:15
-
-
Save DaisukeNagata/1175b1fa039659c5b61c43512d0008c7 to your computer and use it in GitHub Desktop.
All Devices Aspect Ratio
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(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
home: Scaffold( | |
body: Container( | |
color: Colors.blueGrey[200], | |
child: Center( | |
child: FractionallySizedBox( | |
widthFactor: 0.8, | |
heightFactor: 0.4, | |
child: Container( | |
alignment: Alignment.center, | |
color: Colors.orange, | |
child: _aspectRatio()), | |
), | |
), | |
), | |
), | |
); | |
} | |
Widget _aspectRatio() { | |
return AspectRatio( | |
aspectRatio: 16 / 9, | |
child: Container( | |
alignment: Alignment.center, | |
color: Colors.green, | |
child: const Text( | |
'16:9 Aspect Ratio', | |
style: TextStyle( | |
color: Colors.white, | |
fontSize: 24, | |
), | |
), | |
), | |
); | |
} | |
} |
Author
DaisukeNagata
commented
May 3, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment