Skip to content

Instantly share code, notes, and snippets.

@DaisukeNagata
Last active May 3, 2023 12:15
Show Gist options
  • Save DaisukeNagata/1175b1fa039659c5b61c43512d0008c7 to your computer and use it in GitHub Desktop.
Save DaisukeNagata/1175b1fa039659c5b61c43512d0008c7 to your computer and use it in GitHub Desktop.
All Devices Aspect Ratio
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,
),
),
),
);
}
}
@DaisukeNagata
Copy link
Author

スクリーンショット 2023-05-03 18 48 58

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment