Skip to content

Commit

Permalink
version change 2.1.1. Bookmark article from Webview/Article reader sc…
Browse files Browse the repository at this point in the history
…reen.
  • Loading branch information
sreejithbnaick committed Nov 13, 2023
1 parent 9ab32db commit b48da54
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/bookmarks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class _BookmarksState extends State<Bookmarks> {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => WebViewScreen(post["title"], url)));
builder: (context) => WebViewScreen(post["title"], url, post)));
}

isPdfPost(url) {
Expand Down
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class _MyHomePageState extends State<MyHomePage> {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => WebViewScreen(post["title"], url)));
builder: (context) => WebViewScreen(post["title"], url, post)));
}

isPdfPost(url) {
Expand Down
28 changes: 23 additions & 5 deletions lib/webview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,44 @@ import 'package:webview_flutter/webview_flutter.dart';
import 'package:webview_flutter_android/webview_flutter_android.dart';
import 'package:webview_flutter_wkwebview/webview_flutter_wkwebview.dart';

import 'bookmark_service.dart';

const double _kEdgeDragWidth = 20.0;
const double _kMinFlingVelocity = 365.0;

class WebViewScreen extends StatelessWidget {
final url;
final title;
final post;

WebViewScreen(this.title, this.url);
WebViewScreen(this.title, this.url, this.post);

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return WebViewContainer(title, url);
return WebViewContainer(title, url, post);
}
}

class WebViewContainer extends StatefulWidget {
final url;
final title;
final post;

WebViewContainer(this.title, this.url);
WebViewContainer(this.title, this.url, this.post);

@override
createState() => _WebViewContainerState(this.title, this.url);
createState() => _WebViewContainerState(this.title, this.url, this.post);
}

class _WebViewContainerState extends State<WebViewContainer> {
final bookmarkService = BookmarkService();
var _url;
final title;
final post;
late WebViewController _controller;

_WebViewContainerState(this.title, this._url);
_WebViewContainerState(this.title, this._url, this.post);

@override
void initState() {
Expand Down Expand Up @@ -120,6 +126,12 @@ class _WebViewContainerState extends State<WebViewContainer> {
Share.share(url);
}

_bookmark(post) async {
var list = await bookmarkService.getBookmarks();
list.add(post);
await bookmarkService.saveBookmarks(list);
}

@override
Widget build(BuildContext context) {
return Scaffold(
Expand All @@ -139,6 +151,12 @@ class _WebViewContainerState extends State<WebViewContainer> {
var url = await _controller.currentUrl();
_share(url);
},
),
IconButton(
icon: Icon(Icons.bookmark),
onPressed: () async {
_bookmark(post);
},
)
]),
body: Column(
Expand Down

0 comments on commit b48da54

Please sign in to comment.