Skip to content

Commit

Permalink
Dart format .
Browse files Browse the repository at this point in the history
  • Loading branch information
MartenM committed Feb 18, 2024
1 parent 4874454 commit e90f79f
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 38 deletions.
7 changes: 4 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ class MyApp extends StatelessWidget {
HintedStyle(defaultBBStylesheet(), "Default style"),
HintedStyle(
defaultBBStylesheet(
textStyle: const TextStyle(color: Colors.blue, fontSize: 28, height: 1)),
textStyle:
const TextStyle(color: Colors.blue, fontSize: 28, height: 1)),
"Default style with text style changed."),
HintedStyle(BBStylesheet(tags: []), "Empty style sheet"),
HintedStyle(defaultBBStylesheet().replaceTag(HeaderTag(3, 6)),
Expand Down Expand Up @@ -167,7 +168,7 @@ class _MyHomePageState extends State<MyHomePage> {
child: Center(child: parsedBBCode),
),
floatingActionButton:
Column(mainAxisAlignment: MainAxisAlignment.end, children: [
Column(mainAxisAlignment: MainAxisAlignment.end, children: [
FloatingActionButton.small(
onPressed: _selectNextExample,
tooltip: 'Next example text',
Expand All @@ -186,4 +187,4 @@ class _MyHomePageState extends State<MyHomePage> {
]),
);
}
}
}
6 changes: 4 additions & 2 deletions lib/src/default_tags/abstract_tags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ abstract class WrappedStyleTag extends AbstractTag {
/// Method that should be overwritten by the implementing tag.
/// The [spans] are all styled children of this tag.
/// A list of [InlineSpan] should be returned. For a quote tag this would be one single element.
List<InlineSpan> wrap(FlutterRenderer renderer, bbob.Element element, List<InlineSpan> spans);
List<InlineSpan> wrap(
FlutterRenderer renderer, bbob.Element element, List<InlineSpan> spans);

@override
void onTagStart(FlutterRenderer renderer) {
Expand All @@ -55,7 +56,8 @@ abstract class WrappedStyleTag extends AbstractTag {
@override
void onTagEnd(FlutterRenderer renderer) {
final wrappedElement = renderer.endWrappedStyle();
final output = wrap(renderer, wrappedElement.element, wrappedElement.parsedChildren);
final output =
wrap(renderer, wrappedElement.element, wrappedElement.parsedChildren);
renderer.appendTextSpans(output);
super.onTagEnd(renderer);
}
Expand Down
23 changes: 14 additions & 9 deletions lib/src/default_tags/basic_tags.dart
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ class QuoteTag extends WrappedStyleTag {
}) : super("quote");

@override
List<InlineSpan> wrap(FlutterRenderer renderer, bbob.Element element, List<InlineSpan> spans) {
List<InlineSpan> wrap(
FlutterRenderer renderer, bbob.Element element, List<InlineSpan> spans) {
String? author =
element.attributes.isNotEmpty ? element.attributes.values.first : null;

Expand All @@ -194,7 +195,8 @@ class SpoilerTag extends WrappedStyleTag {
SpoilerTag() : super("spoiler");

@override
List<InlineSpan> wrap(FlutterRenderer renderer, bbob.Element element, List<InlineSpan> spans) {
List<InlineSpan> wrap(
FlutterRenderer renderer, bbob.Element element, List<InlineSpan> spans) {
late String text;
if (element.attributes.isNotEmpty) {
text = "Spoiler: ${element.attributes.values.join(' ')}";
Expand All @@ -205,10 +207,10 @@ class SpoilerTag extends WrappedStyleTag {
return [
WidgetSpan(
child: SpoilerDisplay(
spoilerText: text,
content: spans,
selectable: renderer.stylesheet.selectableText,
))
spoilerText: text,
content: spans,
selectable: renderer.stylesheet.selectableText,
))
];
}
}
Expand All @@ -217,7 +219,8 @@ class LeftAlignTag extends WrappedStyleTag {
LeftAlignTag() : super("left");

@override
List<InlineSpan> wrap(FlutterRenderer renderer, bbob.Element element, List<InlineSpan> spans) {
List<InlineSpan> wrap(
FlutterRenderer renderer, bbob.Element element, List<InlineSpan> spans) {
return [
WidgetSpan(
child: SizedBox(
Expand All @@ -232,7 +235,8 @@ class CenterAlignTag extends WrappedStyleTag {
CenterAlignTag() : super("center");

@override
List<InlineSpan> wrap(FlutterRenderer renderer, bbob.Element element, List<InlineSpan> spans) {
List<InlineSpan> wrap(
FlutterRenderer renderer, bbob.Element element, List<InlineSpan> spans) {
return [
WidgetSpan(
child: SizedBox(
Expand All @@ -248,7 +252,8 @@ class RightAlignTag extends WrappedStyleTag {
RightAlignTag() : super("right");

@override
List<InlineSpan> wrap(FlutterRenderer renderer, bbob.Element element, List<InlineSpan> spans) {
List<InlineSpan> wrap(
FlutterRenderer renderer, bbob.Element element, List<InlineSpan> spans) {
return [
WidgetSpan(
child: SizedBox(
Expand Down
3 changes: 2 additions & 1 deletion lib/src/default_tags/list_tag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ abstract class AbstractListTag extends WrappedStyleTag {
}

@override
List<InlineSpan> wrap(FlutterRenderer renderer, bbob.Element element, List<InlineSpan> spans) {
List<InlineSpan> wrap(
FlutterRenderer renderer, bbob.Element element, List<InlineSpan> spans) {
// Remove accidental \n at the start and end.
if (spans.first.toPlainText() == "\n") spans.removeAt(0);
if (spans.last.toPlainText() == "\n") spans.removeLast();
Expand Down
15 changes: 11 additions & 4 deletions lib/src/default_tags/widgets/spoiler_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ class SpoilerDisplay extends StatelessWidget {
final double elevation;
final bool selectable;

const SpoilerDisplay({Key? key, required this.spoilerText, required this.content, this.elevation = 2, this.selectable = true}) : super(key: key);
const SpoilerDisplay(
{Key? key,
required this.spoilerText,
required this.content,
this.elevation = 2,
this.selectable = true})
: super(key: key);

@override
Widget build(BuildContext context) {
Expand All @@ -21,11 +27,12 @@ class SpoilerDisplay extends StatelessWidget {
Divider(height: 1),
Padding(
padding: EdgeInsets.all(10),
child: selectable ? SelectableText.rich(TextSpan(children: content)) : RichText(text: TextSpan(children: content))
)
child: selectable
? SelectableText.rich(TextSpan(children: content))
: RichText(text: TextSpan(children: content)))
],
),
),
);
}
}
}
9 changes: 6 additions & 3 deletions lib/src/style/stylesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ class BBStylesheet {

/// Constructor for a [BBStylesheet]. Requires at least a list
/// of tags to be supplied.
BBStylesheet({required Iterable<AbstractTag> tags, TextStyle? defaultText, this.selectableText = false}) {
defaultTextStyle =
defaultText ?? const TextStyle(color: Colors.black, fontSize: 14, height: 1);
BBStylesheet(
{required Iterable<AbstractTag> tags,
TextStyle? defaultText,
this.selectableText = false}) {
defaultTextStyle = defaultText ??
const TextStyle(color: Colors.black, fontSize: 14, height: 1);

for (var parser in tags) {
_tags[parser.tag] = parser;
Expand Down
12 changes: 5 additions & 7 deletions lib/src/widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ class BBCodeText extends StatelessWidget {
/// The [tagParsers] are the parsers for the tags. When left empty, all available tag parsers will be used. One might
/// want to get the subset of [_allTags] and additionally overwrite some like [UrlTag] to fit with the style scheme.
const BBCodeText(
{Key? key,
required this.data,
this.stylesheet,
this.errorBuilder})
{Key? key, required this.data, this.stylesheet, this.errorBuilder})
: super(key: key);

@override
Expand Down Expand Up @@ -79,12 +76,13 @@ class BBCodeText extends StatelessWidget {

if (stylesheet?.selectableText ?? false) {
return SelectableText.rich(
TextSpan(children: spans, style: stylesheet?.defaultTextStyle),
textScaler: textScaler,
TextSpan(children: spans, style: stylesheet?.defaultTextStyle),
textScaler: textScaler,
);
}
return RichText(
text: TextSpan(children: spans, style: stylesheet?.defaultTextStyle), textScaler: textScaler);
text: TextSpan(children: spans, style: stylesheet?.defaultTextStyle),
textScaler: textScaler);
}
}

Expand Down
12 changes: 3 additions & 9 deletions test/flutter_bbcode_internal_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,12 @@ void main() {
var newStyle = TextStyle(fontSize: 999);

var initial = defaultBBStylesheet();
var copy = initial.copyWith(
defaultTextStyle: newStyle,
selectableText: true
);
var copy =
initial.copyWith(defaultTextStyle: newStyle, selectableText: true);

expect(initial.tags, copy.tags);
expect(copy.defaultTextStyle, newStyle);
expect(copy.selectableText, true);
});


});


}
}

0 comments on commit e90f79f

Please sign in to comment.