mirror of
https://github.com/flutter/samples.git
synced 2026-05-13 10:27:09 +00:00
Update desktop_photo_search to use url_launcher's Link (#780)
This commit is contained in:
@@ -3,15 +3,14 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:transparent_image/transparent_image.dart';
|
||||
import 'package:url_launcher/url_launcher.dart' as url_launcher;
|
||||
import 'package:url_launcher/link.dart';
|
||||
|
||||
import '../../unsplash_access_key.dart';
|
||||
import '../unsplash/photo.dart';
|
||||
|
||||
final _unsplashHomepage = Uri.encodeFull(
|
||||
final _unsplashHomepage = Uri.parse(
|
||||
'https://unsplash.com/?utm_source=$unsplashAppName&utm_medium=referral');
|
||||
|
||||
typedef PhotoDetailsPhotoSaveCallback = void Function(Photo);
|
||||
@@ -31,43 +30,26 @@ class PhotoDetails extends StatefulWidget {
|
||||
class _PhotoDetailsState extends State<PhotoDetails>
|
||||
with TickerProviderStateMixin {
|
||||
Widget _buildPhotoAttribution(BuildContext context) {
|
||||
return Expanded(
|
||||
child: RichText(
|
||||
overflow: TextOverflow.fade,
|
||||
text: TextSpan(
|
||||
style: Theme.of(context).textTheme.bodyText2,
|
||||
children: [
|
||||
const TextSpan(text: 'Photo by '),
|
||||
TextSpan(
|
||||
text: widget.photo.user.name,
|
||||
style: const TextStyle(
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () async {
|
||||
final url = Uri.encodeFull(
|
||||
'https://unsplash.com/@${widget.photo.user.username}?utm_source=$unsplashAppName&utm_medium=referral');
|
||||
if (await url_launcher.canLaunch(url)) {
|
||||
await url_launcher.launch(url);
|
||||
}
|
||||
},
|
||||
),
|
||||
const TextSpan(text: ' on '),
|
||||
TextSpan(
|
||||
text: 'Unsplash',
|
||||
style: const TextStyle(
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () async {
|
||||
if (await url_launcher.canLaunch(_unsplashHomepage)) {
|
||||
await url_launcher.launch(_unsplashHomepage);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
return Row(
|
||||
children: [
|
||||
Text('Photo by '),
|
||||
Link(
|
||||
uri: Uri.parse(
|
||||
'https://unsplash.com/@${widget.photo.user.username}?utm_source=$unsplashAppName&utm_medium=referral'),
|
||||
builder: (context, followLink) => TextButton(
|
||||
onPressed: followLink,
|
||||
child: Text(widget.photo.user.name),
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(' on '),
|
||||
Link(
|
||||
uri: _unsplashHomepage,
|
||||
builder: (context, followLink) => TextButton(
|
||||
onPressed: followLink,
|
||||
child: Text('Unsplash'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user