1 Star 0 Fork 0

chenanshun/flutter_html

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
interactable_element.dart 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
import 'package:flutter/material.dart';
import 'package:flutter_html/src/html_elements.dart';
import 'package:flutter_html/style.dart';
import 'package:html/dom.dart' as dom;
/// An [InteractableElement] is a [StyledElement] that takes user gestures (e.g. tap).
class InteractableElement extends StyledElement {
String? href;
InteractableElement({
required String name,
required List<StyledElement> children,
required Style style,
required this.href,
required dom.Node node,
required String elementId,
}) : super(name: name, children: children, style: style, node: node as dom.Element?, elementId: elementId);
}
/// A [Gesture] indicates the type of interaction by a user.
enum Gesture {
TAP,
}
StyledElement parseInteractableElement(
dom.Element element, List<StyledElement> children) {
switch (element.localName) {
case "a":
if (element.attributes.containsKey('href')) {
return InteractableElement(
name: element.localName!,
children: children,
href: element.attributes['href'],
style: Style(
color: Colors.blue,
textDecoration: TextDecoration.underline,
),
node: element,
elementId: element.id
);
}
// When <a> tag have no href, it must be non clickable and without decoration.
return StyledElement(
name: element.localName!,
children: children,
style: Style(),
node: element,
elementId: element.id,
);
/// will never be called, just to suppress missing return warning
default:
return InteractableElement(
name: element.localName!,
children: children,
node: element,
href: '',
style: Style(),
elementId: "[[No ID]]"
);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chenanshun/flutter_html.git
git@gitee.com:chenanshun/flutter_html.git
chenanshun
flutter_html
flutter_html
master

搜索帮助