Skip to content

Instantly share code, notes, and snippets.

@xsahil03x
Last active May 19, 2023 09:30
Show Gist options
  • Save xsahil03x/7285e31652d1a0a9a1ca830b86e2f493 to your computer and use it in GitHub Desktop.
Save xsahil03x/7285e31652d1a0a9a1ca830b86e2f493 to your computer and use it in GitHub Desktop.
Aspect Ratio Expands
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
final String title;
const MyHomePage({
Key? key,
required this.title,
}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(
minWidth: 170,
maxWidth: 256,
minHeight: 100,
maxHeight: 300,
),
child: AspectRatio(
aspectRatio: 1,
child: Container(
color: Colors.red,
height: 50,
width: 50,
),
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment