Replace deprecated dart:html with package:web

- Updated document_viewer.dart to use web.HTMLIFrameElement/HTMLDivElement
- Updated file_explorer.dart to use web.HTMLAnchorElement for downloads
- Added web and http packages to pubspec.yaml
This commit is contained in:
Leon Bösche
2026-01-13 14:52:12 +01:00
parent 70039a8288
commit afeb7a35ad
4 changed files with 12 additions and 9 deletions

View File

@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'dart:convert';
import 'dart:html' as html;
import 'package:web/web.dart' as web;
import 'dart:ui_web' as ui;
import '../theme/app_theme.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -471,7 +471,7 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
ui.platformViewRegistry.registerViewFactory(viewType, (int viewId) {
// Create iframe pointing to the proxy endpoint
final iframe = html.IFrameElement()
final iframe = web.HTMLIFrameElement()
..style.border = 'none'
..style.width = '100%'
..style.height = '100%'
@@ -487,7 +487,7 @@ class _DocumentViewerModalState extends State<DocumentViewerModal> {
'allow-same-origin allow-scripts allow-popups allow-popups-to-escape-sandbox allow-forms allow-presentation',
);
final container = html.DivElement()
final container = web.HTMLDivElement()
..style.width = '100%'
..style.height = '100%'
..style.margin = '0'

View File

@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:file_picker/file_picker.dart' hide FileType;
import 'package:path/path.dart' as p;
import 'dart:html' as html;
import 'package:web/web.dart' as web;
import '../blocs/file_browser/file_browser_bloc.dart';
import '../blocs/file_browser/file_browser_event.dart';
import '../blocs/file_browser/file_browser_state.dart';
@@ -291,9 +291,10 @@ class _FileExplorerState extends State<FileExplorer> {
final fullUrl = '${fileService.baseUrl}$downloadUrl';
// Trigger download via anchor element
html.AnchorElement(href: fullUrl)
..setAttribute('download', file.name)
..click();
final anchor = web.HTMLAnchorElement()
..href = fullUrl
..download = file.name;
anchor.click();
if (context.mounted) {
ScaffoldMessenger.of(

View File

@@ -553,7 +553,7 @@ packages:
source: hosted
version: "2.0.1"
http:
dependency: transitive
dependency: "direct main"
description:
name: http
sha256: "87721a4a50b19c7f1d49001e51409bddc46303966ce89a65af4f4e6004896412"
@@ -1422,7 +1422,7 @@ packages:
source: hosted
version: "1.2.0"
web:
dependency: transitive
dependency: "direct main"
description:
name: web
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"

View File

@@ -55,6 +55,8 @@ dependencies:
infinite_scroll_pagination: ^5.1.1
collection: ^1.18.0
syncfusion_flutter_pdfviewer: ^31.1.21
web: ^1.1.0
http: ^1.2.0
dev_dependencies:
flutter_test: