0

I have created one app with support of android, IOS and web using flutter and created new windows application using URL of the flutter web.

I have used below mentioned WebView to load the URL in the windows app that contains the flutter web URL.

https://pub.dev/packages/webview_windows

Currently I am facing issue in scrolling, where the loaded view isn't scrollable with the mouse, but I can scroll using scrollbar provided on the right.

Tried creating app with flutter windows but not all packages are supported so tried to managed it this way, I want the loaded URL working with the scroll automatically with the mouse as it is working in app and web perfectly. In Windows app it is not scroll using mouse wheel and only scrollable using scrollbar.

Video for web app

Below is the code that I have used in the Webapp to load the URL.

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:webview_windows/webview_windows.dart';

final navigatorKey = GlobalKey<NavigatorState>();

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: navigatorKey,
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _controller = WebviewController();
  double _scrollPosition = 0;

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  Future<void> initPlatformState() async {
    try {
      await _controller.initialize();
      _controller.url.listen((url) async {
        print("URL==>${url}");

        // _textController.text = url;
      });

      await _controller.setBackgroundColor(Colors.transparent);

      await _controller.setPopupWindowPolicy(WebviewPopupWindowPolicy.allow);

      await _controller.loadUrl('https://dashboardpro-trueuly.web.app/');
  

      if (!mounted) return;
      setState(() {});
    } on PlatformException catch (e) {}
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        toolbarHeight: 0,
        title: Text(widget.title),
      ),
      body: Webview(
        _controller,
        width: MediaQuery.of(context).size.width,
        height: MediaQuery.of(context).size.height,
        // permissionRequested: _onPermissionRequested,
      ),
    );
  }

  Future<WebviewPermissionDecision> _onPermissionRequested(
      String url, WebviewPermissionKind kind, bool isUserInitiated) async {
    final decision = await showDialog<WebviewPermissionDecision>(
      context: navigatorKey.currentContext!,
      builder: (BuildContext context) => AlertDialog(
        title: const Text('WebView permission requested'),
        content: Text('WebView has requested permission \'$kind\''),
        actions: <Widget>[
          TextButton(
            onPressed: () =>
                Navigator.pop(context, WebviewPermissionDecision.deny),
            child: const Text('Deny'),
          ),
          TextButton(
            onPressed: () =>
                Navigator.pop(context, WebviewPermissionDecision.allow),
            child: const Text('Allow'),
          ),
        ],
      ),
    );

    return decision ?? WebviewPermissionDecision.none;
  }
}



I tried to load URL with different web views that supports windows but none of them were able to scroll this flutter web URL. I want the web URL to be working with the actual scroll that is provided in the app not the scrollable view that supports in windows.

Jay_Panchal
  • 327
  • 2
  • 11

0 Answers0