Created
December 24, 2021 13:25
-
-
Save Roaa94/44b2cf35985d247b5fd5304b179c2066 to your computer and use it in GitHub Desktop.
RichText Widget Examples
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'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'RichText Example', | |
debugShowCheckedModeBanner: false, | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: StarterPage(), | |
); | |
} | |
} | |
class StarterPage extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('RichText Example'), | |
backgroundColor: const Color(0xff39cefd), | |
), | |
body: Padding( | |
padding: const EdgeInsets.all(17), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.start, | |
children: [ | |
RichText( | |
text: TextSpan( | |
text: | |
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ornare eget diam nec interdum. Vivamus ultrices eros at sem blandit, eu auctor turpis maximus. Vestibulum sed ornare justo. Mauris malesuada tristique nunc non iaculis. ', | |
style: Theme.of(context).textTheme.bodyText1, | |
children: <TextSpan>[ | |
TextSpan( | |
text: 'sneaky large, red text. ', | |
style: Theme.of(context) | |
.textTheme | |
.headline6! | |
.copyWith(color: Colors.red), | |
), | |
TextSpan( | |
text: | |
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ornare eget diam nec interdum. Vivamus ultrices eros at sem blandit, eu auctor turpis maximus. Vestibulum sed ornare justo. Mauris malesuada tristique nunc non iaculis. ', | |
style: Theme.of(context).textTheme.bodyText1, | |
), | |
TextSpan( | |
text: 'sneaky large, blue text. ', | |
style: Theme.of(context) | |
.textTheme | |
.headline6! | |
.copyWith(color: Colors.blue), | |
), | |
TextSpan( | |
text: | |
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ornare eget diam nec interdum. Vivamus ultrices eros at sem blandit, eu auctor turpis maximus. Vestibulum sed ornare justo. Mauris malesuada tristique nunc non iaculis. ', | |
style: Theme.of(context).textTheme.bodyText1, | |
), | |
], | |
), | |
) | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment