Last active
April 25, 2023 00:35
-
-
Save HansMuller/dab66f5d34225ad8499ad285e69b6160 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// https://gist.github.com/HansMuller/dab66f5d34225ad8499ad285e69b6160 | |
// The goal here is for the 'ClipBoxDemo' text widget to appear to scroll upwards | |
// and be clipped by its Container, as the height of its Container is reduced. | |
import 'package:flutter/material.dart'; | |
class ClipBoxDemo extends StatelessWidget { | |
const ClipBoxDemo({ super.key }); | |
static const double titleHeight = 52; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Container( | |
color: Colors.green.withOpacity(0.1), | |
padding: const EdgeInsets.all(100), | |
alignment: Alignment.center, | |
child: Container( | |
color: Colors.green.withOpacity(0.1), | |
constraints: const BoxConstraints(maxHeight: titleHeight), | |
// The child's height shrinks from 52 to 0 as its window height is reduced. | |
child:const ClipRect( | |
clipBehavior: Clip.hardEdge, | |
child: OverflowBox( | |
minHeight: titleHeight, | |
maxHeight: titleHeight, | |
alignment: Alignment.bottomLeft, | |
child: Text('ClipBoxDemo', style: TextStyle(fontSize: 44)), | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
void main() { | |
runApp(const MaterialApp(home: ClipBoxDemo())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment