Skip to content

Commit

Permalink
Merge pull request #877 from bannzai/fix/ui/mini_currency_unit
Browse files Browse the repository at this point in the history
¥表記を小さくしてみる
  • Loading branch information
bannzai committed Jul 28, 2023
2 parents 9ab0a6c + 297eb61 commit ddefa36
Show file tree
Hide file tree
Showing 4 changed files with 134 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:intl/intl.dart';
import 'package:pilll/components/atoms/color.dart';
import 'package:pilll/components/atoms/font.dart';
import 'package:pilll/components/atoms/text_color.dart';
import 'package:pilll/features/premium_introduction/util/currency.dart';
import 'package:pilll/provider/purchase.dart';
import 'package:purchases_flutter/purchases_flutter.dart';

Expand All @@ -20,8 +21,7 @@ class AnnualPurchaseButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
final monthlyPrice = annualPackage.storeProduct.price / 12;
Locale locale = Localizations.localeOf(context);
final monthlyPriceString = NumberFormat.simpleCurrency(locale: locale.toString(), decimalDigits: 0).format(monthlyPrice);
final monthlyPriceString = removeZero(monthlyPrice);

return GestureDetector(
onTap: () {
Expand Down Expand Up @@ -53,22 +53,70 @@ class AnnualPurchaseButton extends StatelessWidget {
fontWeight: FontWeight.w700,
),
),
Text(
"${annualPackage.storeProduct.priceString}/年",
style: const TextStyle(
color: TextColor.main,
fontFamily: FontFamily.japanese,
fontSize: 16,
fontWeight: FontWeight.w600,
RichText(
text: TextSpan(
children: [
TextSpan(
text: currencySymbol(context),
style: const TextStyle(
color: TextColor.main,
fontFamily: FontFamily.japanese,
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
TextSpan(
text: "${removeZero(annualPackage.storeProduct.price)}/年",
style: const TextStyle(
color: TextColor.main,
fontFamily: FontFamily.japanese,
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
],
),
),
Text(
"($monthlyPriceString/月)",
style: const TextStyle(
color: TextColor.main,
fontFamily: FontFamily.japanese,
fontSize: 14,
fontWeight: FontWeight.w600,
RichText(
text: TextSpan(
children: [
const TextSpan(
text: "(",
style: TextStyle(
color: TextColor.main,
fontFamily: FontFamily.japanese,
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
TextSpan(
text: currencySymbol(context),
style: const TextStyle(
color: TextColor.main,
fontFamily: FontFamily.japanese,
fontSize: 10,
fontWeight: FontWeight.w600,
),
),
TextSpan(
text: "$monthlyPriceString/月",
style: const TextStyle(
color: TextColor.main,
fontFamily: FontFamily.japanese,
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
const TextSpan(
text: ")",
style: TextStyle(
color: TextColor.main,
fontFamily: FontFamily.japanese,
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
],
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:pilll/components/atoms/color.dart';
import 'package:pilll/components/atoms/font.dart';
import 'package:pilll/components/atoms/text_color.dart';
import 'package:pilll/features/premium_introduction/util/currency.dart';
import 'package:purchases_flutter/purchases_flutter.dart';

class MonthlyPurchaseButton extends StatelessWidget {
Expand Down Expand Up @@ -42,13 +43,28 @@ class MonthlyPurchaseButton extends StatelessWidget {
fontWeight: FontWeight.w700,
),
),
Text(
"${monthlyPackage.storeProduct.priceString}/月",
style: const TextStyle(
color: TextColor.main,
fontFamily: FontFamily.japanese,
fontSize: 16,
fontWeight: FontWeight.w600,
RichText(
text: TextSpan(
children: [
TextSpan(
text: currencySymbol(context),
style: const TextStyle(
color: TextColor.main,
fontFamily: FontFamily.japanese,
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
TextSpan(
text: "${removeZero(monthlyPackage.storeProduct.price)}/月",
style: const TextStyle(
color: TextColor.main,
fontFamily: FontFamily.japanese,
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
],
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:flutter_svg/svg.dart';
import 'package:pilll/components/atoms/font.dart';
import 'package:pilll/components/atoms/text_color.dart';
import 'package:pilll/features/premium_introduction/util/currency.dart';
import 'package:pilll/features/premium_introduction/util/discount_deadline.dart';
import 'package:purchases_flutter/object_wrappers.dart';

Expand Down Expand Up @@ -79,14 +80,29 @@ class PremiumIntroductionDiscountRow extends HookConsumerWidget {
const SizedBox(height: 4),
Stack(
children: [
Text(
monthlyPremiumPackage.storeProduct.priceString,
RichText(
textAlign: TextAlign.center,
style: const TextStyle(
fontWeight: FontWeight.w700,
fontSize: 28,
fontFamily: FontFamily.japanese,
color: TextColor.main,
text: TextSpan(
children: [
TextSpan(
text: currencySymbol(context),
style: const TextStyle(
fontWeight: FontWeight.w700,
fontSize: 20,
fontFamily: FontFamily.japanese,
color: TextColor.main,
),
),
TextSpan(
text: removeZero(monthlyPremiumPackage.storeProduct.price),
style: const TextStyle(
fontWeight: FontWeight.w700,
fontSize: 28,
fontFamily: FontFamily.japanese,
color: TextColor.main,
),
),
],
),
),
Positioned(
Expand Down
24 changes: 24 additions & 0 deletions lib/features/premium_introduction/util/currency.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';

String currencySymbol(BuildContext context) {
Locale locale = Localizations.localeOf(context);
var format = NumberFormat.simpleCurrency(locale: locale.toString());
return format.currencySymbol;
}

String removeZero(double price) {
var priceString = price.toString();

if (price.toString().split(".").isNotEmpty) {
var decmialPoint = price.toString().split(".")[1];
if (decmialPoint == "0") {
priceString = priceString.split(".0").join("");
}
if (decmialPoint == "00") {
priceString = priceString.split(".00").join("");
}
}

return priceString;
}

0 comments on commit ddefa36

Please sign in to comment.