improved tab handling by id

This commit is contained in:
Fabian Freund
2024-08-19 04:27:47 +02:00
parent a465195ec4
commit 23dad27d61
12 changed files with 78 additions and 40 deletions
@@ -0,0 +1,10 @@
import 'package:drift/drift.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
abstract interface class ITab {
String get id;
Uri get url;
String? get title;
Favicon? get favicon;
Uint8List? get screenshot;
}
@@ -3,25 +3,35 @@ import 'package:fast_equatable/fast_equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:lensai/core/uuid.dart';
import 'package:lensai/domain/entities/web_page_info.dart';
import 'package:lensai/features/web_view/domain/entities/abstract/tab.dart';
part 'web_view_page.g.dart';
typedef PageHistory = ({bool canGoBack, bool canGoForward});
@CopyWith(constructor: '_')
class WebViewPage extends WebPageInfo with FastEquatable {
class WebViewPage extends WebPageInfo with FastEquatable implements ITab {
@CopyWithField(immutable: true)
final Key key;
@override
@CopyWithField(immutable: true)
final String id;
final InAppWebViewController? controller;
// ignore: missing_field_in_equatable_props
final SslError? sslError;
@override
final Uint8List? screenshot;
final PageHistory pageHistory;
WebViewPage({
String? id,
this.controller,
required super.url,
this.sslError,
@@ -29,10 +39,12 @@ class WebViewPage extends WebPageInfo with FastEquatable {
super.favicon,
this.screenshot,
this.pageHistory = (canGoBack: false, canGoForward: false),
}) : key = GlobalKey();
}) : key = GlobalKey(),
id = id ?? uuid.v7();
WebViewPage._({
required this.key,
required this.id,
required this.controller,
required super.url,
required this.sslError,
@@ -48,8 +60,9 @@ class WebViewPage extends WebPageInfo with FastEquatable {
@override
List<Object?> get hashParameters => [
key,
id,
controller,
url,
super.url,
sslError?.toString(),
title,
favicon?.toString(),
@@ -86,6 +86,7 @@ class _$WebViewPageCWProxyImpl implements _$WebViewPageCWProxy {
}) {
return WebViewPage._(
key: _value.key,
id: _value.id,
controller: controller == const $CopyWithPlaceholder()
? _value.controller
// ignore: cast_nullable_to_non_nullable