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

Day 8 chat is implemented (KIDS-954) #755

Merged
merged 2 commits into from
May 22, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,68 @@
"main": {
"type": "textMessage",
"side": "interlocutor",
"text": "Hey {lastName} Family. This is a placeholder!",
"text": "You did it {lastName} Family! Through your acts of generosity Tulsa is full of colour again!",
"functionName": "showConfetti",
"next": {
"type": "textMessage",
"type": "imageMessage",
"side": "interlocutor",
"text": "Make a recurring allowance pls pls pls"
"path": "https://givtstoragedebug.blob.core.windows.net/public/cdn/generosity-challenge/Givt_Superhero_THUMBNAILS_011.png",
"mediaSourceType": "network",
"next": {
"type": "textMessage",
"side": "interlocutor",
"text": "You have made a real difference but this isn't the end of your generosity journey",
"next": {
"type": "buttonAnswer",
"side": "user",
"text": "It isn't?",
"answerText": "It isn't?",
"next": {
"type": "textMessage",
"side": "interlocutor",
"text": "No, it's just the beginning. You have built a great habit but you need to keep this going.",
"next": {
"type": "textMessage",
"side": "interlocutor",
"text": "Otherwise we will end up right back where we started!",
"next": {
"type": "buttonAnswer",
"side": "user",
"text": "What shall we do?",
"answerText": "What shall we do?",
"next": {
"type": "textMessage",
"side": "interlocutor",
"text": "Keep helping, keep sharing and keep giving",
"next": {
"type": "imageMessage",
"side": "interlocutor",
"path": "https://givtstoragedebug.blob.core.windows.net/public/cdn/generosity-challenge/Givt_Superhero_THUMBNAILS_012.png",
"mediaSourceType": "network",
"next": {
"type": "textMessage",
"side": "interlocutor",
"text": "And to help you along, I am giving the kids a Wallet",
"next": {
"type": "imageMessage",
"side": "interlocutor",
"path": "assets/images/wallet.svg",
"mediaSourceType": "asset",
"next": {
"type": "buttonAnswer",
"side": "user",
"text": "Show us",
"answerText": "Show us"
}
}
}
}
}
}
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:lottie/lottie.dart';

class ChatConfettiDialog extends StatefulWidget {
const ChatConfettiDialog({
required this.duration,
super.key,
});

final Duration duration;

static Future<void> showChatConfettiDialog(
BuildContext context, {
Duration duration = _defaultDuration,
}) async {
await showDialog<void>(
context: context,
barrierDismissible: false,
barrierColor: Colors.transparent,
builder: (_) => ChatConfettiDialog(duration: duration),
);
}

static const Duration _defaultDuration = Duration(milliseconds: 2000);

@override
State<ChatConfettiDialog> createState() => _ChatConfettiDialogState();
}

class _ChatConfettiDialogState extends State<ChatConfettiDialog> {
@override
void initState() {
super.initState();
_schedulePop();
}

Future<void> _schedulePop() =>
Future.delayed(widget.duration, () => context.pop());

@override
Widget build(BuildContext context) {
return Center(
child: Lottie.asset(
'assets/lotties/confetti.json',
fit: BoxFit.fitWidth,
width: double.infinity,
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:app_settings/app_settings.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:givt_app/app/injection/injection.dart';
import 'package:givt_app/features/children/generosity_challenge_chat/chat_scripts/dialogs/chat_confetti_dialog.dart';
import 'package:givt_app/features/children/generosity_challenge_chat/chat_scripts/utils/chat_script_registration_handler.dart';

enum ChatScriptFunction {
Expand All @@ -12,6 +13,9 @@ enum ChatScriptFunction {
registerUser(
function: _registerUser,
),
showConfetti(
function: _showConfetti,
),
;

const ChatScriptFunction({
Expand Down Expand Up @@ -49,4 +53,11 @@ enum ChatScriptFunction {
) async {
return getIt<ChatScriptRegistrationHandler>().handleRegistration();
}

static Future<bool> _showConfetti(
BuildContext context,
) async {
await ChatConfettiDialog.showChatConfettiDialog(context);
return true;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:givt_app/features/children/generosity_challenge_chat/chat_scripts/widgets/chat_picture.dart';
import 'package:givt_app/utils/utils.dart';
import 'package:go_router/go_router.dart';
import 'package:lottie/lottie.dart';
Expand Down Expand Up @@ -203,8 +203,7 @@ class ChatBubble extends StatelessWidget {
fontSize: 18,
fontFamily: 'Rouna',
fontWeight: FontWeight.w500,
//TODO: replace with secondary20
color: AppTheme.secondary30,
color: AppTheme.secondary20,
),
);
}
Expand All @@ -213,13 +212,12 @@ class ChatBubble extends StatelessWidget {
final Widget child;
switch (mediaType) {
case ChatBubbleMediaType.image:
child = isAssetMedia
? Image.asset(mediaPath, width: width, height: height)
: Image.network(
mediaPath,
width: width,
height: height,
);
child = ChatPicture(
width: width,
height: height,
path: mediaPath,
isAsset: isAssetMedia,
);
case ChatBubbleMediaType.lottie:
child = isAssetMedia
? Lottie.asset(mediaPath, width: width, height: height)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

class ChatPicture extends StatelessWidget {
const ChatPicture({
required this.width,
required this.height,
required this.path,
required this.isAsset,
super.key,
});

final double width;
final double height;
final String path;
final bool isAsset;

bool get isSvg {
// the simpliest solution for now (w/o additional script params)
final pathParts = path.split('.');
return pathParts.isNotEmpty && pathParts.last.contains('svg');
}

Widget _createImage() {
return isAsset
? Image.asset(path, width: width, height: height)
: Image.network(
path,
width: width,
height: height,
);
}

Widget _createSvg() {
return Container(
width: width,
height: height,
color: Colors.white,
// the simpliest solution for now
padding: const EdgeInsets.all(20),
child: isAsset
? SvgPicture.asset(path, width: width, height: height)
: SvgPicture.network(
path,
width: width,
height: height,
),
);
}

@override
Widget build(BuildContext context) => isSvg ? _createSvg() : _createImage();
}