forked from core/mobile_nebula
Fix share button on iPad (#124)
This commit is contained in:
parent
5ae4c20c70
commit
f7a7093879
|
@ -84,32 +84,28 @@ class _SiteLogsScreenState extends State<SiteLogsScreen> {
|
||||||
),
|
),
|
||||||
child: Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
|
child: Row(mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[
|
||||||
Expanded(
|
Expanded(
|
||||||
child: PlatformIconButton(
|
child: Builder(
|
||||||
padding: padding,
|
builder: (BuildContext context) {
|
||||||
icon: Icon(context.platformIcons.share, size: 30),
|
return PlatformIconButton(
|
||||||
onPressed: () {
|
padding: padding,
|
||||||
Share.shareFile(
|
icon: Icon(context.platformIcons.share, size: 30),
|
||||||
title: '${widget.site.name} logs',
|
onPressed: () {
|
||||||
filePath: widget.site.logFile,
|
Share.shareFile(context,
|
||||||
filename: '${widget.site.name}.log');
|
title: '${widget.site.name} logs',
|
||||||
},
|
filePath: widget.site.logFile,
|
||||||
|
filename: '${widget.site.name}.log');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
)),
|
)),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: PlatformIconButton(
|
child: PlatformIconButton(
|
||||||
padding: padding,
|
padding: padding,
|
||||||
icon: Icon(context.platformIcons.delete, size: Platform.isIOS ? 38 : 30),
|
icon: Icon(context.platformIcons.downArrow, size: 30),
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
Utils.confirmDelete(context, 'Are you sure you want to clear all logs?', () => deleteLogs());
|
controller.animateTo(controller.position.maxScrollExtent,
|
||||||
},
|
duration: const Duration(milliseconds: 500), curve: Curves.linearToEaseOut);
|
||||||
)),
|
},
|
||||||
Expanded(
|
|
||||||
child: PlatformIconButton(
|
|
||||||
padding: padding,
|
|
||||||
icon: Icon(context.platformIcons.downArrow, size: 30),
|
|
||||||
onPressed: () async {
|
|
||||||
controller.animateTo(controller.position.maxScrollExtent,
|
|
||||||
duration: const Duration(milliseconds: 500), curve: Curves.linearToEaseOut);
|
|
||||||
},
|
|
||||||
)),
|
)),
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,11 +92,18 @@ class _AddCertificateScreenState extends State<AddCertificateScreen> {
|
||||||
labelWidth: 0,
|
labelWidth: 0,
|
||||||
content: SelectableText(pubKey, style: TextStyle(fontFamily: 'RobotoMono', fontSize: 14)),
|
content: SelectableText(pubKey, style: TextStyle(fontFamily: 'RobotoMono', fontSize: 14)),
|
||||||
),
|
),
|
||||||
ConfigButtonItem(
|
Builder(
|
||||||
content: Text('Share Public Key'),
|
builder: (BuildContext context) {
|
||||||
onPressed: () async {
|
return ConfigButtonItem(
|
||||||
await Share.share(title: 'Please sign and return a certificate', text: pubKey, filename: 'device.pub');
|
content: Text('Share Public Key'),
|
||||||
},
|
onPressed: () async {
|
||||||
|
await Share.share(context,
|
||||||
|
title: 'Please sign and return a certificate',
|
||||||
|
text: pubKey,
|
||||||
|
filename: 'device.pub');
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
])
|
])
|
||||||
];
|
];
|
||||||
|
|
|
@ -19,11 +19,17 @@ class RenderedConfigScreen extends StatelessWidget {
|
||||||
title: Text('Rendered Site Config'),
|
title: Text('Rendered Site Config'),
|
||||||
scrollable: SimpleScrollable.both,
|
scrollable: SimpleScrollable.both,
|
||||||
trailingActions: <Widget>[
|
trailingActions: <Widget>[
|
||||||
PlatformIconButton(
|
Builder(
|
||||||
padding: EdgeInsets.zero,
|
builder: (BuildContext context) {
|
||||||
icon: Icon(context.platformIcons.share, size: 28.0),
|
return PlatformIconButton(
|
||||||
onPressed: () => Share.share(title: '$name.yaml', text: config, filename: '$name.yaml'),
|
padding: EdgeInsets.zero,
|
||||||
)
|
icon: Icon(context.platformIcons.share, size: 28.0),
|
||||||
|
onPressed: () =>
|
||||||
|
Share.share(context,
|
||||||
|
title: '$name.yaml', text: config, filename: '$name.yaml'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
),
|
||||||
],
|
],
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: EdgeInsets.all(5),
|
padding: EdgeInsets.all(5),
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:share_plus/share_plus.dart' as sp;
|
import 'package:share_plus/share_plus.dart' as sp;
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
|
@ -10,7 +11,8 @@ class Share {
|
||||||
/// - title: Title of message or subject if sending an email
|
/// - title: Title of message or subject if sending an email
|
||||||
/// - text: The text to share
|
/// - text: The text to share
|
||||||
/// - filename: The filename to use if sending over airdrop for example
|
/// - filename: The filename to use if sending over airdrop for example
|
||||||
static Future<bool> share({
|
static Future<bool> share(
|
||||||
|
BuildContext context, {
|
||||||
required String title,
|
required String title,
|
||||||
required String text,
|
required String text,
|
||||||
required String filename,
|
required String filename,
|
||||||
|
@ -25,7 +27,7 @@ class Share {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
file.writeAsStringSync(text, flush: true);
|
file.writeAsStringSync(text, flush: true);
|
||||||
res = await Share.shareFile(title: title, filePath: file.path);
|
res = await Share.shareFile(context, title: title, filePath: file.path);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Ignoring file write errors
|
// Ignoring file write errors
|
||||||
}
|
}
|
||||||
|
@ -38,19 +40,22 @@ class Share {
|
||||||
/// - title: Title of message or subject if sending an email
|
/// - title: Title of message or subject if sending an email
|
||||||
/// - filePath: Path to the file to share
|
/// - filePath: Path to the file to share
|
||||||
/// - filename: An optional filename to override the existing file
|
/// - filename: An optional filename to override the existing file
|
||||||
static Future<bool> shareFile({
|
static Future<bool> shareFile(BuildContext context,
|
||||||
required String title,
|
{required String title,
|
||||||
required String filePath,
|
required String filePath,
|
||||||
String? filename
|
String? filename}) async {
|
||||||
}) async {
|
|
||||||
assert(title.isNotEmpty);
|
assert(title.isNotEmpty);
|
||||||
assert(filePath.isNotEmpty);
|
assert(filePath.isNotEmpty);
|
||||||
|
|
||||||
|
final box = context.findRenderObject() as RenderBox?;
|
||||||
|
|
||||||
//NOTE: the filename used to specify the name of the file in gmail/slack/etc but no longer works that way
|
//NOTE: the filename used to specify the name of the file in gmail/slack/etc but no longer works that way
|
||||||
// If we want to support that again we will need to save the file to a temporary directory, share that,
|
// If we want to support that again we will need to save the file to a temporary directory, share that,
|
||||||
// and then delete it
|
// and then delete it
|
||||||
final xFile = sp.XFile(filePath, name: filename);
|
final xFile = sp.XFile(filePath, name: filename);
|
||||||
final result = await sp.Share.shareXFiles([xFile], subject: title);
|
final result = await sp.Share.shareXFiles([xFile],
|
||||||
|
subject: title,
|
||||||
|
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size);
|
||||||
return result.status == sp.ShareResultStatus.success;
|
return result.status == sp.ShareResultStatus.success;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue