Skip to content

Commit

Permalink
Merge pull request #238 from kaushal1717/Animated-Buttons-Branch
Browse files Browse the repository at this point in the history
[Buttons Done] Animated Buttons
  • Loading branch information
Debajyoti14 authored Jun 7, 2023
2 parents fbf64d4 + 7a3683c commit a66e677
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 18 deletions.
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))),
);
}
}
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,
)),
);
}
}
67 changes: 66 additions & 1 deletion lib/ui_components/buttons/buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import 'package:flutter_component_ui/ui_components/buttons/all_buttons/elevated_
import 'package:flutter_component_ui/ui_components/buttons/all_buttons/elevated_button/button5.dart';
import 'package:flutter_component_ui/ui_components/buttons/all_buttons/text_button/button6.dart';
import 'package:provider/provider.dart';

import '../../theme/theme.dart';
import 'all_buttons/animated_button/button11.dart';
import 'all_buttons/animated_button/button12.dart';
import 'all_buttons/elevated_button/button7.dart';
import 'all_buttons/outline_button/button10.dart';
import 'all_buttons/outline_button/button2.dart';
Expand Down Expand Up @@ -47,6 +48,13 @@ class _ButtonScreenState extends State<ButtonScreen> {
];
List<int> customTextButtonIndex = [9];

final List<Widget> customAnimatedButton = [
const Button11("button"),
const Button12("button"),
];

List<Color?> customAnimatedButtonColor = [null, null];

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down Expand Up @@ -229,6 +237,63 @@ class _ButtonScreenState extends State<ButtonScreen> {
),
),
),
Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Animated Buttons",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: MyTheme.lightBluishColor)),
),
),
Wrap(
direction: Axis.horizontal,
children: List.generate(
customAnimatedButton.length,
(index) => Consumer<FavoritesProvider>(
builder: (context, favProviderModel, child) => Column(
children: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8,
),
width: double.infinity,
child: customAnimatedButton[index],
),
Padding(
padding: const EdgeInsets.fromLTRB(0, 3, 20, 3),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('Add to favorite'),
const SizedBox(
width: 5,
),
GestureDetector(
onTap: () {
favProviderModel
.add(customTextButtonIndex[index]);
setState(() {
customTextButtonColor[index] = Colors.amber;
});
},
child: Icon(
Icons.star_border_outlined,
color: customAnimatedButtonColor[index],
),
),
],
),
),
],
),
),
),
),
// SizedBox(
// width: (MediaQuery.of(context).size.width / 2 - 20),
// child: ListView.builder(
Expand Down
34 changes: 17 additions & 17 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ packages:
dependency: transitive
description:
name: async
sha256: "947bfcf187f74dbc5e146c9eb9c0f10c9f8b30743e341481c1e2ed3ecc18c20c"
sha256: bfe67ef28df125b7dddcea62755991f807aa39a2492a23e1550161692950bbe0
url: "https://pub.dev"
source: hosted
version: "2.11.0"
version: "2.10.0"
boolean_selector:
dependency: transitive
description:
Expand All @@ -29,10 +29,10 @@ packages:
dependency: transitive
description:
name: characters
sha256: "04a925763edad70e8443c99234dc3328f442e811f1d8fd1a72f1c8ad0f69a605"
sha256: e6a326c8af69605aec75ed6c187d06b349707a27fbff8222ca9cc2cff167975c
url: "https://pub.dev"
source: hosted
version: "1.3.0"
version: "1.2.1"
clipboard:
dependency: "direct main"
description:
Expand All @@ -53,10 +53,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: cfc915e6923fe5ce6e153b0723c753045de46de1b4d63771530504004a45fae0
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.17.0"
crypto:
dependency: transitive
description:
Expand Down Expand Up @@ -188,10 +188,10 @@ packages:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
sha256: "5528c2f391ededb7775ec1daa69e65a2d61276f7552de2b5f7b8d34ee9fd4ab7"
url: "https://pub.dev"
source: hosted
version: "0.6.7"
version: "0.6.5"
lints:
dependency: transitive
description:
Expand All @@ -204,10 +204,10 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: "16db949ceee371e9b99d22f88fa3a73c4e59fd0afed0bd25fc336eb76c198b72"
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.13"
material_color_utilities:
dependency: transitive
description:
Expand All @@ -220,10 +220,10 @@ packages:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: "6c268b42ed578a53088d834796959e4a1814b5e9e164f147f580a386e5decf42"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.8.0"
nested:
dependency: transitive
description:
Expand All @@ -244,10 +244,10 @@ packages:
dependency: transitive
description:
name: path
sha256: "8829d8a55c13fc0e37127c29fedf290c102f4e40ae94ada574091fe0ff96c917"
sha256: db9d4f58c908a4ba5953fcee2ae317c94889433e5024c27ce74a37f94267945b
url: "https://pub.dev"
source: hosted
version: "1.8.3"
version: "1.8.2"
path_provider:
dependency: transitive
description:
Expand Down Expand Up @@ -377,10 +377,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: ad540f65f92caa91bf21dfc8ffb8c589d6e4dc0c2267818b4cc2792857706206
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.4.16"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -478,5 +478,5 @@ packages:
source: hosted
version: "1.0.0"
sdks:
dart: ">=3.0.0-0 <4.0.0"
dart: ">=2.19.0 <3.0.0"
flutter: ">=3.3.0"

0 comments on commit a66e677

Please sign in to comment.