Skip to content
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
3 changes: 3 additions & 0 deletions demo_app/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ analyzer:
# TODO: remove this when it auto ignores `depend_on_referenced_packages`
- lib/generated_plugin_registrant.dart

formatter:
trailing_commas: preserve

linter:
rules:
always_put_control_body_on_new_line: true
12 changes: 7 additions & 5 deletions demo_app/integration_test/auto_resize_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void main() {
child: VideoPlayer(
'https://flutter-widget-from-html.github.io/pages/flower.mp4',
aspectRatio: 1,
loadingBuilder: (_, __, ___) =>
loadingBuilder: (_, _, _) =>
const Center(child: CircularProgressIndicator()),
),
);
Expand All @@ -36,10 +36,11 @@ void main() {
final testCase = webViewTestCases.currentValue!;
final test = await testCase.run($);

for (var i = 0;; i++) {
for (var i = 0; ; i++) {
await $.pump();
await $.tester
.runAsync(() => Future.delayed(const Duration(seconds: 3)));
await $.tester.runAsync(
() => Future.delayed(const Duration(seconds: 3)),
);
await $.pump();

try {
Expand Down Expand Up @@ -70,7 +71,8 @@ class WebViewTestCase {
});

Future<_AspectRatioTest> run(PatrolIntegrationTester $) async {
final html = '''
final html =
'''
<!doctype html>
<head>
<meta charset="utf-8">
Expand Down
23 changes: 12 additions & 11 deletions demo_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ void main() {
}

void _onLogRecord(LogRecord record) {
final prefix = '${record.time.toIso8601String().substring(11)} '
final prefix =
'${record.time.toIso8601String().substring(11)} '
'${record.loggerName}@${record.level.name} ';
debugPrint('$prefix${record.message}');

Expand All @@ -28,15 +29,15 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) => PopupMenuStateProvider(
builder: (context) => MaterialApp(
title: 'Flutter Widget from HTML',
theme: FlexThemeData.light(scheme: FlexScheme.blueM3),
darkTheme: FlexThemeData.dark(scheme: FlexScheme.blueM3),
showPerformanceOverlay: context.showPerformanceOverlay,
builder: (context) => MaterialApp(
title: 'Flutter Widget from HTML',
theme: FlexThemeData.light(scheme: FlexScheme.blueM3),
darkTheme: FlexThemeData.dark(scheme: FlexScheme.blueM3),
showPerformanceOverlay: context.showPerformanceOverlay,

// let HomeScreen handle all the routings
initialRoute: '/',
onGenerateRoute: HomeScreen.onGenerateRoute,
),
);
// let HomeScreen handle all the routings
initialRoute: '/',
onGenerateRoute: HomeScreen.onGenerateRoute,
),
);
}
113 changes: 57 additions & 56 deletions demo_app/lib/screens/audio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,74 +24,75 @@ class _State extends State<AudioScreen> {

@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('AudioScreen'),
appBar: AppBar(
title: const Text('AudioScreen'),
),
body: ListView(
children: <Widget>[
CheckboxListTile(
value: autoplay,
onChanged: (v) => _setState(() => autoplay = v == true),
title: const Text('autoplay'),
),
body: ListView(
children: <Widget>[
CheckboxListTile(
value: autoplay,
onChanged: (v) => _setState(() => autoplay = v == true),
title: const Text('autoplay'),
),
CheckboxListTile(
value: loop,
onChanged: (v) => _setState(() => loop = v == true),
title: const Text('loop'),
),
CheckboxListTile(
value: muted,
onChanged: (v) => _setState(() => muted = v == true),
title: const Text('muted'),
),
CheckboxListTile(
value: preload,
onChanged: (v) => _setState(() => preload = v == true),
title: const Text('preload'),
),
ListTile(
title: const Text('HTML:'),
subtitle: Text(_html),
),
ListTile(
title: const Text('Rendered:'),
subtitle: HtmlWidget(
_html,
key: Key(_html),
baseUrl: Uri.parse(
'https://interactive-examples.mdn.mozilla.net/pages/tabbed/audio.html',
),
),
CheckboxListTile(
value: loop,
onChanged: (v) => _setState(() => loop = v == true),
title: const Text('loop'),
),
CheckboxListTile(
value: muted,
onChanged: (v) => _setState(() => muted = v == true),
title: const Text('muted'),
),
CheckboxListTile(
value: preload,
onChanged: (v) => _setState(() => preload = v == true),
title: const Text('preload'),
),
ListTile(
title: const Text('HTML:'),
subtitle: Text(_html),
),
ListTile(
title: const Text('Rendered:'),
subtitle: HtmlWidget(
_html,
key: Key(_html),
baseUrl: Uri.parse(
'https://interactive-examples.mdn.mozilla.net/pages/tabbed/audio.html',
),
const Center(child: Text('----')),
],
),
),
);
const Center(child: Text('----')),
],
),
);

void _setState(VoidCallback callback) => setState(() {
callback();
callback();

final attributes = <String>[];
if (autoplay) {
attributes.add('autoplay');
}
if (loop) {
attributes.add('loop');
}
if (muted) {
attributes.add('muted');
}
if (preload) {
attributes.add('preload');
}
final attributes = <String>[];
if (autoplay) {
attributes.add('autoplay');
}
if (loop) {
attributes.add('loop');
}
if (muted) {
attributes.add('muted');
}
if (preload) {
attributes.add('preload');
}

_html = '''
_html =
'''
<figure>
<audio src="/media/cc0-audio/t-rex-roar.mp3" ${attributes.join(' ')}>
Sorry, <code>AUDIO</code> tag is not supported.
</audio>
<figcaption>Source: <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/audio">developer.mozilla.org</a></figcaption>
</figure>
''';
});
});
}
24 changes: 12 additions & 12 deletions demo_app/lib/screens/custom_styles_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ class CustomStylesBuilderScreen extends StatelessWidget {

@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('CustomStylesBuilderScreen'),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: HtmlWidget(
kHtml,
customStylesBuilder: (e) =>
e.classes.contains('name') ? {'color': 'red'} : null,
),
),
);
appBar: AppBar(
title: const Text('CustomStylesBuilderScreen'),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: HtmlWidget(
kHtml,
customStylesBuilder: (e) =>
e.classes.contains('name') ? {'color': 'red'} : null,
),
),
);
}
69 changes: 34 additions & 35 deletions demo_app/lib/screens/custom_widget_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,44 @@ class CustomWidgetBuilderScreen extends StatelessWidget {

@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('CustomWidgetBuilderScreen'),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: HtmlWidget(
kHtml,
customWidgetBuilder: (e) {
if (!e.classes.contains('carousel')) {
return null;
}
appBar: AppBar(
title: const Text('CustomWidgetBuilderScreen'),
),
body: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: HtmlWidget(
kHtml,
customWidgetBuilder: (e) {
if (!e.classes.contains('carousel')) {
return null;
}

final srcs = <String>[];
for (final child in e.children) {
for (final grandChild in child.children) {
if (grandChild.attributes case {'src': final String src}) {
srcs.add(src);
}
}
final srcs = <String>[];
for (final child in e.children) {
for (final grandChild in child.children) {
if (grandChild.attributes case {'src': final String src}) {
srcs.add(src);
}
}
}

return CarouselSlider(
options: CarouselOptions(
autoPlay: true,
autoPlayAnimationDuration:
const Duration(milliseconds: 500),
autoPlayInterval: const Duration(seconds: 2),
enlargeCenterPage: true,
),
items: srcs.map(_toItem).toList(growable: false),
);
},
),
),
return CarouselSlider(
options: CarouselOptions(
autoPlay: true,
autoPlayAnimationDuration: const Duration(milliseconds: 500),
autoPlayInterval: const Duration(seconds: 2),
enlargeCenterPage: true,
),
items: srcs.map(_toItem).toList(growable: false),
);
},
),
);
),
),
);

static Widget _toItem(String src) => Center(
child: Image.network(src, fit: BoxFit.cover, width: 1000),
);
child: Image.network(src, fit: BoxFit.cover, width: 1000),
);
}
Loading
Loading