feat: import SvgPicture package to display SVG

This commit is contained in:
Lucas.Xu 2022-07-27 22:06:32 +08:00
parent 45a8566e61
commit c5560caf3c
6 changed files with 80 additions and 7 deletions

View File

@ -0,0 +1,4 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="2" y="2" width="12" height="12" rx="4" fill="#00BCF0"/>
<path d="M6 8L7.61538 9.5L10.5 6.5" stroke="white" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

After

Width:  |  Height:  |  Size: 268 B

View File

@ -0,0 +1,3 @@
<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="2.5" y="2.5" width="11" height="11" rx="3.5" stroke="#BDBDBD"/>
</svg>

After

Width:  |  Height:  |  Size: 176 B

View File

@ -76,6 +76,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
flutter_svg:
dependency: transitive
description:
name: flutter_svg
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.1+1"
flutter_test:
dependency: "direct dev"
description: flutter
@ -135,6 +142,27 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.1"
path_drawing:
dependency: transitive
description:
name: path_drawing
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
path_parsing:
dependency: transitive
description:
name: path_parsing
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.0"
plugin_platform_interface:
dependency: transitive
description:
@ -259,6 +287,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.0"
sdks:
dart: ">=2.17.0 <3.0.0"
flutter: ">=2.10.0"
flutter: ">=2.11.0-0.1.pre"

View File

@ -0,0 +1,27 @@
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
class FlowySvg extends StatelessWidget {
const FlowySvg({
Key? key,
required this.name,
required this.size,
this.color,
}) : super(key: key);
final String name;
final Size size;
final Color? color;
@override
Widget build(BuildContext context) {
return SizedBox.fromSize(
size: size,
child: SvgPicture.asset(
'assets/images/$name.svg',
color: color,
package: 'flowy_editor',
),
);
}
}

View File

@ -2,6 +2,7 @@ import 'package:flowy_editor/render/rich_text/rich_text_style.dart';
import 'package:flowy_editor/flowy_editor.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flowy_editor/infra/flowy_svg.dart';
class RichTextNodeWidgetBuilder extends NodeWidgetBuilder {
RichTextNodeWidgetBuilder.create({
@ -154,15 +155,16 @@ class _FlowyRichTextState extends State<FlowyRichText> with Selectable {
}
Widget _buildTodoListRichText(BuildContext context) {
final name = _textNode.attributes.todo ? 'check' : 'uncheck';
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GestureDetector(
child: Icon(
child: FlowySvg(
name: name,
key: _decorationKey,
_textNode.attributes.todo
? Icons.square_rounded
: Icons.square_outlined),
size: const Size.square(20),
),
onTap: () => TransactionBuilder(_editorState)
..updateNode(_textNode, {
'todo': !_textNode.attributes.todo,

View File

@ -11,6 +11,7 @@ dependencies:
flutter:
sdk: flutter
flutter_svg: ^1.1.1+1
provider: ^6.0.3
dev_dependencies:
@ -26,7 +27,8 @@ flutter:
# To add assets to your package, add an assets section, like this:
assets:
- document.json
- assets/images/uncheck.svg
- assets/images/
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#