-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from kaushal1717/Animated-Buttons-Branch
[Buttons Done] Animated Buttons
- Loading branch information
Showing
4 changed files
with
201 additions
and
18 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
lib/ui_components/buttons/all_buttons/animated_button/button11.dart
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class Button11 extends StatefulWidget { | ||
final String title; | ||
const Button11(this.title, {super.key}); | ||
|
||
@override | ||
State<Button11> createState() => _Button11State(); | ||
} | ||
|
||
class _Button11State extends State<Button11> { | ||
bool _isLoading = false; | ||
@override | ||
Widget build(BuildContext context) { | ||
return ElevatedButton( | ||
onPressed: () async { | ||
setState(() => _isLoading = true); | ||
await Future.delayed(const Duration(seconds: 3)); | ||
setState(() => _isLoading = false); | ||
}, | ||
style: ElevatedButton.styleFrom( | ||
backgroundColor: const Color.fromARGB(255, 0, 194, 203), | ||
fixedSize: const Size(100, 60), | ||
shape: | ||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(50))), | ||
child: _isLoading | ||
// ignore: sized_box_for_whitespace | ||
? Container( | ||
width: 200, | ||
height: 60, | ||
child: Row( | ||
children: const [ | ||
CircularProgressIndicator(color: Colors.white), | ||
SizedBox(width: 30), | ||
Text('Please wait...', | ||
style: TextStyle( | ||
fontSize: 20, | ||
// fontWeight: FontWeight.w600, | ||
color: Color.fromARGB(255, 255, 255, 255))) | ||
], | ||
), | ||
) | ||
: Text(widget.title, | ||
style: const TextStyle( | ||
fontSize: 20, | ||
// fontWeight: FontWeight.w600, | ||
color: Color.fromARGB(255, 255, 255, 255))), | ||
); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
lib/ui_components/buttons/all_buttons/animated_button/button12.dart
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
enum ButtonState { init, loading, done } | ||
|
||
class Button12 extends StatefulWidget { | ||
final String title; | ||
const Button12(this.title, {super.key}); | ||
@override | ||
Button12State createState() => Button12State(); | ||
} | ||
|
||
class Button12State extends State<Button12> { | ||
bool _isAnimating = true; | ||
ButtonState state = ButtonState.init; | ||
@override | ||
Widget build(BuildContext context) { | ||
var width = MediaQuery.of(context).size.width; | ||
bool isStretched = _isAnimating || state == ButtonState.init; | ||
bool isDone = state == ButtonState.done; | ||
return AnimatedContainer( | ||
duration: const Duration(milliseconds: 300), | ||
curve: Curves.easeIn, | ||
alignment: Alignment.center, | ||
width: state == ButtonState.init ? width : 100, | ||
height: 70, | ||
onEnd: () => setState(() => _isAnimating = !_isAnimating), | ||
child: isStretched ? buildButton() : smallButton(isDone), | ||
); | ||
} | ||
|
||
Widget buildButton() => ElevatedButton( | ||
onPressed: () async { | ||
setState(() => state = ButtonState.loading); | ||
await Future.delayed(const Duration(seconds: 3)); | ||
setState(() => state = ButtonState.done); | ||
await Future.delayed(const Duration(seconds: 3)); | ||
setState(() => state = ButtonState.init); | ||
}, | ||
style: ElevatedButton.styleFrom( | ||
backgroundColor: const Color.fromARGB(255, 0, 194, 203), | ||
fixedSize: const Size(100, 60), | ||
shape: RoundedRectangleBorder( | ||
borderRadius: BorderRadius.circular(50))), | ||
child: Text(widget.title, | ||
style: const TextStyle( | ||
fontSize: 20, | ||
fontWeight: FontWeight.w600, | ||
color: Color.fromARGB(255, 255, 255, 255))), | ||
); | ||
Widget smallButton(bool isDone) { | ||
final color = | ||
isDone ? Colors.green : const Color.fromARGB(255, 0, 194, 203); | ||
return Container( | ||
height: 55, | ||
decoration: BoxDecoration(color: color, shape: BoxShape.circle), | ||
child: Center( | ||
child: isDone | ||
? const Icon( | ||
Icons.done, | ||
color: Colors.white, | ||
size: 45, | ||
) | ||
: const CircularProgressIndicator( | ||
color: Colors.white, | ||
)), | ||
); | ||
} | ||
} |
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
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