Skip to content

Commit

Permalink
implement reload web content
Browse files Browse the repository at this point in the history
  • Loading branch information
wuuzw committed Feb 9, 2021
1 parent 965051b commit 8582509
Show file tree
Hide file tree
Showing 11 changed files with 108 additions and 39 deletions.
5 changes: 0 additions & 5 deletions lib/app/modules/item/item_controller.dart
@@ -1,4 +1,3 @@
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:mobx/mobx.dart';

Expand All @@ -15,7 +14,6 @@ abstract class _ItemControllerBase with Store {
final ItemRepository _repository;

int _id;
InAppWebViewController webViewController;

_ItemControllerBase(this._repository);

Expand All @@ -25,9 +23,6 @@ abstract class _ItemControllerBase with Store {
@observable
bool isViewingComment = false;

@observable
bool isLoadingWebContent = false;

bool get hasWebContent => !itemFuture.value.domain.isNullOrEmpty();

@action
Expand Down
19 changes: 1 addition & 18 deletions lib/app/modules/item/item_controller.g.dart

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

2 changes: 2 additions & 0 deletions lib/app/modules/item/item_module.dart
@@ -1,4 +1,5 @@
import 'package:flutter_modular/flutter_modular.dart';
import 'package:zone/app/modules/item/widgets/web_view/web_view_body_controller.dart';

import 'item_controller.dart';
import 'item_page.dart';
Expand All @@ -7,6 +8,7 @@ import 'repository/item_repository.dart';
class ItemModule extends ChildModule {
@override
List<Bind> get binds => [
$WebViewBodyController,
$ItemController,
$ItemRepository,
];
Expand Down
2 changes: 1 addition & 1 deletion lib/app/modules/item/widgets/item_body.dart
Expand Up @@ -7,7 +7,7 @@ import '../../../shared/widgets/error_indicator.dart';
import '../../../shared/widgets/loading_indicator.dart';
import '../item_controller.dart';
import 'comment_view/comment_view_body.dart';
import 'webview/webview_body.dart';
import 'web_view/web_view_body.dart';

class ItemBody extends StatelessWidget {
final ItemController controller = Modular.get();
Expand Down
4 changes: 3 additions & 1 deletion lib/app/modules/item/widgets/item_bottom_bar.dart
Expand Up @@ -7,11 +7,13 @@ import '../../../service/share_service.dart';
import '../../../service/url_launch_service.dart';
import '../../../shared/constants/dimens.dart';
import '../item_controller.dart';
import 'web_view/web_view_body_controller.dart';

class ItemBottomBar extends StatelessWidget {
final ItemController controller = Modular.get();
final ShareService shareService = Modular.get();
final UrlLaunchService urlLaunchService = Modular.get();
final WebViewBodyController webViewBodyController = Modular.get();

@override
Widget build(BuildContext context) {
Expand All @@ -31,7 +33,7 @@ class ItemBottomBar extends StatelessWidget {
icon: Icon(MdiIcons.refresh),
tooltip: 'Reload current page',
onPressed: () {
//_webViewKey.currentState?.reload();
webViewBodyController.reload();
},
),
Spacer(),
Expand Down
Expand Up @@ -3,11 +3,12 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:flutter_modular/flutter_modular.dart';

import '../../item_controller.dart';
import 'web_view_body_controller.dart';

class WebViewBody extends StatelessWidget {
final WebViewBodyController controller = Modular.get();

final String url;
final ItemController controller = Modular.get();

WebViewBody({Key key, this.url}) : super(key: key);

Expand All @@ -18,7 +19,7 @@ class WebViewBody extends StatelessWidget {
return Stack(
children: [
InAppWebView(
initialUrl: controller.itemFuture.value.url,
initialUrl: url,
initialOptions: InAppWebViewGroupOptions(
android: AndroidInAppWebViewOptions(
forceDark: AndroidForceDark.FORCE_DARK_ON,
Expand All @@ -40,8 +41,4 @@ class WebViewBody extends StatelessWidget {
},
);
}

void reload() {
controller.webViewController?.reload();
}
}
@@ -0,0 +1,19 @@
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:mobx/mobx.dart';

part 'web_view_body_controller.g.dart';

@Injectable()
class WebViewBodyController = _WebViewBodyControllerBase with _$WebViewBodyController;

abstract class _WebViewBodyControllerBase with Store {
InAppWebViewController webViewController;

@observable
bool isLoadingWebContent = false;

void reload() {
webViewController?.reload();
}
}

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

@@ -0,0 +1,25 @@
import 'package:flutter_modular/flutter_modular_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:zone/app/modules/item/item_module.dart';
import 'package:zone/app/modules/item/widgets/web_view/web_view_body_controller.dart';

void main() {
initModule(ItemModule());
WebViewBodyController webviewbody;
//
setUp(() {
// webviewbody = ItemModule.to.get<WebViewBodyController>();
});

group('WebViewBodyController Test', () {
// test("First Test", () {
// expect(webviewbody, isInstanceOf<WebViewBodyController>());
// });

// test("Set Value", () {
// expect(webviewbody.value, equals(0));
// webviewbody.increment();
// expect(webviewbody.value, equals(1));
// });
});
}
@@ -0,0 +1,9 @@
import 'package:flutter_test/flutter_test.dart';

void main() {
testWidgets('WebViewBody has message', (tester) async {
// await tester.pumpWidget(buildTestableWidget(WebViewBody()));
// final textFinder = find.text('WebViewBody');
// expect(textFinder, findsOneWidget);
});
}

This file was deleted.

0 comments on commit 8582509

Please sign in to comment.