flutter_colorful_markdown 0.0.3
flutter_colorful_markdown: ^0.0.3 copied to clipboard
A widget that displays markdown with random colorful style. It supports images, links, latex and text styles.
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter_colorful_markdown/flutter_colorful_markdown.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 MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
),
home: const MyHomePage(title: 'Colorful Markdown Example'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
ColorfulMarkdown(
backgroundImage: _backgroundImages[Random().nextInt(_backgroundImages.length)],
data: _markdownData
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 16.0),
child:
const Text('random colorful markdonw times:'),
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Get Random Color',
child: const Icon(Icons.change_circle_outlined),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
const String _markdownData = '''
## ChatGPT Response
Welcome to ChatGPT! Below is an example of a response with Markdown and LaTeX code:
### Markdown Example
You can use Markdown to format text easily. Here are some examples:
- **Bold Text**: **This text is bold**
- *Italic Text*: *This text is italicized*
- [Link](https://www.example.com): [This is a link](https://www.example.com)
- Lists:
1. Item 1
2. Item 2
3. Item 3
### LaTeX Example
You can also use LaTeX for mathematical expressions. Here's an example:
- **Equation**: \( f(x) = x^2 + 2x + 1 \)
- **Integral**: \( \int_{0}^{1} x^2 \, dx \)
- **Matrix**:
\[
\begin{bmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{bmatrix}
\]
### Conclusion
Markdown and LaTeX can be powerful tools for formatting text and mathematical expressions in your Flutter app. If you have any questions or need further assistance, feel free to ask!
### Test for Chinese
👋你好,👋世界。
''';
const List<String> _backgroundImages = [
'https://www.allkpop.com/upload/2023/02/content/131452/web_data/allkpop_1676318355_untitled-1.jpg',
'https://pic4.zhimg.com/v2-efd4f4517d5bdb43858a04f7e4ff5f7f_r.jpg',
'https://ts1.cn.mm.bing.net/th/id/R-C.d59defd071ba6667d0f9a4f09663e305?rik=Z5nZoB%2bQyOxpAg&riu=http%3a%2f%2fimage.hnol.net%2fc%2f2013-02%2f06%2f19%2f201302061921067231-3280363.jpg&ehk=5IefOtlW1ii2YJbl2kzi3nzKTSBCINQwHQEGeu8ncX4%3d&risl=&pid=ImgRaw&r=0',
];