2
1

More than 1 year has passed since last update.

【Flutter】share_plusがiPadで機能しない

Posted at

公式に書かれている通りに実装したけど、 AndroidやiPhoneでは機能するのにiPadでは機能しない。

しかも長文の謎のエラーを吐く。

[LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
	(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x2819a8190 h=-&- v=--& _UIActivityContentNavigationBar:0x101baec40.minY == 0   (active, names: '|':UILayoutContainerView:0x101bc5cf0 )>",
    "<NSAutoresizingMaskLayoutConstraint:0x2819a92c0 h=-&- v=--& _UIActivityContentNavigationBar:0x101baec40.height == 50   (active)>",
    "<NSLayoutConstraint:0x2819b9130 V:[_UIActivityContentNavigationBar:0x101baec40]-(0)-[UIFocusContainerGuide:0x28053e850'UINavigationControllerContentFocusContainerGuide']   (active)>",
    "<NSLayoutConstraint:0x2819b9b80 UIFocusContainerGuide:0x28053e850'UINavigationControllerContentFocusContainerGuide'.bottom == UILayoutContainerView:0x101bc5cf0.bottom   (active)>",
    "<NSLayoutConstraint:0x2819ba670 V:|-(0)-[UILayoutContainerView:0x101bc5cf0]   (active, names: '|':UIView:0x101b93700 )>",
    "<NSLayoutConstraint:0x2819ba580 UILayoutContainerView:0x101bc5cf0.bottom == UIView:0x101b93700.bottom   (active)>",
    "<NSLayoutConstraint:0x281929090 'UIView-Encapsulated-Layout-Height' UIView:0x101b93700.height == 0   (active)>"
)


Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x2819b9130 V:[_UIActivityContentNavigationBar:0x101baec40]-(0)-[UIFocusContainerGuide:0x28053e850'UINavigationControllerContentFocusContainerGuide']   (active)>


Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
[Default] Task Runner[2128]/1#4 LF=0 couldn't find entitlement CopresenceCore.Entitlement.publicAPI error nil
[LayoutConstraints] Unable to simultaneously satisfy constraints.
	Probably at least one of the constraints in the following list is one you don't want. 
	Try this: 
		(1) look at each constraint and try to figure out which you don't expect; 
		(2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x281939310 H:|-(0)-[_UIActivityContentTitleView:0x12a955830]   (active, names: '|':_UINavigationBarContentView:0x101b90150 )>",
    "<NSLayoutConstraint:0x281938190 _UIActivityContentTitleView:0x12a955830.trailing == _UINavigationBarContentView:0x101b90150.trailing   (active)>",
    "<NSLayoutConstraint:0x28192bd40 LPLinkView:0x101a0e510.leading == UILayoutGuide:0x28030dea0'UIViewLayoutMarginsGuide'.leading   (active)>",
    "<NSLayoutConstraint:0x28192b840 LPLinkView:0x101a0e510.trailing == UILayoutGuide:0x28030dea0'UIViewLayoutMarginsGuide'.trailing   (active)>",
    "<NSLayoutConstraint:0x281954370 'UIView-Encapsulated-Layout-Width' _UINavigationBarContentView:0x101b90150.width == 0   (active)>",
    "<NSLayoutConstraint:0x2819349b0 'UIView-leftMargin-guide-constraint' H:|-(16)-[UILayoutGuide:0x28030dea0'UIViewLayoutMarginsGuide'](LTR)   (active, names: '|':_UIActivityContentTitleView:0x12a955830 )>",
    "<NSLayoutConstraint:0x28192a0d0 'UIView-rightMargin-guide-constraint' H:[UILayoutGuide:0x28030dea0'UIViewLayoutMarginsGuide']-(8)-|(LTR)   (active, names: '|':_UIActivityContentTitleView:0x12a955830 )>"
)


Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x28192b840 LPLinkView:0x101a0e510.trailing == UILayoutGuide:0x28030dea0'UIViewLayoutMarginsGuide'.trailing   (active)>


Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

解決策

そして辿り着いたのがこのissueページ
https://github.com/flutter/flutter/issues/47220


final shareBtnKey = GlobalKey();

void shareFile() {
  Share.shareFiles(
	...
    sharePositionOrigin: shareButtonRect(),
  );
}

Rect shareButtonRect() {
  RenderBox renderBox = shareBtnKey.currentContext?.findRenderObject() as RenderBox;

  Size size = renderBox.size;
  Offset position = renderBox.localToGlobal(Offset.zero);

  return Rect.fromCenter(
    center: position + Offset(size.width / 2, size.height / 2),
    width: size.width,
    height: size.height,
  );
}

公式に書いてあるのとは違って、僕はこれで動きました。
shareBtnKeyは共有ボタンのkeyとしてセットしてお使いください。

時間をだいぶ無駄にしましたが、先人の知恵に救われました。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1