Created
June 30, 2023 17:44
-
-
Save justinmc/12135ff74f489d8a6df96ccbc0330220 to your computer and use it in GitHub Desktop.
Demonstrates undesired full width of link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/gestures.dart'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
const MyHomePage({Key? key, required this.title}) : super(key: key); | |
final String title; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: Text(title), | |
), | |
body: const Center( | |
child: _Link(), | |
), | |
); | |
} | |
} | |
class _Link extends StatefulWidget { | |
const _Link(); | |
@override | |
State<_Link> createState() => _LinkState(); | |
} | |
class _LinkState extends State<_Link> { | |
late final TapGestureRecognizer _recognizer; | |
void _onTap() { | |
print('Tapped.'); | |
} | |
@override | |
void initState() { | |
super.initState(); | |
_recognizer = TapGestureRecognizer()..onTap = _onTap; | |
} | |
@override | |
void dispose() { | |
_recognizer.dispose(); | |
super.dispose(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return RichText( | |
text: TextSpan( | |
style: DefaultTextStyle.of(context).style, | |
text: 'First line\n', | |
children: <InlineSpan>[ | |
TextSpan( | |
recognizer: _recognizer, | |
style: const TextStyle( | |
color: Colors.blue, | |
), | |
text: 'Click me', | |
), | |
const TextSpan( | |
text: '\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', | |
), | |
], | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment