mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
76 lines
1.9 KiB
Dart
76 lines
1.9 KiB
Dart
// Copyright 2014 The Flutter Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
// This example demonstrates using LinkedText to make URLs open on tap.
|
|
|
|
void main() {
|
|
runApp(const LinkedTextApp());
|
|
}
|
|
|
|
class LinkedTextApp extends StatelessWidget {
|
|
const LinkedTextApp({
|
|
super.key,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Flutter Demo',
|
|
theme: ThemeData(
|
|
primarySwatch: Colors.blue,
|
|
),
|
|
home: const MyHomePage(title: 'Flutter Link Demo'),
|
|
);
|
|
}
|
|
}
|
|
|
|
class MyHomePage extends StatelessWidget {
|
|
const MyHomePage({
|
|
super.key,
|
|
required this.title,
|
|
});
|
|
|
|
final String title;
|
|
static const String _text = 'Check out https://www.flutter.dev, or maybe just flutter.dev or www.flutter.dev.';
|
|
|
|
void _handleTapUri(BuildContext context, Uri uri) {
|
|
// A package like url_launcher would be useful for actually opening the URL
|
|
// here instead of just showing a dialog.
|
|
Navigator.of(context).push(
|
|
DialogRoute<void>(
|
|
context: context,
|
|
builder: (BuildContext context) => AlertDialog(title: Text('You tapped: $uri')),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(title),
|
|
),
|
|
body: Center(
|
|
child: Builder(
|
|
builder: (BuildContext context) {
|
|
return SelectionArea(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: <Widget>[
|
|
LinkedText(
|
|
text: _text,
|
|
onTapUri: (Uri uri) => _handleTapUri(context, uri),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|