8000 Fix analysis and code format issues by Sub6Resources · Pull Request #1148 · Sub6Resources/flutter_html · GitHub
[go: up one dir, main page]

Skip to content

Fix analysis and code format issues #1148

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

Merged
merged 13 commits into from
Sep 27, 2022
Merged
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
6 changes: 6 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ jobs:
command: melos run gen_coverage
- codecov/upload:
file: coverage_report/lcov.info
- run:
name: Run flutter analyze
command: melos run analyze
- run:
name: Check That Flutter Code is Formatted Correctly
command: flutter format -o none --set-exit-if-changed .
29 changes: 29 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
139 changes: 79 additions & 60 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_html_all/flutter_html_all.dart';
import 'package:flutter_math_fork/flutter_math.dart';

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

class MyApp extends StatelessWidget {
const MyApp({super.key});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return new MaterialApp(
return MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
theme: ThemeData(
primarySwatch: Colors.deepPurple,
),
home: new MyHomePage(title: 'flutter_html Example'),
home: const MyHomePage(title: 'flutter_html Example'),
);
}
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key? key, required this.title}) : super(key: key);
const MyHomePage({Key? key, required this.title}) : super(key: key);

final String title;

@override
_MyHomePageState createState() => new _MyHomePageState();
MyHomePageState createState() => MyHomePageState();
}

const htmlData = r"""
Expand Down Expand Up @@ -66,9 +67,9 @@ const htmlData = r"""
<div style="width: 150px; height: 20px; background-color: #ff99ff; margin: 15px auto;">margin: 15px auto</div>
<div style="width: 150px; height: 20px; background-color: #9999ff; margin-left: auto;">margin-left: auto</div>
<p>With an image - non-block (should not center):</p>
<img style="margin: auto;" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png">
<img alt='' style="margin: auto;" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png">
<p>block image (should center):</p>
<img style="display: block; margin: auto;" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png">
<img alt='' style="display: block; margin: auto;" src="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_92x30dp.png">
<h3>Table support (with custom styling!):</h3>
<p>
<q>Famous quote...</q>
Expand Down Expand Up @@ -253,18 +254,19 @@ const htmlData = r"""

final staticAnchorKey = GlobalKey();

class _MyHomePageState extends State<MyHomePage> {
class MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
return Scaffold(
appBar: AppBar(
title: Text('flutter_html Example'),
title: const Text('flutter_html Example'),
centerTitle: true,
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.arrow_downward),
child: const Icon(Icons.arrow_downward),
onPressed: () {
final anchorContext = AnchorKey.forId(staticAnchorKey, "bottom")?.currentContext;
final anchorContext =
AnchorKey.forId(staticAnchorKey, "bottom")?.currentContext;
if (anchorContext != null) {
Scrollable.ensureVisible(anchorContext);
}
Expand All @@ -276,94 +278,111 @@ class _MyHomePageState extends State<MyHomePage> {
data: htmlData,
style: {
"table": Style(
backgroundColor: Color.fromARGB(0x50, 0xee, 0xee, 0xee),
backgroundColor: const Color.fromARGB(0x50, 0xee, 0xee, 0xee),
),
"tr": Style(
border: Border(bottom: BorderSide(color: Colors.grey)),
border: const Border(bottom: BorderSide(color: Colors.grey)),
),
"th": Style(
padding: EdgeInsets.all(6),
padding: const EdgeInsets.all(6),
backgroundColor: Colors.grey,
),
"td": Style(
padding: EdgeInsets.all(6),
padding: const EdgeInsets.all(6),
alignment: Alignment.topLeft,
),
'h5': Style(maxLines: 2, textOverflow: TextOverflow.ellipsis),
},
tagsList: Html.tags..addAll(['tex', 'bird', 'flutter']),
customRenders: {
tagMatcher("tex"): CustomRender.widget(widget: (context, buildChildren) => Math.tex(
context.tree.element?.innerHtml ?? '',
mathStyle: MathStyle.display,
textStyle: context.style.generateTextStyle(),
onErrorFallback: (FlutterMathException e) {
return Text(e.message);
},
)),
tagMatcher("bird"): CustomRender.inlineSpan(inlineSpan: (context, buildChildren) => TextSpan(text: "🐦")),
tagMatcher("flutter"): CustomRender.widget(widget: (context, buildChildren) => FlutterLogo(
style: (context.tree.element!.attributes['horizontal'] != null)
? FlutterLogoStyle.horizontal
: FlutterLogoStyle.markOnly,
textColor: context.style.color!,
size: context.style.fontSize!.value * 5,
)),
tagMatcher("table"): CustomRender.widget(widget: (context, buildChildren) => SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: tableRender.call().widget!.call(context, buildChildren),
)),
tagMatcher("tex"): CustomRender.widget(
widget: (context, buildChildren) => Math.tex(
context.tree.element?.innerHtml ?? '',
mathStyle: MathStyle.display,
textStyle: context.style.generateTextStyle(),
onErrorFallback: (FlutterMathException e) {
return Text(e.message);
},
)),
tagMatcher("bird"): CustomRender.inlineSpan(
inlineSpan: (context, buildChildren) =>
const TextSpan(text: "🐦")),
tagMatcher("flutter"): CustomRender.widget(
widget: (context, buildChildren) => FlutterLogo(
style: (context.tree.element!.attributes['horizontal'] !=
null)
? FlutterLogoStyle.horizontal
: FlutterLogoStyle.markOnly,
textColor: context.style.color!,
size: context.style.fontSize!.value * 5,
)),
tagMatcher("table"): CustomRender.widget(
widget: (context, buildChildren) => SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: tableRender
.call()
.widget!
.call(context, buildChildren),
)),
audioMatcher(): audioRender(),
iframeMatcher(): iframeRender(),
mathMatcher(): mathRender(onMathError: (error, exception, exceptionWithType) {
print(exception);
mathMatcher():
mathRender(onMathError: (error, exception, exceptionWithType) {
debugPrint(exception);
return Text(exception);
}),
svgTagMatcher(): svgTagRender(),
svgDataUriMatcher(): svgDataImageRender(),
svgAssetUriMatcher(): svgAssetImageRender(),
svgNetworkSourceMatcher(): svgNetworkImageRender(),
networkSourceMatcher(domains: ["flutter.dev"]): CustomRender.widget(
widget: (context, buildChildren) {
return FlutterLogo(size: 36);
}),
networkSourceMatcher(domains: ["flutter.dev"]):
CustomRender.widget(widget: (context, buildChildren) {
return const FlutterLogo(size: 36);
}),
networkSourceMatcher(domains: ["mydomain.com"]): networkImageRender(
headers: {"Custom-Header": "some-value"},
altWidget: (alt) => Text(alt ?? ""),
loadingWidget: () => Text("Loading..."),
loadingWidget: () => const Text("Loading..."),
),
// On relative paths starting with /wiki, prefix with a base url
(context) => context.tree.element?.attributes["src"] != null
&& context.tree.element!.attributes["src"]!.startsWith("/wiki"):
networkImageRender(mapUrl: (url) => "https://upload.wikimedia.org" + url!),
(context) =>
context.tree.element?.attributes["src"] != null &&
context.tree.element!.attributes["src"]!
.startsWith("/wiki"): networkImageRender(
mapUrl: (url) => "https://upload.wikimedia.org${url!}"),
// Custom placeholder image for broken links
networkSourceMatcher(): networkImageRender(altWidget: (_) => FlutterLogo()),
networkSourceMatcher():
networkImageRender(altWidget: (_) => const FlutterLogo()),
videoMatcher(): videoRender(),
},
onLinkTap: (url, _, __, ___) {
print("Opening $url...");
debugPrint("Opening $url...");
},
onImageTap: (src, _, __, ___) {
print(src);
debugPrint(src);
},
onImageError: (exception, stackTrace) {
print(exception);
debugPrint(exception.toString());
},
onCssParseError: (css, messages) {
print("css that errored: $css");
print("error messages:");
messages.forEach((element) {
print(element);
});
debugPrint("css that errored: $css");
debugPrint("error messages:");
for (var element in messages) {
debugPrint(element.toString());
}
return '';
},
),
),
);
}
}

CustomRenderMatcher texMatcher() => (context) => context.tree.element?.localName == 'tex';
CustomRenderMatcher texMatcher() =>
(context) => context.tree.element?.localName == 'tex';

CustomRenderMatcher birdMatcher() => (context) => context.tree.element?.localName == 'bird';
CustomRenderMatcher birdMatcher() =>
(context) => context.tree.element?.localName == 'bird';

CustomRenderMatcher flutterMatcher() => (context) => context.tree.element?.localName == 'flutter';
CustomRenderMatcher flutterMatcher() =>
(context) => context.tree.element?.localName == 'flutter';
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.1

flutter:

Expand Down
Loading
0