Skip to content

Commit

Permalink
Merge pull request #126 from BuildMirai/dv/mirai-webview
Browse files Browse the repository at this point in the history
feat: Update Mirai webview & Add docs
  • Loading branch information
divyanshub024 authored Jan 21, 2025
2 parents a983a3e + 3ab2d64 commit 4f01b90
Show file tree
Hide file tree
Showing 10 changed files with 250 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/mirai_gallery/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ packages:
path: "../../packages/mirai_webview"
relative: true
source: path
version: "0.0.3"
version: "0.0.4"
nested:
dependency: transitive
description:
Expand Down
6 changes: 6 additions & 0 deletions packages/mirai_webview/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 0.0.4

* Update webview_flutter to 4.10.0
* Add layoutDirection property to the WebView
* Add documentation for the WebView

## 0.0.3

* minor changes
Expand Down
10 changes: 9 additions & 1 deletion packages/mirai_webview/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# Mirai Web View

A webView support for Mirai.
A webView support for [Mirai](https://pub.dev/packages/mirai).

## Usage

1. Add `mirai_webview` as a dependency in your pubspec.yaml file.

Install the plugin by running the following command from the project root:

```bash
flutter pub add mirai_webview
```

or add it manually in your `pubspec.yaml` file:

```yaml
dependencies:
mirai_webview:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:webview_flutter/webview_flutter.dart';

Expand All @@ -6,14 +7,36 @@ export 'mirai_webview_parser.dart';
part 'mirai_webview.freezed.dart';
part 'mirai_webview.g.dart';

/// `MiraiWebView` is a widget that renders a web page within a flutter application.
@freezed
class MiraiWebView with _$MiraiWebView {
/// `MiraiWebView` constructor.
const factory MiraiWebView({
/// The URL to load in the `WebView`.
required String url,

/// Sets whether JavaScript execution is enabled.
///
/// Default value is `JavaScriptMode.unrestricted`.
@Default(JavaScriptMode.unrestricted) JavaScriptMode javaScriptMode,
@Default("#000000") String backgroundColor,

/// Background color of the `WebView`.
///
/// Default value is `#FFFFFF`.
@Default("#FFFFFF") String backgroundColor,

/// The user agent for the `WebView`.
String? userAgent,

/// Sets whether zoom is enabled for the `WebView`.
///
/// Default value is `false`.
@Default(false) bool enableZoom,

/// The layout direction for the `WebView`.
///
/// Default value is `TextDirection.ltr`.
@Default(TextDirection.ltr) TextDirection layoutDirection,
}) = _MiraiWebView;

factory MiraiWebView.fromJson(Map<String, dynamic> json) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,38 @@ MiraiWebView _$MiraiWebViewFromJson(Map<String, dynamic> json) {

/// @nodoc
mixin _$MiraiWebView {
/// The URL to load in the `WebView`.
String get url => throw _privateConstructorUsedError;

/// Sets whether JavaScript execution is enabled.
///
/// Default value is `JavaScriptMode.unrestricted`.
JavaScriptMode get javaScriptMode => throw _privateConstructorUsedError;

/// Background color of the `WebView`.
///
/// Default value is `#FFFFFF`.
String get backgroundColor => throw _privateConstructorUsedError;

/// The user agent for the `WebView`.
String? get userAgent => throw _privateConstructorUsedError;

/// Sets whether zoom is enabled for the `WebView`.
///
/// Default value is `false`.
bool get enableZoom => throw _privateConstructorUsedError;

/// The layout direction for the `WebView`.
///
/// Default value is `TextDirection.ltr`.
TextDirection get layoutDirection => throw _privateConstructorUsedError;

/// Serializes this MiraiWebView to a JSON map.
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)

/// Create a copy of MiraiWebView
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$MiraiWebViewCopyWith<MiraiWebView> get copyWith =>
throw _privateConstructorUsedError;
}
Expand All @@ -43,7 +67,8 @@ abstract class $MiraiWebViewCopyWith<$Res> {
JavaScriptMode javaScriptMode,
String backgroundColor,
String? userAgent,
bool enableZoom});
bool enableZoom,
TextDirection layoutDirection});
}

/// @nodoc
Expand All @@ -56,6 +81,8 @@ class _$MiraiWebViewCopyWithImpl<$Res, $Val extends MiraiWebView>
// ignore: unused_field
final $Res Function($Val) _then;

/// Create a copy of MiraiWebView
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Expand All @@ -64,6 +91,7 @@ class _$MiraiWebViewCopyWithImpl<$Res, $Val extends MiraiWebView>
Object? backgroundColor = null,
Object? userAgent = freezed,
Object? enableZoom = null,
Object? layoutDirection = null,
}) {
return _then(_value.copyWith(
url: null == url
Expand All @@ -86,6 +114,10 @@ class _$MiraiWebViewCopyWithImpl<$Res, $Val extends MiraiWebView>
? _value.enableZoom
: enableZoom // ignore: cast_nullable_to_non_nullable
as bool,
layoutDirection: null == layoutDirection
? _value.layoutDirection
: layoutDirection // ignore: cast_nullable_to_non_nullable
as TextDirection,
) as $Val);
}
}
Expand All @@ -103,7 +135,8 @@ abstract class _$$MiraiWebViewImplCopyWith<$Res>
JavaScriptMode javaScriptMode,
String backgroundColor,
String? userAgent,
bool enableZoom});
bool enableZoom,
TextDirection layoutDirection});
}

/// @nodoc
Expand All @@ -114,6 +147,8 @@ class __$$MiraiWebViewImplCopyWithImpl<$Res>
_$MiraiWebViewImpl _value, $Res Function(_$MiraiWebViewImpl) _then)
: super(_value, _then);

/// Create a copy of MiraiWebView
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Expand All @@ -122,6 +157,7 @@ class __$$MiraiWebViewImplCopyWithImpl<$Res>
Object? backgroundColor = null,
Object? userAgent = freezed,
Object? enableZoom = null,
Object? layoutDirection = null,
}) {
return _then(_$MiraiWebViewImpl(
url: null == url
Expand All @@ -144,6 +180,10 @@ class __$$MiraiWebViewImplCopyWithImpl<$Res>
? _value.enableZoom
: enableZoom // ignore: cast_nullable_to_non_nullable
as bool,
layoutDirection: null == layoutDirection
? _value.layoutDirection
: layoutDirection // ignore: cast_nullable_to_non_nullable
as TextDirection,
));
}
}
Expand All @@ -154,30 +194,53 @@ class _$MiraiWebViewImpl implements _MiraiWebView {
const _$MiraiWebViewImpl(
{required this.url,
this.javaScriptMode = JavaScriptMode.unrestricted,
this.backgroundColor = "#000000",
this.backgroundColor = "#FFFFFF",
this.userAgent,
this.enableZoom = false});
this.enableZoom = false,
this.layoutDirection = TextDirection.ltr});

factory _$MiraiWebViewImpl.fromJson(Map<String, dynamic> json) =>
_$$MiraiWebViewImplFromJson(json);

/// The URL to load in the `WebView`.
@override
final String url;

/// Sets whether JavaScript execution is enabled.
///
/// Default value is `JavaScriptMode.unrestricted`.
@override
@JsonKey()
final JavaScriptMode javaScriptMode;

/// Background color of the `WebView`.
///
/// Default value is `#FFFFFF`.
@override
@JsonKey()
final String backgroundColor;

/// The user agent for the `WebView`.
@override
final String? userAgent;

/// Sets whether zoom is enabled for the `WebView`.
///
/// Default value is `false`.
@override
@JsonKey()
final bool enableZoom;

/// The layout direction for the `WebView`.
///
/// Default value is `TextDirection.ltr`.
@override
@JsonKey()
final TextDirection layoutDirection;

@override
String toString() {
return 'MiraiWebView(url: $url, javaScriptMode: $javaScriptMode, backgroundColor: $backgroundColor, userAgent: $userAgent, enableZoom: $enableZoom)';
return 'MiraiWebView(url: $url, javaScriptMode: $javaScriptMode, backgroundColor: $backgroundColor, userAgent: $userAgent, enableZoom: $enableZoom, layoutDirection: $layoutDirection)';
}

@override
Expand All @@ -193,15 +256,19 @@ class _$MiraiWebViewImpl implements _MiraiWebView {
(identical(other.userAgent, userAgent) ||
other.userAgent == userAgent) &&
(identical(other.enableZoom, enableZoom) ||
other.enableZoom == enableZoom));
other.enableZoom == enableZoom) &&
(identical(other.layoutDirection, layoutDirection) ||
other.layoutDirection == layoutDirection));
}

@JsonKey(ignore: true)
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(
runtimeType, url, javaScriptMode, backgroundColor, userAgent, enableZoom);
int get hashCode => Object.hash(runtimeType, url, javaScriptMode,
backgroundColor, userAgent, enableZoom, layoutDirection);

@JsonKey(ignore: true)
/// Create a copy of MiraiWebView
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$MiraiWebViewImplCopyWith<_$MiraiWebViewImpl> get copyWith =>
Expand All @@ -221,23 +288,48 @@ abstract class _MiraiWebView implements MiraiWebView {
final JavaScriptMode javaScriptMode,
final String backgroundColor,
final String? userAgent,
final bool enableZoom}) = _$MiraiWebViewImpl;
final bool enableZoom,
final TextDirection layoutDirection}) = _$MiraiWebViewImpl;

factory _MiraiWebView.fromJson(Map<String, dynamic> json) =
_$MiraiWebViewImpl.fromJson;

/// The URL to load in the `WebView`.
@override
String get url;

/// Sets whether JavaScript execution is enabled.
///
/// Default value is `JavaScriptMode.unrestricted`.
@override
JavaScriptMode get javaScriptMode;

/// Background color of the `WebView`.
///
/// Default value is `#FFFFFF`.
@override
String get backgroundColor;

/// The user agent for the `WebView`.
@override
String? get userAgent;

/// Sets whether zoom is enabled for the `WebView`.
///
/// Default value is `false`.
@override
bool get enableZoom;

/// The layout direction for the `WebView`.
///
/// Default value is `TextDirection.ltr`.
@override
TextDirection get layoutDirection;

/// Create a copy of MiraiWebView
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(ignore: true)
@JsonKey(includeFromJson: false, includeToJson: false)
_$$MiraiWebViewImplCopyWith<_$MiraiWebViewImpl> get copyWith =>
throw _privateConstructorUsedError;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4f01b90

Please sign in to comment.