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

Sang/postcard/group postcard #1335

Merged
merged 6 commits into from
Oct 31, 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
2 changes: 1 addition & 1 deletion assets
52 changes: 50 additions & 2 deletions lib/screen/interactive_postcard/postcard_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import 'package:autonomy_flutter/screen/interactive_postcard/design_stamp.dart';
import 'package:autonomy_flutter/screen/interactive_postcard/leaderboard/postcard_leaderboard.dart';
import 'package:autonomy_flutter/screen/interactive_postcard/postcard_detail_bloc.dart';
import 'package:autonomy_flutter/screen/interactive_postcard/postcard_detail_state.dart';
import 'package:autonomy_flutter/screen/interactive_postcard/postcard_explain.dart';
import 'package:autonomy_flutter/screen/interactive_postcard/postcard_view_widget.dart';
import 'package:autonomy_flutter/screen/interactive_postcard/travel_info/postcard_travel_info.dart';
import 'package:autonomy_flutter/screen/interactive_postcard/travel_info/travel_info_bloc.dart';
Expand All @@ -33,6 +34,7 @@ import 'package:autonomy_flutter/screen/settings/help_us/inapp_webview.dart';
import 'package:autonomy_flutter/service/chat_service.dart';
import 'package:autonomy_flutter/service/configuration_service.dart';
import 'package:autonomy_flutter/service/metric_client_service.dart';
import 'package:autonomy_flutter/service/navigation_service.dart';
import 'package:autonomy_flutter/service/postcard_service.dart';
import 'package:autonomy_flutter/service/settings_data_service.dart';
import 'package:autonomy_flutter/util/asset_token_ext.dart';
Expand Down Expand Up @@ -602,11 +604,23 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
return const SizedBox();
}
if (!(asset.isStamping || asset.isStamped)) {
final button = PostcardAsyncButton(
text: "continue".tr(),
fontSize: 18,
onTap: () async {
injector<NavigationService>().popAndPushNamed(AppRouter.designStamp,
arguments: DesignStampPayload(asset));
},
color: AppColor.momaGreen,
);
final page = _postcardPreview(context, asset);
return PostcardButton(
text: "stamp_postcard".tr(),
onTap: () {
Navigator.of(context).pushNamed(AppRouter.designStamp,
arguments: DesignStampPayload(asset));
Navigator.of(context).pushNamed(
AppRouter.postcardExplain,
arguments: PostcardExplainPayload(asset, button, pages: [page]),
);
},
);
}
Expand Down Expand Up @@ -995,6 +1009,40 @@ class ClaimedPostcardDetailPageState extends State<ClaimedPostcardDetailPage>
},
);
}

Widget _postcardPreview(BuildContext context, AssetToken asset) {
final theme = Theme.of(context);
return SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 265,
child: Stack(
children: [
PostcardViewWidget(
assetToken: asset,
withPreviewStamp: true,
),
Positioned.fill(child: Container(color: Colors.transparent)),
],
),
),
const SizedBox(height: 60),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"this_is_your_group_postcard".tr(),
style:
theme.textTheme.moMASans400Black14.copyWith(fontSize: 18),
),
],
)
],
),
);
}
}

class PostcardIdentity {
Expand Down
56 changes: 47 additions & 9 deletions lib/screen/interactive_postcard/postcard_explain.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:autonomy_flutter/common/injector.dart';
import 'package:autonomy_flutter/screen/interactive_postcard/postcard_view_widget.dart';
import 'package:autonomy_flutter/service/configuration_service.dart';
import 'package:autonomy_flutter/service/navigation_service.dart';
import 'package:autonomy_flutter/service/postcard_service.dart';
Expand Down Expand Up @@ -65,14 +66,16 @@ class _PostcardExplainState extends State<PostcardExplain> {

@override
Widget build(BuildContext context) {
final pages = [
_page1(_controller),
_page3(1, _colouringController),
_page2(2, totalDistance: 0),
_page2(3, totalDistance: 7926),
_page2(4, totalDistance: 91103),
_page4(5),
];
final pages = widget.payload.pages ??
[
_page1(_controller),
_page3(1, _colouringController),
_page2(2, totalDistance: 0),
_page2(3, totalDistance: 7926),
_page2(4, totalDistance: 91103),
_page4(5),
_postcardPreview(context, widget.payload.asset),
];
final swiperSize = pages.length;
final theme = Theme.of(context);
final padding = ResponsiveLayout.pageHorizontalEdgeInsets;
Expand Down Expand Up @@ -404,11 +407,46 @@ class _PostcardExplainState extends State<PostcardExplain> {
),
);
}

Widget _postcardPreview(BuildContext context, AssetToken asset) {
final theme = Theme.of(context);
return SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 265,
child: Stack(
children: [
PostcardViewWidget(
assetToken: asset,
withPreviewStamp: true,
),
Positioned.fill(child: Container(color: Colors.transparent)),
],
),
),
const SizedBox(height: 60),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"this_is_your_group_postcard".tr(),
style:
theme.textTheme.moMASans400Black14.copyWith(fontSize: 18),
),
],
)
],
),
);
}
}

class PostcardExplainPayload {
final AssetToken asset;
final Widget startButton;
final List<Widget>? pages;

PostcardExplainPayload(this.asset, this.startButton);
PostcardExplainPayload(this.asset, this.startButton, {this.pages});
}
45 changes: 38 additions & 7 deletions lib/screen/interactive_postcard/postcard_view_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/log.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:gif_view/gif_view.dart';
import 'package:nft_collection/models/asset_token.dart';
Expand All @@ -19,6 +20,7 @@ class PostcardViewWidget extends StatefulWidget {
final String? jsonPath;
final int? zoomIndex;
final Color backgroundColor;
final bool withPreviewStamp;

const PostcardViewWidget({
super.key,
Expand All @@ -27,6 +29,7 @@ class PostcardViewWidget extends StatefulWidget {
this.jsonPath,
this.zoomIndex,
this.backgroundColor = Colors.black,
this.withPreviewStamp = false,
});

@override
Expand Down Expand Up @@ -54,25 +57,50 @@ class _PostcardViewWidgetState extends State<PostcardViewWidget> {
);
}

void _getNewStamp(String base64Image, String base64Json, int index) {
log.info("[Postcard] getNewStamp");
_controller?.evaluateJavascript(
source: "getNewStamp('$base64Image', '$base64Json')",
);
log.info("[Postcard] getNewStamp");
log.info("[Postcard] $index");
log.info(base64Json);
log.info("[Postcard] base64Image ${base64Image.runtimeType}");
_controller?.evaluateJavascript(
source: "getNewStamp($index, '$base64Image', '$base64Json')",
);
}

_convertFileToBase64() async {
log.info("[Postcard] add stamp ${widget.imagePath}, ${widget.jsonPath}");
if (widget.imagePath == null || widget.jsonPath == null) return;
final image = await File(widget.imagePath!).readAsBytes();
final json = await File(widget.jsonPath!).readAsBytes();

base64Json = base64Encode(json);
base64Image = base64Encode(image);
final index = widget.assetToken.getArtists.length;
if (base64Image != null && base64Json != null) {
log.info("[Postcard] getNewStamp");
log.info("[Postcard] $index");
log.info(base64Json);
log.info("[Postcard] base64Image ${base64Image.runtimeType}");
_controller?.evaluateJavascript(
source: "getNewStamp($index, '$base64Image', '$base64Json')",
);
_getNewStamp(base64Image!, base64Json!, index);
}
}

_addPreviewStamp() async {
final Map<String, dynamic> metadata = {
"address": "",
"claimAddress": "",
"stampedAt": "",
};
final base64Json = base64Encode(utf8.encode(jsonEncode(metadata)));
final data =
await PlatformAssetBundle().load("assets/images/pink_stamp.png");
final image =
data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
final base64Image = base64Encode(image);
final index = widget.assetToken.getArtists.length;
_getNewStamp(base64Image, base64Json, index);
}

@override
Widget build(BuildContext context) {
final version = injector<ConfigurationService>().getVersionInfo();
Expand All @@ -93,6 +121,9 @@ class _PostcardViewWidgetState extends State<PostcardViewWidget> {
"[Postcard] Software artwork console log: ${consoleMessage.message}");
if (consoleMessage.message == POSTCARD_SOFTWARE_FULL_LOAD_MESSAGE) {
await _convertFileToBase64();
if (widget.withPreviewStamp) {
await _addPreviewStamp();
}
if (widget.zoomIndex != null) {
_zoomIntoStamp(
index: widget.zoomIndex!, color: widget.backgroundColor);
Expand Down
18 changes: 18 additions & 0 deletions lib/service/navigation_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,24 @@ class NavigationService {
?.pushNamed(routeName, arguments: arguments);
}

Future<dynamic>? popAndPushNamed(String routeName, {Object? arguments}) {
log.info("NavigationService.popAndPushNamed: $routeName");

if (routeName == AppRouter.wcConnectPage && _isWCConnectInShow) {
log.info(
"[NavigationService] skip popAndPushNamed because WCConnectPage is in showing");
return null;
}

if (navigatorKey.currentState?.mounted != true ||
navigatorKey.currentContext == null) {
return null;
}

return navigatorKey.currentState
?.popAndPushNamed(routeName, arguments: arguments);
}

Future<dynamic>? navigateUntil(
String routeName,
RoutePredicate predicate, {
Expand Down