.png)
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
Future viewWebsite(String recvUrl) async {
final url = Uri.parse(recvUrl);
launchUrl(url);
}
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('リンク飛ぶ')),
body: Center(
child: RichText(
text: TextSpan(
style: TextStyle(color: Colors.black, height: 1),
children: [
TextSpan(text: '詳しくは', style: TextStyle(fontSize: 30)),
WidgetSpan(
child: GestureDetector(
onTap: () {viewWebsite('<https://www.google.com/>');},
child: Text(
' こちら',
style: TextStyle(
color: Colors.indigo[500],
fontWeight: FontWeight.w500,
fontSize: 30
),
),
),
),
],
),
),
),
),
);
}
}
.png)
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
Future viewWebsite(String recvUrl) async {
final url = Uri.parse(recvUrl);
launchUrl(url);
}
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('リンク飛ぶ')),
body: Center(
child: RichText(
text: TextSpan(
style: TextStyle(color: Colors.black, height: 1),
children: [
TextSpan(text: '詳しくは', style: TextStyle(fontSize: 30)),
WidgetSpan(
alignment: PlaceholderAlignment.baseline,
baseline: TextBaseline.alphabetic,
child: GestureDetector(
onTap: () {viewWebsite('<https://www.google.com/>');},
child: Text(
' こちら',
style: TextStyle(
color: Colors.indigo[500],
fontWeight: FontWeight.w500,
fontSize: 30
),
),
),
),
],
),
),
),
),
);
}
}
WidgetSpan内に、alignmentとbaselineを追加する
WidgetSpan(
alignment: PlaceholderAlignment.baseline,
baseline: TextBaseline.alphabetic,
<aside> <img src="/icons/info-alternate_lightgray.svg" alt="/icons/info-alternate_lightgray.svg" width="40px" />
このページに載っているコードは、自由にお使いいただいて構いません。
(使用に伴い発生した損害などに対して一切責任は負いませんので、あくまで自己責任でご使用ください)
掲載している内容に間違いやミスを発見した場合、面倒でなければ、ご連絡いただければ幸いです。 </aside>