Created
April 5, 2025 22:05
-
-
Save loic-sharma/96dcdbbf832fcf9cdbc4447cf7c29640 to your computer and use it in GitHub Desktop.
Text widget verbosity
This file contains hidden or 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/material.dart'; | |
import 'package:flutter/gestures.dart'; | |
import 'package:url_launcher/url_launcher.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Text Demo', | |
home: Scaffold( | |
body: Center( | |
child: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: MyError(), | |
), | |
), | |
), | |
); | |
} | |
} | |
class MyError extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return RichText( | |
text: TextSpan( | |
children: <TextSpan>[ | |
TextSpan( | |
text: 'Error:', | |
style: TextStyle(fontWeight: FontWeight.bold), | |
), | |
TextSpan(text: ' Incorrect Text widget.\n'), | |
TextSpan( | |
text: 'Text widget documentation', | |
style: TextStyle( | |
color: Colors.blue, | |
decoration: TextDecoration.underline, | |
), | |
recognizer: TapGestureRecognizer() | |
..onTap = () { | |
launchUrl(Uri.parse('https://api.flutter.dev/flutter/widgets/Text-class.html')); | |
}, | |
), | |
TextSpan(text: '.'), | |
], | |
), | |
); | |
} | |
} |
This file contains hidden or 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/material.dart'; | |
import 'package:flutter/gestures.dart'; | |
import 'package:url_launcher/url_launcher.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Text Demo', | |
home: Scaffold( | |
body: Center( | |
child: Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: MyError(), | |
), | |
), | |
), | |
); | |
} | |
} | |
class MyError extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
final String markdown = ''' | |
**Error**: Incorrect Text widget. | |
[Text widget documentation](https://api.flutter.dev/flutter/widgets/Text-class.html). | |
'''; | |
return Text.markdown( | |
markdown, | |
onTapUrl: launchUrl, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment