diff --git a/.idea/libraries/Flutter_Plugins.xml b/.idea/libraries/Flutter_Plugins.xml index c744bff..1a88ab7 100644 --- a/.idea/libraries/Flutter_Plugins.xml +++ b/.idea/libraries/Flutter_Plugins.xml @@ -1,12 +1,12 @@ - - + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2941aef..d1e277e 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,15 +2,13 @@ - - + - - - + + + - - - - + + + + @@ -65,36 +64,36 @@ - + - - + + - - + + - - + + - + - + - + diff --git a/assets/images/bookmark_add.png b/assets/images/bookmark_add.png deleted file mode 100644 index 3778b9b..0000000 Binary files a/assets/images/bookmark_add.png and /dev/null differ diff --git a/assets/images/bookmark_remove.png b/assets/images/bookmark_remove.png deleted file mode 100644 index b599b2f..0000000 Binary files a/assets/images/bookmark_remove.png and /dev/null differ diff --git a/assets/images/remove.png b/assets/images/remove.png new file mode 100644 index 0000000..4e65fc8 Binary files /dev/null and b/assets/images/remove.png differ diff --git a/lib/MyManagement/HistoryStorage.dart b/lib/MyManagement/HistoryStorage.dart index 36dadae..4529cdd 100644 --- a/lib/MyManagement/HistoryStorage.dart +++ b/lib/MyManagement/HistoryStorage.dart @@ -10,7 +10,7 @@ final String _tableName = 'main_value'; final String columnId = '_id'; final String columnTitle = 'title'; -final String columnUrl = "url"; +final String columnUrl = "webUrl"; final String columnTime = "time"; class HistoryItem { diff --git a/lib/in_app_browser.dart b/lib/in_app_browser.dart index 41d936e..1856fbd 100644 --- a/lib/in_app_browser.dart +++ b/lib/in_app_browser.dart @@ -53,7 +53,7 @@ class InAppBrowser extends StatefulWidget { final String historyTitle; final double appbarTxtSize; final FontWeight appbarFontWeight; - final double historyDialogSize; + double historyDialogSize; InAppBrowser( this.mUrl, { @@ -84,7 +84,7 @@ class InAppBrowser extends StatefulWidget { this.historyCloseIconColor = Colors.white, this.appbarTxtSize = 15, this.appbarFontWeight = FontWeight.bold, - this.historyDialogSize = 100, + this.historyDialogSize = 200, }) : super(key: key); @override @@ -100,6 +100,8 @@ class _InAppBrowserState extends State List> _myList = []; bool isLoading = true; bool showDialog = false; + bool isDialogFull = false; + double tempHistoryDialogSize = 0; static Widget iconInkWell({Function func, IconData mIcon, Color iconColor}) { return InkWell( @@ -113,6 +115,8 @@ class _InAppBrowserState extends State // TODO: implement initState super.initState(); + tempHistoryDialogSize = widget.historyDialogSize; + flutterWebViewPlugin.onUrlChanged.forEach((element) { widget.mUrl = element; setState(() {}); @@ -136,327 +140,389 @@ class _InAppBrowserState extends State }); } + void mDispose() { + if (showDialog) { + showDialog = false; + isDialogFull = false; + widget.historyDialogSize = tempHistoryDialogSize; + setState(() {}); + } else { + flutterWebViewPlugin.dispose(); + flutterWebViewPlugin.hide(); + + Future.delayed(Duration(microseconds: 10), () { + Navigator.pop(context); + }); + } + } + @override Widget build(BuildContext context) { return isLoading ? SizedBox.shrink() - : Directionality( - textDirection: widget.mDirection, - child: WebviewScaffold( - appBar: AppBar( - backgroundColor: widget.appBarColor, - title: Text( - widget.showAppName ? widget.appName : widget.mUrl, - overflow: TextOverflow.ellipsis, - style: TextStyle( - fontWeight: widget.appbarFontWeight, - fontSize: widget.appbarTxtSize, - ), - ), - leading: widget.closeIcon == null - ? SizedBox.shrink() - : InkWell( - child: Icon( - widget.closeIcon, - color: widget.closeIconColor, + : WillPopScope( + onWillPop: () { + mDispose(); + }, + child: Directionality( + textDirection: widget.mDirection, + child: WebviewScaffold( + appBar: isDialogFull + ? null + : AppBar( + backgroundColor: widget.appBarColor, + title: Text( + widget.showAppName ? widget.appName : widget.mUrl, + overflow: TextOverflow.ellipsis, + style: TextStyle( + fontWeight: widget.appbarFontWeight, + fontSize: widget.appbarTxtSize, + ), ), - onTap: () { - Navigator.pop(context); - }, - ), - actions: [ - (widget.addBookmarkIcon == null || - widget.removeBookmarkIcon == null) - ? SizedBox.shrink() - : InkWell( - child: _myList - .where((element) => - element['url'] == widget.mUrl) - .isNotEmpty - ? Icon( - widget.removeBookmarkIcon, - color: widget.removeBookmarkIconColor, - ) - : Icon( - widget.addBookmarkIcon, - color: widget.addBookmarkIconColor, + leading: widget.closeIcon == null + ? SizedBox.shrink() + : InkWell( + child: Icon( + widget.closeIcon, + color: widget.closeIconColor, ), - onTap: () async { - await _storeProvider - .checkValue(widget.mUrl) - .then((value) async { - if (value == null) { - String html = - await flutterWebViewPlugin.evalJavascript( - "window.document.getElementsByTagName('html')[0].outerHTML;"); - - String title = ""; - if (html.contains("u003Ctitle>") && - html.contains("u003Ctitle>")) - title = html.substring( - html.indexOf("u003Ctitle>") + 11, - html.indexOf("u003C/title>")); - else - title = "Your Url"; - - HistoryItem historyItem = HistoryItem(); - - historyItem.title = title; - historyItem.url = widget.mUrl; - historyItem.time = - DateTime.now().millisecondsSinceEpoch; - - _storeProvider.insert(historyItem); - - _myList.add({ - "_id": historyItem.time, - "title": title, - "url": widget.mUrl, - "time": historyItem.time, - }); - } else { - _storeProvider.delete(value.id); - - _myList.removeWhere( - (element) => element["url"] == value.url, - ); - } - setState(() {}); - }); - }, - ), - SizedBox(width: 10), - ], - ), - url: widget.mUrl, - withJavascript: true, - bottomNavigationBar: showDialog - ? Container( - height: widget.historyDialogSize, - decoration: BoxDecoration( - color: widget.bottomNavColor, - borderRadius: BorderRadius.only( - topLeft: Radius.circular(10), - topRight: Radius.circular(10), - ), + onTap: mDispose, + ), + actions: [ + (widget.addBookmarkIcon == null || + widget.removeBookmarkIcon == null) + ? SizedBox.shrink() + : InkWell( + child: _myList + .where((element) => + element['url'] == widget.mUrl) + .isNotEmpty + ? Icon( + widget.removeBookmarkIcon, + color: widget.removeBookmarkIconColor, + ) + : Icon( + widget.addBookmarkIcon, + color: widget.addBookmarkIconColor, + ), + onTap: () async { + await _storeProvider + .checkValue(widget.mUrl) + .then((value) async { + if (value == null) { + String html = await flutterWebViewPlugin + .evalJavascript( + "window.document.getElementsByTagName('html')[0].outerHTML;"); + + String title = ""; + if (html.contains("u003Ctitle>") && + html.contains("u003Ctitle>")) + title = html.substring( + html.indexOf("u003Ctitle>") + 11, + html.indexOf("u003C/title>")); + else + title = "Your Url"; + + HistoryItem historyItem = HistoryItem(); + + historyItem.title = title; + historyItem.url = widget.mUrl; + historyItem.time = DateTime.now() + .millisecondsSinceEpoch; + + _storeProvider.insert(historyItem); + + _myList.add({ + "_id": historyItem.time, + "title": title, + "url": widget.mUrl, + "time": historyItem.time, + }); + } else { + _storeProvider.delete(value.id); + + _myList.removeWhere( + (element) => + element["url"] == value.url, + ); + } + setState(() {}); + }); + }, + ), + SizedBox(width: 10), + ], ), - padding: EdgeInsets.symmetric(horizontal: 5), - child: Column( - children: [ - Icon( - Icons.remove, - color: Colors.grey, - size: 30, + url: widget.mUrl, + withLocalStorage: true, + withJavascript: true, + bottomNavigationBar: showDialog + ? Container( + height: widget.historyDialogSize, + decoration: BoxDecoration( + color: widget.bottomNavColor, + borderRadius: BorderRadius.only( + topLeft: Radius.circular(isDialogFull ? 0 : 10), + topRight: Radius.circular(isDialogFull ? 0 : 10), ), - Padding( - padding: const EdgeInsets.only( - bottom: 8.0, - top: 10, + ), + padding: EdgeInsets.symmetric(horizontal: 5), + child: Column( + children: [ + // Icon( + // Icons.remove, + // color: Colors.grey, + // size: 40, + // ), + GestureDetector( + onPanUpdate: (details) { + print("Mahdi: y ${details.delta.dy}"); + print("Mahdi: x ${details.delta.dx}"); + + double appbarSize = + MediaQuery.of(context).size.height; + + if (details.delta.dy < -3 && + widget.historyDialogSize != appbarSize) { + widget.historyDialogSize = appbarSize; + isDialogFull = true; + setState(() {}); + } else if (details.delta.dy > 3 && showDialog) { + showDialog = false; + isDialogFull = false; + widget.historyDialogSize = + tempHistoryDialogSize; + + setState(() {}); + } + }, + child: Text( + "━━", + style: + TextStyle(fontSize: 20, color: Colors.grey), + ), ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Padding( - padding: EdgeInsets.only( - left: MediaQuery.of(context).size.width * - 0.02, - ), - child: InkWell( - child: Text( - "پاک کردن", - style: TextStyle( - fontSize: 15, - color: Colors.white, + Padding( + padding: const EdgeInsets.only( + bottom: 8.0, + top: 8.0, + ), + child: Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + children: [ + Padding( + padding: EdgeInsets.only( + left: MediaQuery.of(context).size.width * + 0.02, + ), + child: InkWell( + child: Text( + "پاک کردن", + style: TextStyle( + fontSize: 15, + color: Colors.white, + ), ), + onTap: () { + _myList.clear(); + _storeProvider.deleteAll(); + setState(() {}); + }, ), - onTap: () { - _myList.clear(); - _storeProvider.deleteAll(); - setState(() {}); - }, ), - ), - Text( - widget.historyTitle, - style: TextStyle( - fontWeight: FontWeight.bold, - fontSize: 17, - color: Colors.white, + Text( + widget.historyTitle, + style: TextStyle( + fontWeight: FontWeight.bold, + fontSize: 17, + color: Colors.white, + ), ), - ), - widget.historyCloseIconColor == null - ? SizedBox.shrink() - : Padding( - padding: EdgeInsets.only( - right: MediaQuery.of(context) - .size - .width * - 0.02, - ), - child: InkWell( - child: Icon( - widget.historyCloseIcon, - color: widget.historyCloseIconColor, + widget.historyCloseIconColor == null + ? SizedBox.shrink() + : Padding( + padding: EdgeInsets.only( + right: MediaQuery.of(context) + .size + .width * + 0.02, + ), + child: InkWell( + child: Icon( + widget.historyCloseIcon, + color: + widget.historyCloseIconColor, + ), + onTap: () { + showDialog = false; + isDialogFull = false; + widget.historyDialogSize = + tempHistoryDialogSize; + + setState(() {}); + }, ), - onTap: () { - showDialog = false; - setState(() {}); - }, ), - ), - ], + ], + ), ), - ), - Divider(color: Colors.white), - Expanded( - child: ListView.builder( - itemCount: _myList.length, - itemBuilder: (ctx, index) { - int dayDB = DateTime.fromMillisecondsSinceEpoch( - _myList[index]["time"]) - .day; - int monthDB = - DateTime.fromMillisecondsSinceEpoch( - _myList[index]["time"]) - .month; - return Row( - children: [ - SizedBox( - height: - MediaQuery.of(context).size.width * - 0.15, - width: MediaQuery.of(context).size.width * - 0.15, - child: Icon( - Icons.link_outlined, - color: Colors.white, + Divider(color: Colors.white), + Expanded( + child: ListView.builder( + itemCount: _myList.length, + itemBuilder: (ctx, index) { + int dayDB = + DateTime.fromMillisecondsSinceEpoch( + _myList[index]["time"]) + .day; + int monthDB = + DateTime.fromMillisecondsSinceEpoch( + _myList[index]["time"]) + .month; + return Row( + children: [ + SizedBox( + height: + MediaQuery.of(context).size.width * + 0.15, + width: + MediaQuery.of(context).size.width * + 0.15, + child: Icon( + Icons.link_outlined, + color: Colors.white, + ), ), - ), - SizedBox( - width: MediaQuery.of(context).size.width * - 0.01, - ), - Column( - children: [ - SizedBox( - width: MediaQuery.of(context) - .size - .width * - 0.8, - child: Text( - "${_myList[index]["title"]}", - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.bold, + SizedBox( + width: + MediaQuery.of(context).size.width * + 0.01, + ), + Column( + children: [ + SizedBox( + width: MediaQuery.of(context) + .size + .width * + 0.8, + child: Text( + "${_myList[index]["title"]}", + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + ), ), ), - ), - SizedBox( - height: MediaQuery.of(context) - .size - .height * - 0.01, - ), - SizedBox( - width: MediaQuery.of(context) - .size - .width * - 0.8, - child: Text( - "${_myList[index]["url"]}", - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: Colors.grey, + SizedBox( + height: MediaQuery.of(context) + .size + .height * + 0.01, + ), + SizedBox( + width: MediaQuery.of(context) + .size + .width * + 0.8, + child: Text( + "${_myList[index]["url"]}", + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: Colors.grey, + ), ), ), - ), - SizedBox( - height: MediaQuery.of(context) - .size - .height * - 0.01, - ), - SizedBox( - width: MediaQuery.of(context) - .size - .width * - 0.8, - child: Text( - "${months[monthDB - 1]} $dayDB", - overflow: TextOverflow.ellipsis, - style: TextStyle( - color: Colors.grey, + SizedBox( + height: MediaQuery.of(context) + .size + .height * + 0.01, + ), + SizedBox( + width: MediaQuery.of(context) + .size + .width * + 0.8, + child: Text( + "${months[monthDB - 1]} $dayDB", + overflow: TextOverflow.ellipsis, + style: TextStyle( + color: Colors.grey, + ), ), ), - ), - ], - ), - ], - ); - }, - ), - ) - ], - ), - ) - : SizedBox( - height: 56, - child: Card( - color: widget.bottomNavColor, - margin: EdgeInsets.zero, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(0), - ), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - iconInkWell( - func: () { - flutterWebViewPlugin.canGoBack().then((value) { - if (value) flutterWebViewPlugin.goBack(); - }); - }, - mIcon: widget.backIcon, - iconColor: widget.backIconColor, - ), - iconInkWell( - func: () { - flutterWebViewPlugin - .canGoForward() - .then((value) { - if (value) flutterWebViewPlugin.goForward(); - }); - }, - mIcon: widget.nextIcon, - iconColor: widget.nextIconColor, - ), - iconInkWell( - func: () { - Share.share(widget.mUrl); - }, - mIcon: widget.shareIcon, - iconColor: widget.shareIconColor, - ), - iconInkWell( - mIcon: widget.historyIcon, - iconColor: widget.historyIconColor, - func: () { - showDialog = true; - setState(() {}); - }, - ), - iconInkWell( - mIcon: widget.refreshIcon, - iconColor: widget.refreshIconColor, - func: () { - flutterWebViewPlugin.reload(); - }, - ), + ], + ), + ], + ); + }, + ), + ) ], ), + ) + : SizedBox( + height: 56, + child: Card( + color: widget.bottomNavColor, + margin: EdgeInsets.zero, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(0), + ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + iconInkWell( + func: () { + flutterWebViewPlugin + .canGoBack() + .then((value) { + if (value) flutterWebViewPlugin.goBack(); + }); + }, + mIcon: widget.backIcon, + iconColor: widget.backIconColor, + ), + iconInkWell( + func: () { + flutterWebViewPlugin + .canGoForward() + .then((value) { + if (value) flutterWebViewPlugin.goForward(); + }); + }, + mIcon: widget.nextIcon, + iconColor: widget.nextIconColor, + ), + iconInkWell( + func: () { + Share.share(widget.mUrl); + }, + mIcon: widget.shareIcon, + iconColor: widget.shareIconColor, + ), + iconInkWell( + mIcon: widget.historyIcon, + iconColor: widget.historyIconColor, + func: () { + showDialog = true; + setState(() {}); + }, + ), + iconInkWell( + mIcon: widget.refreshIcon, + iconColor: widget.refreshIconColor, + func: () { + flutterWebViewPlugin.reload(); + }, + ), + ], + ), + ), ), - ), + ), ), ); } diff --git a/pubspec.yaml b/pubspec.yaml index a7b2211..2fc0446 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -39,7 +39,7 @@ flutter: # To add assets to your plugin package, add an assets section, like this: assets: - - assets/images/ + - assets/images/remove.png # - images/a_dot_ham.jpeg # # For details regarding assets in packages, see