David PHAM-VAN

Add Markdown example

1 # Changelog 1 # Changelog
2 2
  3 +## 2.1.9
  4 +
  5 +- Add Markdown example
  6 +
3 ## 2.1.8 7 ## 2.1.8
4 8
5 - Revert "Update plugin platforms" (Flutter 1.9.1) 9 - Revert "Update plugin platforms" (Flutter 1.9.1)
@@ -6,6 +6,7 @@ import 'dart:ui' as ui; @@ -6,6 +6,7 @@ import 'dart:ui' as ui;
6 import 'package:flutter/material.dart'; 6 import 'package:flutter/material.dart';
7 import 'package:flutter/rendering.dart'; 7 import 'package:flutter/rendering.dart';
8 import 'package:flutter/services.dart'; 8 import 'package:flutter/services.dart';
  9 +import 'package:markdown/markdown.dart' as markdown;
9 import 'package:path_provider/path_provider.dart'; 10 import 'package:path_provider/path_provider.dart';
10 11
11 import 'package:pdf/pdf.dart'; 12 import 'package:pdf/pdf.dart';
@@ -141,6 +142,16 @@ class MyAppState extends State<MyApp> { @@ -141,6 +142,16 @@ class MyAppState extends State<MyApp> {
141 }); 142 });
142 } 143 }
143 144
  145 + Future<void> _printMarkdown() async {
  146 + print('Print Markdown ...');
  147 + await Printing.layoutPdf(onLayout: (PdfPageFormat format) async {
  148 + final String md = await rootBundle.loadString('assets/example.md');
  149 + final String html = markdown.markdownToHtml(md,
  150 + extensionSet: markdown.ExtensionSet.gitHubWeb);
  151 + return await Printing.convertHtml(format: format, html: html);
  152 + });
  153 + }
  154 +
144 @override 155 @override
145 Widget build(BuildContext context) { 156 Widget build(BuildContext context) {
146 bool canDebug = false; 157 bool canDebug = false;
@@ -187,6 +198,9 @@ class MyAppState extends State<MyApp> { @@ -187,6 +198,9 @@ class MyAppState extends State<MyApp> {
187 child: const Text('Save to file'), onPressed: _saveAsFile), 198 child: const Text('Save to file'), onPressed: _saveAsFile),
188 RaisedButton( 199 RaisedButton(
189 child: const Text('Print Html'), onPressed: _printHtml), 200 child: const Text('Print Html'), onPressed: _printHtml),
  201 + RaisedButton(
  202 + child: const Text('Print Markdown'),
  203 + onPressed: _printMarkdown),
190 canDebug 204 canDebug
191 ? Row( 205 ? Row(
192 mainAxisSize: MainAxisSize.min, 206 mainAxisSize: MainAxisSize.min,
@@ -14,6 +14,7 @@ dependencies: @@ -14,6 +14,7 @@ dependencies:
14 flutter_full_pdf_viewer: 14 flutter_full_pdf_viewer:
15 cupertino_icons: 15 cupertino_icons:
16 qr: 16 qr:
  17 + markdown:
17 18
18 dev_dependencies: 19 dev_dependencies:
19 flutter_test: 20 flutter_test: