Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confetti after order confirmed #823

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 54 additions & 15 deletions mobile/lib/features/trade/order_submission_status_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:confetti/confetti.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

Expand All @@ -9,7 +10,7 @@ enum OrderSubmissionStatusDialogType {
failedSubmit
}

class OrderSubmissionStatusDialog extends StatelessWidget {
class OrderSubmissionStatusDialog extends StatefulWidget {
final String title;
final OrderSubmissionStatusDialogType type;
final Widget content;
Expand All @@ -26,24 +27,47 @@ class OrderSubmissionStatusDialog extends StatelessWidget {
this.insetPadding = const EdgeInsets.all(50),
this.navigateToRoute = ""});

@override
State<OrderSubmissionStatusDialog> createState() => _OrderSubmissionStatusDialog();
}

class _OrderSubmissionStatusDialog extends State<OrderSubmissionStatusDialog> {
late final ConfettiController _confettiController;
Copy link
Contributor

@da-kami da-kami Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓Why are we defining the ConfettiController in the OrderSubmissionStatusDialog and the TradeScreen?

My understanding is that the dialog cannot be closed anymore before we reach the orderFilled state; so I think it should be enough to define the confetti on the OrderSubmissionStatusDialog.

I don't think it's wrong to define it on the underlying Tradescreen as well, but I'm not sure it's necessary.


@override
void initState() {
super.initState();
_confettiController = ConfettiController(duration: const Duration(seconds: 3));
}

@override
void dispose() {
_confettiController.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
bool isPending = type == OrderSubmissionStatusDialogType.successfulSubmit ||
type == OrderSubmissionStatusDialogType.pendingSubmit;
bool isPending = widget.type == OrderSubmissionStatusDialogType.successfulSubmit ||
widget.type == OrderSubmissionStatusDialogType.pendingSubmit;

WidgetsBinding.instance.addPostFrameCallback((_) {
_confettiController.play();
});

Widget closeButton = ElevatedButton(
onPressed: () {
GoRouter.of(context).pop();

if (navigateToRoute.isNotEmpty) {
GoRouter.of(context).go(navigateToRoute);
if (widget.navigateToRoute.isNotEmpty) {
GoRouter.of(context).go(widget.navigateToRoute);
}
},
child: Text(buttonText));
child: Text(widget.buttonText));

AlertDialog dialog = AlertDialog(
icon: (() {
switch (type) {
switch (widget.type) {
case OrderSubmissionStatusDialogType.pendingSubmit:
case OrderSubmissionStatusDialogType.successfulSubmit:
return const Center(
Expand All @@ -55,14 +79,29 @@ class OrderSubmissionStatusDialog extends StatelessWidget {
color: Colors.red,
);
case OrderSubmissionStatusDialogType.filled:
return const Icon(
Icons.check_circle,
color: Colors.green,
);
return Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(
Icons.check_circle,
color: Colors.green,
),
ConfettiWidget(
confettiController: _confettiController,
blastDirectionality: BlastDirectionality.explosive,
maxBlastForce: 10, // set a lower max blast force
minBlastForce: 9, // set a lower min blast force
emissionFrequency: 0.00001,
numberOfParticles: 20, // a lot of particles at once
gravity: 0.2,
shouldLoop: false,
),
]);
}
})(),
title: Text("$title ${(() {
switch (type) {
title: Text("${widget.title} ${(() {
switch (widget.type) {
case OrderSubmissionStatusDialogType.pendingSubmit:
case OrderSubmissionStatusDialogType.successfulSubmit:
return "Pending";
Expand All @@ -73,9 +112,9 @@ class OrderSubmissionStatusDialog extends StatelessWidget {
return "Failure";
}
})()}"),
content: content,
content: widget.content,
actions: isPending ? null : [closeButton],
insetPadding: insetPadding,
insetPadding: widget.insetPadding,
);

// If pending, prevent use of back button
Expand Down
8 changes: 8 additions & 0 deletions mobile/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.0"
confetti:
dependency: "direct main"
description:
name: confetti
sha256: "979aafde2428c53947892c95eb244466c109c129b7eee9011f0a66caaca52267"
url: "https://pub.dev"
source: hosted
version: "0.7.0"
convert:
dependency: transitive
description:
Expand Down
1 change: 1 addition & 0 deletions mobile/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies:
shared_preferences: ^2.1.2
package_info_plus: ^4.0.2
uuid: ^3.0.7
confetti: ^0.7.0
dev_dependencies:
flutter_launcher_icons: ^0.13.1
flutter_test:
Expand Down