Skip to content

Commit

Permalink
test artwork on every page
Browse files Browse the repository at this point in the history
Signed-off-by: phuoc <[email protected]>
  • Loading branch information
phuocbitmark committed Nov 11, 2024
1 parent e50978f commit 32094d7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 82 deletions.
103 changes: 24 additions & 79 deletions lib/screen/account/test_artwork_screen.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import 'package:autonomy_flutter/nft_rendering/audio_rendering_widget.dart';
import 'package:autonomy_flutter/nft_rendering/gif_rendering_widget.dart';
import 'package:autonomy_flutter/nft_rendering/image_rendering_widget.dart';
import 'package:autonomy_flutter/nft_rendering/nft_rendering_widget.dart';
import 'package:autonomy_flutter/nft_rendering/pdf_rendering_widget.dart';
import 'package:autonomy_flutter/nft_rendering/svg_rendering_widget.dart';
import 'package:autonomy_flutter/nft_rendering/video_player_widget.dart';
import 'package:autonomy_flutter/nft_rendering/webview_rendering_widget.dart';
import 'package:autonomy_flutter/util/constants.dart';
import 'package:autonomy_flutter/util/string_ext.dart';
import 'package:autonomy_flutter/view/au_text_field.dart';
import 'package:autonomy_flutter/view/back_appbar.dart';
Expand All @@ -14,6 +8,10 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

bool testArtworkMode = false;
String? testArtworkRenderingType;
String? testArtworkPreviewURL;

class TestArtworkScreen extends StatefulWidget {
const TestArtworkScreen({super.key});

Expand All @@ -35,7 +33,6 @@ class _TestArtworkScreenState extends State<TestArtworkScreen> {
];
final _urlController = TextEditingController();
String _renderingType = RenderingTypeExtension.auto;
Widget? _renderingWidget;

@override
Widget build(BuildContext context) => Scaffold(
Expand Down Expand Up @@ -70,6 +67,10 @@ class _TestArtworkScreenState extends State<TestArtworkScreen> {
}),
PrimaryAsyncButton(
onTap: () async {
final isInhouse = await isAppCenterBuild();
if (!isInhouse) {
return;
}
if (_urlController.text.isNotEmpty &&
_renderingType.isNotEmpty) {
String renderingType = _renderingType;
Expand All @@ -86,83 +87,27 @@ class _TestArtworkScreenState extends State<TestArtworkScreen> {
} else {
renderingType = RenderingType.webview;
}
}

Widget renderingWidget;
final previewURL = link;

switch (renderingType) {
case RenderingType.image:
renderingWidget = InteractiveViewer(
minScale: 1,
maxScale: 4,
child: Center(
child: ImageNFTRenderingWidget(
previewURL: previewURL,
),
),
);
case RenderingType.video:
renderingWidget = InteractiveViewer(
minScale: 1,
maxScale: 4,
child: Center(
child: VideoNFTRenderingWidget(
previewURL: previewURL,
),
),
);
case RenderingType.gif:
renderingWidget = InteractiveViewer(
minScale: 1,
maxScale: 4,
child: Center(
child: GifNFTRenderingWidget(
previewURL: previewURL,
),
),
);
case RenderingType.svg:
renderingWidget = InteractiveViewer(
minScale: 1,
maxScale: 4,
child: Center(
child: SVGNFTRenderingWidget(
previewURL: previewURL)),
);
case RenderingType.pdf:
renderingWidget = Center(
child: PDFNFTRenderingWidget(
previewURL: previewURL,
),
);
case RenderingType.audio:
renderingWidget = Center(
child: AudioNFTRenderingWidget(
previewURL: previewURL,
),
);
default:
renderingWidget = Center(
child: WebviewNFTRenderingWidget(
previewURL: previewURL,
),
);
setState(() {
testArtworkMode = true;
testArtworkRenderingType = renderingType;
testArtworkPreviewURL = link;
});
}

setState(() {
_renderingWidget = renderingWidget;
});
}
},
text: 'test_artwork'.tr(),
),
Visibility(
visible: _renderingWidget != null,
child: Padding(
padding: const EdgeInsets.only(top: 20),
child: _renderingWidget,
),
PrimaryButton(
enabled: testArtworkMode,
onTap: () {
setState(() {
testArtworkMode = false;
testArtworkRenderingType = null;
testArtworkPreviewURL = null;
});
},
text: 'Turn off test artwork mode',
),
],
),
Expand Down
13 changes: 11 additions & 2 deletions lib/screen/detail/preview_detail/preview_detail_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:autonomy_flutter/nft_rendering/pdf_rendering_widget.dart';
import 'package:autonomy_flutter/nft_rendering/svg_rendering_widget.dart';
import 'package:autonomy_flutter/nft_rendering/video_player_widget.dart';
import 'package:autonomy_flutter/nft_rendering/webview_rendering_widget.dart';
import 'package:autonomy_flutter/screen/account/test_artwork_screen.dart';
import 'package:autonomy_flutter/screen/detail/artwork_detail_page.dart';
import 'package:autonomy_flutter/screen/detail/preview_detail/preview_detail_bloc.dart';
import 'package:autonomy_flutter/screen/detail/preview_detail/preview_detail_state.dart';
Expand Down Expand Up @@ -131,9 +132,17 @@ class ArtworkPreviewWidgetState extends State<ArtworkPreviewWidget>
alignment: Alignment.center,
child: PostcardRatio(assetToken: assetToken));
}
final previewURL = assetToken.getPreviewUrl() ?? '';
late final String previewURL;
late final String mimeType;
if (testArtworkMode) {
previewURL = testArtworkPreviewURL!;
mimeType = testArtworkRenderingType!;
} else {
previewURL = assetToken.getPreviewUrl() ?? '';
mimeType = assetToken.getMimeType;
}

switch (assetToken.getMimeType) {
switch (mimeType) {
case RenderingType.image:
_currentRenderingWidget = ImageNFTRenderingWidget(
key: _artworkKey,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import 'package:autonomy_flutter/au_bloc.dart';
import 'package:autonomy_flutter/screen/account/test_artwork_screen.dart';
import 'package:autonomy_flutter/screen/feralfile_artwork_preview/feralfile_artwork_preview_state.dart';
import 'package:autonomy_flutter/util/exhibition_ext.dart';

class FFArtworkPreviewBloc
extends AuBloc<FFArtworkPreviewEvent, FFArtworkPreviewState> {
FFArtworkPreviewBloc() : super(FFArtworkPreviewState()) {
on<FFArtworkPreviewConfigByArtwork>((event, emit) async {
if (testArtworkMode) {
emit(state.copyWith(
mediumMap: {testArtworkPreviewURL!: testArtworkPreviewURL!}));
return;
}
if (!state.mediumMap.containsKey(event.artwork.previewURL)) {
final medium = await event.artwork.renderingType();
final Map<String, String> mediumMap = {};
Expand Down
5 changes: 4 additions & 1 deletion lib/view/feralfile_artwork_preview_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:autonomy_flutter/nft_rendering/pdf_rendering_widget.dart';
import 'package:autonomy_flutter/nft_rendering/svg_rendering_widget.dart';
import 'package:autonomy_flutter/nft_rendering/video_player_widget.dart';
import 'package:autonomy_flutter/nft_rendering/webview_rendering_widget.dart';
import 'package:autonomy_flutter/screen/account/test_artwork_screen.dart';
import 'package:autonomy_flutter/screen/feralfile_artwork_preview/feralfile_artwork_preview_bloc.dart';
import 'package:autonomy_flutter/screen/feralfile_artwork_preview/feralfile_artwork_preview_state.dart';
import 'package:autonomy_flutter/util/exhibition_ext.dart';
Expand Down Expand Up @@ -65,7 +66,9 @@ class _FeralfileArtworkPreviewWidgetState

@override
Widget build(BuildContext context) {
final previewUrl = widget.payload.artwork.previewURL;
final previewUrl = testArtworkMode
? testArtworkPreviewURL!
: widget.payload.artwork.previewURL;
final thumbnailUrl = widget.payload.artwork.thumbnailURL;
return BlocProvider(
create: (_) => RetryCubit(),
Expand Down

0 comments on commit 32094d7

Please sign in to comment.