Last active
December 19, 2023 10:13
-
-
Save aloisdeniel/de84051b2c37c066f23b46d1fbfd2c75 to your computer and use it in GitHub Desktop.
FittedBox
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'; | |
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