|
| 1 | +// Copyright 2013 The Flutter Authors. All rights reserved. |
| 2 | +// Use of this source code is governed by a BSD-style license that can be |
| 3 | +// found in the LICENSE file. |
| 4 | + |
| 5 | +// TODO(goderbauer): Restructure the examples to avoid this ignore, https://github.com/flutter/flutter/issues/110208. |
| 6 | +// ignore_for_file: avoid_implementing_value_types |
| 7 | + |
| 8 | +import 'package:flutter/material.dart'; |
| 9 | +import 'package:flutter_markdown_plus/flutter_markdown_plus.dart'; |
| 10 | +import 'package:flutter_markdown_plus_latex/flutter_markdown_plus_latex.dart'; |
| 11 | +import 'package:markdown/markdown.dart' as md; |
| 12 | + |
| 13 | +import '../shared/markdown_demo_widget.dart'; |
| 14 | + |
| 15 | +// ignore_for_file: public_member_api_docs |
| 16 | + |
| 17 | +const String _markdownData = r""" |
| 18 | +This is inline latex: $f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x}$ |
| 19 | +
|
| 20 | +This is block level latex: |
| 21 | +
|
| 22 | +$$ |
| 23 | +c = \pm\sqrt{a^2 + b^2} |
| 24 | +$$ |
| 25 | +
|
| 26 | +This is inline latex with displayMode: $$f(x) = \sum_{i=0}^{n} \frac{a_i}{1+x}$$ and here is a very long text that should be in the same line. |
| 27 | +
|
| 28 | +The relationship between the height and the side length of an equilateral triangle is: |
| 29 | +
|
| 30 | +\[ \text{Height} = \frac{\sqrt{3}}{2} \times \text{Side Length} \] |
| 31 | +
|
| 32 | +\[ \text{X} = \frac{1}{2} \times \text{Y} \times \text{Z} = \frac{1}{2} \times 9 \times \frac{\sqrt{3}}{2} \times 9 = \frac{81\sqrt{3}}{4} \] |
| 33 | +
|
| 34 | +The basic form of the Taylor series is: |
| 35 | +
|
| 36 | +\[f(x) = f(a) + f'(a)(x-a) + \frac{f''(a)}{2!}(x-a)^2 + \frac{f'''(a)}{3!}(x-a)^3 + \cdots\] |
| 37 | +
|
| 38 | +where \(f(x)\) is the function to be expanded, \(a\) is the expansion point, \(f'(a)\), \(f''(a)\), \(f'''(a)\), etc., are the first, second, third, and so on derivatives of the function at point \(a\), and \(n!\) denotes the factorial of \(n\). |
| 39 | +
|
| 40 | +In particular, when \(a=0\), this expansion is called the Maclaurin series. |
| 41 | +
|
| 42 | +"""; |
| 43 | + |
| 44 | +const String _notes = ''' |
| 45 | +# Latex & ChatGPT Response Demo |
| 46 | +--- |
| 47 | +
|
| 48 | +## Overview |
| 49 | +
|
| 50 | +... |
| 51 | +'''; |
| 52 | + |
| 53 | +class MarkdownLatexPluginDemo extends StatelessWidget implements MarkdownDemoWidget { |
| 54 | + const MarkdownLatexPluginDemo({super.key}); |
| 55 | + |
| 56 | + static const String _title = 'Latex & ChatGPT Response Demo'; |
| 57 | + |
| 58 | + @override |
| 59 | + String get title => MarkdownLatexPluginDemo._title; |
| 60 | + |
| 61 | + @override |
| 62 | + String get description => 'Shows the functionality of the LaTeX plugin with a ChatGPT response.'; |
| 63 | + |
| 64 | + @override |
| 65 | + Future<String> get data => Future<String>.value(_markdownData); |
| 66 | + |
| 67 | + @override |
| 68 | + Future<String> get notes => Future<String>.value(_notes); |
| 69 | + |
| 70 | + static LatexElementBuilder builder = LatexElementBuilder(); |
| 71 | + |
| 72 | + @override |
| 73 | + Widget build(BuildContext context) { |
| 74 | + return Scaffold( |
| 75 | + body: SafeArea( |
| 76 | + child: Markdown( |
| 77 | + data: _markdownData, |
| 78 | + selectable: true, |
| 79 | + builders: <String, MarkdownElementBuilder>{'latex': builder}, |
| 80 | + extensionSet: md.ExtensionSet( |
| 81 | + <md.BlockSyntax>[LatexBlockSyntax()], |
| 82 | + <md.InlineSyntax>[LatexInlineSyntax()], |
| 83 | + ), |
| 84 | + ), |
| 85 | + ), |
| 86 | + ); |
| 87 | + } |
| 88 | +} |
0 commit comments