Tag class abstract

Abstract base class for creating and manipulating HTML elements programmatically. Tag provides a foundation for building HTML structures in Dart code with support for attributes, child elements, CSS classes, and inline styles. It offers a fluent API for chaining operations and maintains the hierarchical structure of HTML documents. Key features:

  • Dynamic attribute management
  • CSS class manipulation
  • Inline style handling
  • Child element management
  • HTML string generation
  • Fluent method chaining Example usage:
final div = CustomTag('div')
  .addClass('container')
  .addAttr('data-id', '123')
  .addStyle('background-color', 'blue')
  .addChild(CustomTag('p').addChild(TextTag('Hello World')));
String html = div.toHtml();
// Result: <div class="container" data-id="123" style="background-color: blue; "><p>Hello World</p></div>
Implementers

Constructors

Tag({Map? attrs, List<Tag>? children, List classes = const []})

Properties

attrs ↔ Map
getter/setter pair
children ↔ List<Tag>
getter/setter pair
classes ↔ List
getter/setter pair
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
tagName → String
no setter
type ↔ TagType
getter/setter pair

Methods

addAttr(String key, dynamic value) → Tag
addChild(Tag child) → Tag
addClass(dynamic className) → Tag
addStyle(String property, String value) → Tag
attrKey(dynamic key) → String
clearChildren() → Tag
clearClasses() → Tag
clearStyles() → Tag
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
removeAttr(String key) → Tag
removeChild(Tag child) → Tag
removeClass(String className) → Tag
removeStyle(String property) → Tag
setClass(String className) → Tag
setId(String id) → Tag
setStyle(String property, String value) → Tag
toHtml() → String
toString({bool pretty = false}) → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited