Skip to content

Commit

Permalink
fix: focusNode did not work with BackdropScaffold backlayer
Browse files Browse the repository at this point in the history
Signed-off-by: phuoc <[email protected]>
  • Loading branch information
phuocbitmark committed Jul 25, 2024
1 parent 02a0fb7 commit 68d2ca5
Showing 1 changed file with 104 additions and 68 deletions.
172 changes: 104 additions & 68 deletions lib/screen/detail/artwork_detail_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ import 'package:feralfile_app_tv_proto/feralfile_app_tv_proto.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_svg/svg.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:nft_collection/models/asset_token.dart';
import 'package:nft_collection/models/provenance.dart';
import 'package:nft_collection/nft_collection.dart';
import 'package:nft_collection/services/tokens_service.dart';
import 'package:nft_rendering/nft_rendering.dart';
import 'package:shake/shake.dart';
import 'package:social_share/social_share.dart';
import 'package:url_launcher/url_launcher.dart';
Expand Down Expand Up @@ -90,6 +92,8 @@ class _ArtworkDetailPageState extends State<ArtworkDetailPage>
AssetToken? currentAsset;
final _feralfileService = injector.get<FeralFileService>();
final _focusNode = FocusNode();
final _textController = TextEditingController();
InAppWebViewController? _webViewController;
bool _isInfoExpand = false;
static const _infoShrinkPosition = 0.001;
static const _infoExpandPosition = 0.29;
Expand Down Expand Up @@ -217,6 +221,7 @@ class _ArtworkDetailPageState extends State<ArtworkDetailPage>
_scrollController?.dispose();
_animationController.dispose();
_focusNode.dispose();
_textController.dispose();
unawaited(disableLandscapeMode());
unawaited(WakelockPlus.disable());
_detector?.stopListening();
Expand Down Expand Up @@ -358,10 +363,11 @@ class _ArtworkDetailPageState extends State<ArtworkDetailPage>
children: [
Expanded(
child: ArtworkPreviewWidget(
focusNode: _focusNode,
//focusNode: _focusNode,
useIndexer: widget.payload.useIndexer,
identity: widget
.payload.identities[widget.payload.currentIndex],
onLoaded: _onLoaded,
),
),
if (!_isFullScreen)
Expand Down Expand Up @@ -454,6 +460,12 @@ class _ArtworkDetailPageState extends State<ArtworkDetailPage>
),
);

dynamic _onLoaded({InAppWebViewController? webViewController, int? time}) {
setState(() {
_webViewController = webViewController;
});
}

Widget _infoHeader(BuildContext context, AssetToken asset, String? artistName,
bool isViewOnly, CanvasDeviceState canvasState) {
var subTitle = '';
Expand Down Expand Up @@ -505,77 +517,98 @@ class _ArtworkDetailPageState extends State<ArtworkDetailPage>
final theme = Theme.of(context);
final asset = state.assetToken!;
final editionSubTitle = getEditionSubTitle(asset);
return SingleChildScrollView(
controller: _scrollController,
child: SizedBox(
width: double.infinity,
child: Column(
children: [
Visibility(
visible: checkWeb3ContractAddress.contains(asset.contractAddress),
child: Padding(
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 20),
child: OutlineButton(
color: Colors.transparent,
text: 'web3_glossary'.tr(),
onTap: () {
unawaited(Navigator.pushNamed(
context, AppRouter.previewPrimerPage,
arguments: asset));
},
),
),
return Stack(
children: [
Visibility(
visible: _isOpenedWithWebview(asset),
child: TextFormField(
decoration: const InputDecoration(
border: InputBorder.none,
),
Visibility(
visible: editionSubTitle.isNotEmpty,
child: Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: ResponsiveLayout.getPadding,
child: Text(
editionSubTitle,
style: theme.textTheme.ppMori400Grey14,
controller: _textController,
focusNode: _focusNode,
onChanged: (value) {
unawaited(_webViewController?.evaluateJavascript(source: """
window.dispatchEvent(new KeyboardEvent('keydown', {'key': '${value.characters.last}','keyCode': ${keysCode[value.characters.last]},'which': ${keysCode[value.characters.last]}}));window.dispatchEvent(new KeyboardEvent('keypress', {'key': '${value.characters.last}','keyCode': ${keysCode[value.characters.last]},'which': ${keysCode[value.characters.last]}}));window.dispatchEvent(new KeyboardEvent('keyup', {'key': '${value.characters.last}','keyCode': ${keysCode[value.characters.last]},'which': ${keysCode[value.characters.last]}}));"""));
_textController.text = '';
},
),
),
SingleChildScrollView(
controller: _scrollController,
child: SizedBox(
width: double.infinity,
child: Column(
children: [
Visibility(
visible:
checkWeb3ContractAddress.contains(asset.contractAddress),
child: Padding(
padding:
const EdgeInsets.only(left: 16, right: 16, bottom: 20),
child: OutlineButton(
color: Colors.transparent,
text: 'web3_glossary'.tr(),
onTap: () {
unawaited(Navigator.pushNamed(
context, AppRouter.previewPrimerPage,
arguments: asset));
},
),
),
),
),
),
debugInfoWidget(context, currentAsset),
Padding(
padding: ResponsiveLayout.getPadding,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Semantics(
label: 'Desc',
child: HtmlWidget(
customStylesBuilder: auHtmlStyle,
asset.description ?? '',
textStyle: theme.textTheme.ppMori400White14,
Visibility(
visible: editionSubTitle.isNotEmpty,
child: Align(
alignment: Alignment.centerLeft,
child: Padding(
padding: ResponsiveLayout.getPadding,
child: Text(
editionSubTitle,
style: theme.textTheme.ppMori400Grey14,
),
),
),
const SizedBox(height: 40),
artworkDetailsMetadataSection(context, asset, artistName),
if (asset.fungible) ...[
tokenOwnership(context, asset,
identityState.identityMap[asset.owner] ?? ''),
] else ...[
if (state.provenances.isNotEmpty)
_provenanceView(context, state.provenances)
else
const SizedBox()
],
artworkDetailsRightSection(context, asset),
const SizedBox(height: 80),
],
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.5 -
(_appBarBottomDy ?? 80),
),
debugInfoWidget(context, currentAsset),
Padding(
padding: ResponsiveLayout.getPadding,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Semantics(
label: 'Desc',
child: HtmlWidget(
customStylesBuilder: auHtmlStyle,
asset.description ?? '',
textStyle: theme.textTheme.ppMori400White14,
),
),
const SizedBox(height: 40),
artworkDetailsMetadataSection(context, asset, artistName),
if (asset.fungible) ...[
tokenOwnership(context, asset,
identityState.identityMap[asset.owner] ?? ''),
] else ...[
if (state.provenances.isNotEmpty)
_provenanceView(context, state.provenances)
else
const SizedBox()
],
artworkDetailsRightSection(context, asset),
const SizedBox(height: 80),
],
),
),
SizedBox(
height: MediaQuery.of(context).size.height * 0.5 -
(_appBarBottomDy ?? 80),
),
],
),
],
),
),
),
],
);
}

Expand Down Expand Up @@ -604,9 +637,7 @@ class _ArtworkDetailPageState extends State<ArtworkDetailPage>
final ownerWallet = owner?.first;
final addressIndex = owner?.second;
final irlUrl = asset.irlTapLink;
final showKeyboard = (asset.medium == 'software' ||
asset.medium == 'other' ||
(asset.medium?.isEmpty ?? true) ||
final showKeyboard = (_isOpenedWithWebview(asset) ||
canvasDeviceState
.lastSelectedActiveDeviceForKey(_getDisplayKey(asset)) !=
null) &&
Expand Down Expand Up @@ -836,6 +867,11 @@ class _ArtworkDetailPageState extends State<ArtworkDetailPage>
));
}

bool _isOpenedWithWebview(AssetToken asset) =>
asset.medium == 'software' ||
asset.medium == 'other' ||
(asset.medium?.isEmpty ?? true);

Future<void> _setFullScreen() async {
unawaited(_openSnackBar(context));
if (_isInfoExpand) {
Expand Down

0 comments on commit 68d2ca5

Please sign in to comment.