Rich Text (with TextSpan Widget)

 import "package:flutter/material.dart";


void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: "Hello",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.brown,
),
home: const FlutterApp(),
);
}
}

class FlutterApp extends StatefulWidget {
const FlutterApp({super.key});

@override
State<FlutterApp> createState() {
return FlutterState();
}
}

class FlutterState extends State<FlutterApp> {
@override
Widget build(BuildContext context) {
return Scaffold(
drawer: const Drawer(),
appBar: AppBar(
title: const Text(
"Flutter Rich Text",
style: TextStyle(fontWeight: FontWeight.bold),
),
centerTitle: true,
backgroundColor: Colors.grey,
),
// body: Row(
// children: const [
// Text("Hello ", style: TextStyle(fontSize: 16, color: Colors.grey),),
// Text("World!", style: TextStyle(fontSize: 35, color: Colors.blue, fontWeight: FontWeight.bold),),
// ],
// ),
body: Center(
child: RichText(
text: const TextSpan(
style: TextStyle(
///Here,is default style for all text in TextSpan()
color: Colors.grey,
fontSize: 21,
),
///If any particular style is not given in TextSpan(), then the default will apply for all and if we apply style manually
/// in the TextSpan() then that style will apply for that particular text
children: <TextSpan>[
TextSpan(text: "Hello "),
TextSpan(
text: "World!",
style: TextStyle(
fontSize:
25, ///Here,manually added TextStyle() will be applied
color: Colors.blue,
fontWeight: FontWeight.bold,
),
),
TextSpan(text: " Welcome to "),
TextSpan(
text: "Flutter",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 34,
color: Colors.deepOrangeAccent,
fontStyle: FontStyle.italic,
fontFamily: "FontMain",
),
),
],
),
),
),
);
}
}

Comments

Popular posts from this blog

Pagination with Bloc Pattern in Flutter

ExpansionPanel with ExpansionPanelList with Complete Collapse Operation in Flutter

Pagination First Practical in Flutter