Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 354 Vote(s) - 3.54 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Display a few words in different colors in Flutter

#1
I am writing an application which shows a few words in different colors in flutter.

I tried to load HTML files using the plugin flutter_html_view but that one doesn't support styles(inline). I also tried to use markdown.

How can I achieve this?
Reply

#2
Use RichText, TextSpan and TextStyle as i explained in below picture.


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

class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Center(
child: RichText(
text: TextSpan(
text: 'Default',
style: TextStyle(color: Colors.red), /*defining default style is optional */
children: <TextSpan>[
TextSpan(
text: ' bold', style: TextStyle(fontWeight: FontWeight.bold)),
TextSpan(
text: ' colorful',
style: TextStyle(color: Colors.lightGreenAccent)),
TextSpan(
text: ' large',
style: TextStyle(color: Colors.cyanAccent, fontSize: 40)),
],
),
),
),
);
}
}




[![enter image description here][1]][1]


[1]:
Reply

#3
Use [RichText][1] class

var text = new RichText(
text: new TextSpan(
// Note: Styles for TextSpans must be explicitly defined.
// Child text spans will inherit styles from parent
style: new TextStyle(
fontSize: 14.0,
color: Colors.black,
),
children: <TextSpan>[
new TextSpan(text: 'Hello'),
new TextSpan(text: 'World', style: new TextStyle(fontWeight: FontWeight.bold)),
],
),
);


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through