mirror of https://github.com/flutter/pinball.git
parent
47b74e3a9d
commit
687b3715b5
@ -1,3 +1,4 @@
|
||||
library share_repository;
|
||||
|
||||
export 'src/models/models.dart';
|
||||
export 'src/share_repository.dart';
|
||||
|
@ -0,0 +1 @@
|
||||
export 'share_platform.dart';
|
@ -0,0 +1,8 @@
|
||||
/// The platform that is being used to share a score.
|
||||
enum SharePlatform {
|
||||
/// Twitter platform.
|
||||
twitter,
|
||||
|
||||
/// Facebook platform.
|
||||
facebook,
|
||||
}
|
@ -1,7 +1,28 @@
|
||||
import 'package:share_repository/share_repository.dart';
|
||||
|
||||
/// {@template share_repository}
|
||||
/// Repository to facilitate sharing scores.
|
||||
/// {@endtemplate}
|
||||
class ShareRepository {
|
||||
/// {@macro share_repository}
|
||||
const ShareRepository();
|
||||
|
||||
// TODO(jonathandaniels-vgv): Change to prod url.
|
||||
static const _shareUrl = 'https://ashehwkdkdjruejdnensjsjdne.web.app/#/';
|
||||
|
||||
/// Returns a url to share the [shareText] on the given [platform]. The
|
||||
/// [shareText] must have the score embedded.
|
||||
String shareScore({
|
||||
required String shareText,
|
||||
required SharePlatform platform,
|
||||
}) {
|
||||
final encodedUrl = Uri.encodeComponent(_shareUrl);
|
||||
final encodedShareText = Uri.encodeComponent(shareText);
|
||||
switch (platform) {
|
||||
case SharePlatform.twitter:
|
||||
return 'https://twitter.com/intent/tweet?url=$encodedUrl&text=$encodedShareText';
|
||||
case SharePlatform.facebook:
|
||||
return 'https://www.facebook.com/sharer.php?u=$encodedUrl"e=$encodedShareText';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in new issue