Last active
March 23, 2025 14:49
-
-
Save chooyan-eng/f97ab1b5f2398c69548ed8860b794292 to your computer and use it in GitHub Desktop.
A simple demo page of updating box size.
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
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MaterialApp(home: AnimationPage())); | |
} | |
class AnimationPage extends StatefulWidget { | |
const AnimationPage({super.key}); | |
@override | |
State<AnimationPage> createState() => _AnimationPageState(); | |
} | |
class _AnimationPageState extends State<AnimationPage> { | |
double _size = 50; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Stack( | |
children: [ | |
CustomPaint(size: Size.infinite, painter: _GridPainter()), | |
Positioned( | |
left: 20, | |
top: 20, | |
child: Container(width: _size, height: _size, color: Colors.blue), | |
), | |
], | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
setState(() => _size = 100); | |
}, | |
), | |
); | |
} | |
} | |
class _GridPainter extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
final paint = | |
Paint() | |
..color = Colors.grey.withOpacity(0.3) | |
..strokeWidth = 0.5; | |
// Draw vertical lines | |
for (var i = 0.0; i < size.width; i += 10) { | |
canvas.drawLine(Offset(i, 0), Offset(i, size.height), paint); | |
} | |
// Draw horizontal lines | |
for (var i = 0.0; i < size.height; i += 10) { | |
canvas.drawLine(Offset(0, i), Offset(size.width, i), paint); | |
} | |
} | |
@override | |
bool shouldRepaint(covariant CustomPainter oldDelegate) => false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment