Skip to content

Commit

Permalink
feat: add download button to HTML view screen
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-i committed Dec 27, 2023
1 parent 45108c5 commit 315fd37
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
18 changes: 18 additions & 0 deletions app/lib/html_view_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:html';
import 'dart:html' as html;
import 'dart:ui_web' as ui;
import 'package:flutter/material.dart';

Expand Down Expand Up @@ -26,9 +27,26 @@ class HtmlViewScreen extends StatelessWidget {
},
);

// Function to download the content
void downloadContent() {
final blob = html.Blob([htmlContent]);
final url = html.Url.createObjectUrlFromBlob(blob);
final anchor = html.AnchorElement(href: url)
..setAttribute("download", "${appName}.html")
..click();
html.Url.revokeObjectUrl(url);
}

return Scaffold(
appBar: AppBar(
title: Text(appName),
actions: [
IconButton(
icon: Icon(Icons.download),
onPressed: downloadContent, // Trigger the download
tooltip: 'Download Code',
),
],
),
body: HtmlElementView(
key: ValueKey(contentKey), // Use the unique key for the HtmlElementView
Expand Down
17 changes: 11 additions & 6 deletions app/lib/paint_window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ class _PaintWindowState extends State<PaintWindow> {
setState(() {
isLoading = false;
});

clear();
}

void clear() {
nameController.clear();
setState(() {
points.clear();
});
}

@override
Expand All @@ -198,7 +207,7 @@ class _PaintWindowState extends State<PaintWindow> {
}

return AlertDialog(
title: const Text('Paint Window'),
title: const Text('Magic Window'),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
Expand Down Expand Up @@ -251,11 +260,7 @@ class _PaintWindowState extends State<PaintWindow> {
else
TextButton(
child: const Text('Clear'),
onPressed: () {
setState(() {
points.clear();
});
},
onPressed: clear,
),
TextButton(
child: const Text('Build'),
Expand Down

0 comments on commit 315fd37

Please sign in to comment.