|
| 1 | +import 'package:flutter/material.dart'; |
| 2 | + |
| 3 | +class CirclesHomeWidget extends StatefulWidget { |
| 4 | + @override |
| 5 | + State<StatefulWidget> createState() => _CircleHomeState(); |
| 6 | +} |
| 7 | + |
| 8 | +class _CircleHomeState extends State<CirclesHomeWidget> { |
| 9 | + @override |
| 10 | + Widget build(BuildContext context) { |
| 11 | + return Scaffold( |
| 12 | + body: ScrollableCircleGrid(), |
| 13 | + ); |
| 14 | + } |
| 15 | +} |
| 16 | + |
| 17 | +class ScrollableCircleGrid extends StatefulWidget { |
| 18 | + @override |
| 19 | + _ScrollableCircleGridState createState() => _ScrollableCircleGridState(); |
| 20 | +} |
| 21 | + |
| 22 | +class _ScrollableCircleGridState extends State<ScrollableCircleGrid> { |
| 23 | + int? selectedIndex; |
| 24 | + |
| 25 | + @override |
| 26 | + Widget build(BuildContext context) { |
| 27 | + return GridView.builder( |
| 28 | + gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( |
| 29 | + crossAxisCount: 5, |
| 30 | + childAspectRatio: 1, |
| 31 | + ), |
| 32 | + itemBuilder: (context, index) { |
| 33 | + bool isSelected = selectedIndex == index; |
| 34 | + return GestureDetector( |
| 35 | + onTap: () { |
| 36 | + setState(() { |
| 37 | + selectedIndex = isSelected ? null : index; |
| 38 | + }); |
| 39 | + }, |
| 40 | + child: AnimatedContainer( |
| 41 | + duration: Duration(milliseconds: 300), |
| 42 | + margin: EdgeInsets.all(isSelected ? 8 : 4), |
| 43 | + decoration: BoxDecoration( |
| 44 | + shape: BoxShape.circle, |
| 45 | + color: isSelected ? Colors.white : Colors.grey, |
| 46 | + ), |
| 47 | + child: Center( |
| 48 | + child: Text('Friend $index'), |
| 49 | + ), |
| 50 | + ), |
| 51 | + ); |
| 52 | + }, |
| 53 | + ); |
| 54 | + } |
| 55 | +} |
0 commit comments