Skip to content

Instantly share code, notes, and snippets.

@Piinks
Created May 14, 2024 18:36
Show Gist options
  • Save Piinks/98e4f7032bbccfe99b89c1426d0fe800 to your computer and use it in GitHub Desktop.
Save Piinks/98e4f7032bbccfe99b89c1426d0fe800 to your computer and use it in GitHub Desktop.
Span text style issue
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.all(30.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Spacer(),
Text.rich(
TextSpan(
children: [
TextSpan(
text: 'Plain text - more and more of plain text, wrapping to the next line. ',
style: Theme.of(context).textTheme.bodySmall,
),
// This renders the empty space in a different text style,
// affecting the alignment of neighboring spans.
// This should not be necessary though for focus, the
// following WidgetSpan is focusable without it.
// TextSpan(
// text: ' ',
// recognizer: TapGestureRecognizer(),
// semanticsLabel: '',
// ),
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: InkWell(
onTap: () { print('tapped'); },
child: Text(
'Learn more',
style: Theme.of(context).textTheme.bodySmall!.copyWith(
decoration: TextDecoration.underline,
color: Colors.blue,
),
),
),
),
],
),
),
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment