Skip to content

Instantly share code, notes, and snippets.

@aloisdeniel
Last active December 19, 2023 10:13
Show Gist options
  • Save aloisdeniel/de84051b2c37c066f23b46d1fbfd2c75 to your computer and use it in GitHub Desktop.
Save aloisdeniel/de84051b2c37c066f23b46d1fbfd2c75 to your computer and use it in GitHub Desktop.
FittedBox
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
const availableSizes = <Size?>[
null,
Size(1920, 1080),
Size(720, 480),
];
void main() {
runApp(const Deck());
}
class Deck extends StatefulWidget {
const Deck();
@override
State<Deck> createState() => _DeckState();
}
class _DeckState extends State<Deck> {
int sizeIndex = 0;
@override
Widget build(BuildContext context) {
final size = availableSizes[sizeIndex];
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: GestureDetector(
onTap: () => setState(
() => sizeIndex = (sizeIndex + 1) % availableSizes.length),
child: Center(
child: switch (size) {
null => Slide(),
_ => FittedBox(
child: SizedBox(
width: size.width,
height: size.height,
child: Slide(),
),
),
},
),
),
),
);
}
}
class Slide extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: Center(
child: Text(
'Hello, World!',
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: darkBlue,
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment