123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- // Copyright 2018 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- // ignore_for_file: public_member_api_docs
- import 'dart:async';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:sport/widgets/loading.dart';
- import 'package:sport/widgets/menu_share_bottom.dart';
- import 'package:webview_flutter/webview_flutter.dart';
- class WebViewSharePage extends StatefulWidget {
- final String url;
- final String hash;
- final bool openShare;
- WebViewSharePage(this.url, {this.hash, this.openShare = false});
- @override
- _WebViewSharePageState createState() => _WebViewSharePageState();
- }
- class _WebViewSharePageState extends State<WebViewSharePage> {
- final Completer<WebViewController> _controller =
- Completer<WebViewController>();
- bool _isLoading = true;
- @override
- void initState() {
- super.initState();
- if(widget.openShare == true){
- WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
- menuShareBottom(context, "Link",
- url: "http://shoes-web.hiyd.com/share",
- hasDownload: false,
- hash: widget.hash);
- });
- }
- }
- @override
- Widget build(BuildContext context) {
- return AnnotatedRegion<SystemUiOverlayStyle>(
- value: SystemUiOverlayStyle.dark,
- child: Scaffold(
- backgroundColor: Color(0xff241d19),
- // We're using a Builder here so we have a context that is below the Scaffold
- // to allow calling Scaffold.of(context) so we can show a snackbar.
- body: SafeArea(
- child: LoadingWidget(
- loading: _isLoading,
- child: Stack(
- children: <Widget>[
- Container(
- height: MediaQuery.of(context).size.height * 1,
- child: WebView(
- initialUrl:
- 'http://shoes-web.hiyd.com/share?h=${widget.hash}&t=${DateTime.now()}',
- // "http://172.16.14.23:9090/share?h=${widget.hash}&t=${DateTime.now()}",
- javascriptMode: JavascriptMode.unrestricted,
- onWebViewCreated: (WebViewController webViewController) {
- _controller.complete(webViewController);
- },
- // ignore: prefer_collection_literals
- javascriptChannels: <JavascriptChannel>[
- _toasterJavascriptChannel(context),
- ].toSet(),
- onPageStarted: (String url) {
- print('Page started loading: $url');
- setState(() {
- _isLoading = true;
- });
- },
- onPageFinished: (String url) {
- print('Page finished loading: $url');
- setState(() {
- _isLoading = false;
- });
- },
- gestureNavigationEnabled: true,
- ),
- ),
- Positioned(
- left: 12.0,
- top: 11.0,
- child: Container(
- child: InkWell(
- child:
- Image.asset("lib/assets/img/topbar_return_white.png"),
- onTap: () {
- Navigator.pop(context);
- },
- ),
- // color: Colors.red,
- ),
- ),
- Positioned(
- right: 12.0,
- top: 11.0,
- child: Container(
- child: InkWell(
- child:
- Image.asset("lib/assets/img/bbs_icon_share_white.png"),
- onTap: () {
- menuShareBottom(context, "Link",
- url: "http://shoes-web.hiyd.com/share",
- hasDownload: false,
- hash: widget.hash);
- },
- ),
- // color: Colors.red,
- ),
- ),
- ],
- ),
- ),
- )
- // floatingActionButton: favoriteButton(),
- ));
- }
- JavascriptChannel _toasterJavascriptChannel(BuildContext context) {
- return JavascriptChannel(
- name: 'Toaster',
- onMessageReceived: (JavascriptMessage message) {
- Scaffold.of(context).showSnackBar(
- SnackBar(content: Text(message.message)),
- );
- });
- }
- Widget favoriteButton() {
- return FutureBuilder<WebViewController>(
- future: _controller.future,
- builder: (BuildContext context,
- AsyncSnapshot<WebViewController> controller) {
- if (controller.hasData) {
- return FloatingActionButton(
- onPressed: () async {
- final String url = await controller.data.currentUrl();
- Scaffold.of(context).showSnackBar(
- SnackBar(content: Text('Favorited $url')),
- );
- },
- child: const Icon(Icons.favorite),
- );
- }
- return Container();
- });
- }
- }
|