Skip to content

Instantly share code, notes, and snippets.

@loic-sharma
Created April 5, 2025 22:05
Show Gist options
  • Save loic-sharma/96dcdbbf832fcf9cdbc4447cf7c29640 to your computer and use it in GitHub Desktop.
Save loic-sharma/96dcdbbf832fcf9cdbc4447cf7c29640 to your computer and use it in GitHub Desktop.
Text widget verbosity
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: '.'),
],
),
);
}
}
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