Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement new package fwfh_math #471

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions demo_app/lib/screens/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'huge_html.dart';
import 'iframe.dart';
import 'img.dart';
import 'img_file.dart';
import 'math.dart';
import 'photo_view.dart';
import 'smilie.dart';
import 'video.dart';
Expand All @@ -25,6 +26,7 @@ class HomeScreen extends StatelessWidget {
'Iframe': () => const IframeScreen(),
'Images': () => const ImgScreen(),
'Image (file://)': () => const ImgFileScreen(),
'Math': () => const MathScreen(),
'Video': () => const VideoScreen(),
'customStylesBuilder': () => const CustomStylesBuilderScreen(),
'customWidgetBuilder': () => const CustomWidgetBuilderScreen(),
Expand Down
22 changes: 22 additions & 0 deletions demo_app/lib/screens/math.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:fwfh_math/fwfh_math.dart';

class MathScreen extends StatelessWidget {
const MathScreen({Key key}) : super(key: key);

@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('MathFactory Demo'),
),
body: Center(
child: HtmlWidget(
r'Check this out: <math>x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}</math>',
factoryBuilder: () => MyWidgetFactory(),
),
),
);
}

class MyWidgetFactory extends WidgetFactory with MathFactory {}
3 changes: 3 additions & 0 deletions demo_app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
flutter_widget_from_html: any
flutter_widget_from_html_core: any
fwfh_chewie: any
fwfh_math: any
fwfh_url_launcher: any
fwfh_webview: any
html: any
Expand All @@ -35,6 +36,8 @@ dependency_overrides:
path: ../packages/fwfh_chewie
fwfh_just_audio:
path: ../packages/fwfh_just_audio
fwfh_math:
path: ../packages/fwfh_math
fwfh_svg:
path: ../packages/fwfh_svg
fwfh_url_launcher:
Expand Down
3 changes: 3 additions & 0 deletions packages/fwfh_math/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.6.0-rc.2021022601

- First release
21 changes: 21 additions & 0 deletions packages/fwfh_math/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Dao Hoang Son

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
39 changes: 39 additions & 0 deletions packages/fwfh_math/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# MathFactory

![Flutter](https://github.com/daohoangson/flutter_widget_from_html/workflows/Flutter/badge.svg)
[![codecov](https://codecov.io/gh/daohoangson/flutter_widget_from_html/branch/master/graph/badge.svg)](https://codecov.io/gh/daohoangson/flutter_widget_from_html)
[![Pub](https://img.shields.io/pub/v/fwfh_math.svg)](https://pub.dev/packages/fwfh_math)

WidgetFactory extension to render math equation with [flutter_math](https://pub.dev/packages/flutter_math) package.
This is a companion add-on for [flutter_widget_from_html_core](https://pub.dev/packages/flutter_widget_from_html_core) package.

## Getting Started

Add this to your app's `pubspec.yaml` file:

```yaml
dependencies:
flutter_widget_from_html_core: any
fwfh_math: ^0.6.0
```

## Usage

Then use `HtmlWidget` with a custom factory:

```dart
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:fwfh_math/fwfh_math.dart';

// ...

HtmlWidget(
html,
factoryBuilder: () => MyWidgetFactory(),
)

// ...

class MyWidgetFactory extends WidgetFactory with MathFactory {
}
```
1 change: 1 addition & 0 deletions packages/fwfh_math/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:pedantic/analysis_options.yaml
27 changes: 27 additions & 0 deletions packages/fwfh_math/example/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:fwfh_math/fwfh_math.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'fwfh_math',
home: Scaffold(
appBar: AppBar(
title: Text('MathFactory Demo'),
),
body: Center(
child: HtmlWidget(
r'Check this out: <math>x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}</math>',
factoryBuilder: () => MyWidgetFactory(),
),
),
),
);
}
}

class MyWidgetFactory extends WidgetFactory with MathFactory {}
1 change: 1 addition & 0 deletions packages/fwfh_math/lib/fwfh_math.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'src/math_factory.dart';
19 changes: 19 additions & 0 deletions packages/fwfh_math/lib/src/math_factory.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:flutter_math_fork/flutter_math.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';

/// A mixin that can render math equation with `flutter_math` package.
mixin MathFactory on WidgetFactory {
@override
void parse(BuildMetadata meta) {
if (meta.element.localName == 'math') {
meta.register(BuildOp(
onTree: (meta, tree) {
tree.replaceWith(
WidgetBit.inline(tree, Math.tex(meta.element.innerHtml)));
},
));
}

super.parse(meta);
}
}
27 changes: 27 additions & 0 deletions packages/fwfh_math/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: fwfh_math
version: 0.6.0-rc.2021022601
description: WidgetFactory extension to render math equation with flutter_math package.
homepage: https://github.com/daohoangson/flutter_widget_from_html
publish_to: none

environment:
flutter: ">=2.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
sdk: flutter
flutter_widget_from_html_core: ^0.6.0-0
flutter_math_fork:
git:
url: https://github.com/simpleclub-extended/flutter_math_fork.git
ref: 100a5783ac7aa9dafb70273766dc275dab7f5517

dependency_overrides:
flutter_widget_from_html_core:
path: ../core

dev_dependencies:
flutter_test:
sdk: flutter
pedantic: any