Skip to main content

rich_markdown 0.1.0 copy "rich_markdown: ^0.1.0" to clipboard
rich_markdown: ^0.1.0 copied to clipboard

A Flutter package for rendering Markdown, LaTeX, and HTML content.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:rich_markdown/rich_markdown.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Universal Content Demo',
      theme: ThemeData(colorSchemeSeed: Colors.indigo, useMaterial3: true),
      home: const DemoScreen(),
    );
  }
}

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

  @override
  State<DemoScreen> createState() => _DemoScreenState();
}

class _DemoScreenState extends State<DemoScreen> {
  ContentType selectedType = ContentType.markdown;

  final markdownContent = r'''
# Universal Content

This is **bold**, *italic*, and ~~strikethrough~~.

## LaTeX

Inline equation: \(E = mc^2\)

Block equation:

$$
\int_0^1 x^2\,dx = \frac{1}{3}
$$

## Lists

- Markdown support
- Mathematical formulas
- Reusable Flutter widget

> A blockquote example.

[Open Flutter](https://flutter.dev)
''';

  final htmlContent = r'''
<h2>HTML content</h2>
<p>This is <strong>bold HTML</strong> and
<em>italic HTML</em>.</p>

<ul>
  <li>First item</li>
  <li>Second item</li>
</ul>

<p>Inline math: <tex>Uj1hXjI=</tex></p>
''';

  final latexContent = r'\int_0^\infty e^{-x}\,dx = 1';

  @override
  Widget build(BuildContext context) {
    final content = switch (selectedType) {
      ContentType.markdown => markdownContent,
      ContentType.html => htmlContent,
      ContentType.latex => latexContent,
    };

    return Scaffold(
      appBar: AppBar(title: const Text('Universal Content')),
      body: ListView(
        padding: const EdgeInsets.all(20),
        children: [
          SegmentedButton<ContentType>(
            segments: const [
              ButtonSegment(
                value: ContentType.markdown,
                label: Text('Markdown'),
              ),
              ButtonSegment(value: ContentType.latex, label: Text('LaTeX')),
              ButtonSegment(value: ContentType.html, label: Text('HTML')),
            ],
            selected: {selectedType},
            onSelectionChanged: (selection) {
              setState(() {
                selectedType = selection.first;
              });
            },
          ),
          const SizedBox(height: 24),
          RichMarkdownView(
            data: content,
            type: selectedType,
            textStyle: const TextStyle(fontSize: 16, height: 1.5),
            onLinkTap: (url) {
              debugPrint('Tapped link: $url');
            },
          ),
        ],
      ),
    );
  }
}
8
likes
130
points
450
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Flutter package for rendering Markdown, LaTeX, and HTML content.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, flutter_html, flutter_math_fork, html, markdown

More

Packages that depend on rich_markdown