|
| 1 | +import 'package:animated_icon_button/animated_icon_button.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:simple_icons/simple_icons.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + runApp(MyApp()); |
| 7 | +} |
| 8 | + |
| 9 | +class MyApp extends StatelessWidget { |
| 10 | + @override |
| 11 | + Widget build(BuildContext context) { |
| 12 | + return MaterialApp( |
| 13 | + debugShowCheckedModeBanner: false, |
| 14 | + theme: ThemeData( |
| 15 | + brightness: Brightness.dark, |
| 16 | + primaryColor: Colors.greenAccent, |
| 17 | + ), |
| 18 | + home: MyHomePage(), |
| 19 | + ); |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +class MyHomePage extends StatefulWidget { |
| 24 | + @override |
| 25 | + _MyHomePageState createState() => _MyHomePageState(); |
| 26 | +} |
| 27 | + |
| 28 | +class _MyHomePageState extends State<MyHomePage> |
| 29 | + with SingleTickerProviderStateMixin { |
| 30 | + late AnimationController _progressBorderAc; |
| 31 | + late Animation<double> animation; |
| 32 | + var _selectedIndex = 0; |
| 33 | + var _reverse = false; |
| 34 | + |
| 35 | + @override |
| 36 | + void initState() { |
| 37 | + _progressBorderAc = AnimationController( |
| 38 | + vsync: this, |
| 39 | + duration: const Duration(milliseconds: 300), |
| 40 | + ); |
| 41 | + final tween = Tween<double>( |
| 42 | + begin: 25.0, |
| 43 | + end: 50.0, |
| 44 | + ); |
| 45 | + animation = tween.animate(_progressBorderAc) |
| 46 | + ..addStatusListener((state) => print('$state')); |
| 47 | + |
| 48 | + super.initState(); |
| 49 | + } |
| 50 | + |
| 51 | + @override |
| 52 | + Widget build(BuildContext context) { |
| 53 | + final Size size = MediaQuery.of(context).size; |
| 54 | + return Material( |
| 55 | + color: const Color(0xFF212121), |
| 56 | + child: Center( |
| 57 | + child: AnimatedBuilder( |
| 58 | + builder: (BuildContext context, Widget? child) { |
| 59 | + return Container( |
| 60 | + decoration: BoxDecoration( |
| 61 | + borderRadius: BorderRadius.circular(100), |
| 62 | + boxShadow: [ |
| 63 | + BoxShadow( |
| 64 | + color: color.withOpacity( |
| 65 | + animation.value / 100 * 2, |
| 66 | + ), |
| 67 | + blurRadius: animation.value, |
| 68 | + ) |
| 69 | + ], |
| 70 | + ), |
| 71 | + child: AnimatedIconButton( |
| 72 | + size: size.width * 0.25, |
| 73 | + onPressed: () async { |
| 74 | + setIndex(); |
| 75 | + await _progressBorderAc.forward(); |
| 76 | + await _progressBorderAc.reverse(); |
| 77 | + }, |
| 78 | + duration: const Duration(milliseconds: 300), |
| 79 | + icons: <AnimatedIconItem>[ |
| 80 | + AnimatedIconItem( |
| 81 | + icon: Icon(SimpleIcons.amd, color: color), |
| 82 | + backgroundColor: Colors.white, |
| 83 | + ), |
| 84 | + AnimatedIconItem( |
| 85 | + icon: Icon(SimpleIcons.nasa, color: color), |
| 86 | + backgroundColor: Colors.white, |
| 87 | + ), |
| 88 | + AnimatedIconItem( |
| 89 | + icon: Icon(SimpleIcons.intel, color: color), |
| 90 | + backgroundColor: Colors.white, |
| 91 | + ), |
| 92 | + AnimatedIconItem( |
| 93 | + icon: Icon(SimpleIcons.man, color: color), |
| 94 | + backgroundColor: Colors.white, |
| 95 | + ), |
| 96 | + AnimatedIconItem( |
| 97 | + icon: Icon(SimpleIcons.acer, color: color), |
| 98 | + backgroundColor: Colors.white, |
| 99 | + ), |
| 100 | + AnimatedIconItem( |
| 101 | + icon: Icon(SimpleIcons.travisci, color: color), |
| 102 | + backgroundColor: Colors.white, |
| 103 | + ), |
| 104 | + AnimatedIconItem( |
| 105 | + icon: Icon(SimpleIcons.ea, color: color), |
| 106 | + backgroundColor: Colors.white, |
| 107 | + ), |
| 108 | + AnimatedIconItem( |
| 109 | + icon: Icon(SimpleIcons.dior, color: color), |
| 110 | + backgroundColor: Colors.white, |
| 111 | + ), |
| 112 | + ], |
| 113 | + ), |
| 114 | + ); |
| 115 | + }, |
| 116 | + animation: animation, |
| 117 | + ), |
| 118 | + ), |
| 119 | + ); |
| 120 | + } |
| 121 | + |
| 122 | + void setIndex() { |
| 123 | + if (_selectedIndex < 7) { |
| 124 | + setState(() => _selectedIndex += 1); |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | + Color get color { |
| 129 | + switch (_selectedIndex) { |
| 130 | + case 0: |
| 131 | + return Colors.red; |
| 132 | + case 1: |
| 133 | + return Colors.orange; |
| 134 | + case 2: |
| 135 | + return Colors.yellow; |
| 136 | + case 3: |
| 137 | + return Colors.green; |
| 138 | + case 4: |
| 139 | + return Colors.indigo; |
| 140 | + case 5: |
| 141 | + return Colors.blue; |
| 142 | + case 6: |
| 143 | + return Colors.purple; |
| 144 | + default: |
| 145 | + return Colors.pink; |
| 146 | + } |
| 147 | + } |
| 148 | +} |
0 commit comments