【问题标题】:I want to make a button automatically clickable without a tap in flutter. I'm also using WebView flutter:我想让一个按钮自动点击而无需轻按。我也在使用 WebView 颤振:
【发布时间】:2021-12-28 09:37:14
【问题描述】:

我想让 WebView 的底部(包括广告)无需触摸/点击即可点击。我的 WebView 在其底部包含一个浮动广告。我想让它自动点击而不是一次又一次地点击它。我使用了 IgnorePointer 类。我的代码的某些部分已被注释,您也可以检查它。 (注:我这样做只是为了学习) 这是我的代码:

import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';


class HomeScreen extends StatelessWidget{


  @override
  Widget build(BuildContext context) {
    final _key = UniqueKey();
    final height=MediaQuery.of(context).size.height;
    // return CustomScrollView(
    //
    //   slivers: <Widget>[
    //     SliverAppBar(
    //       title: const Text("Software Testing Help"),
    //       floating: true,
    //     ),
    //     SliverFillRemaining(
    //       child: WebView(initialUrl: "https://www.softwaretestinghelp.com/digital-marketing-software/"),
    //     )
    //   ],
    // );
    return Scaffold(
      appBar: AppBar(
        toolbarHeight: height*0.08,
        backgroundColor: Colors.black,
        title: Center(child: Text('Software Testing Help', style: TextStyle(
          color: Colors.white
        ),)),
      ),
      body:
         Stack(
           children: [
              Container(
                   height: height*0.90,
                   child: Expanded(
                     child: WebView(
                       initialUrl: 'https://www.softwaretestinghelp.com/digital-marketing-software/',
                       key: _key,
                       javascriptMode: JavascriptMode.unrestricted,
                     ),
                   )

             ),
             Positioned(
               bottom:0,
               left: 10,
               child: GestureDetector(
                 onTap: (){
                   Scaffold.of(context).showSnackBar(SnackBar(
                     content: Text('Ad is clicked'),
                   ));
                 },
                 child: IgnorePointer(
                     ignoring: true,
                     child: Container(
                       decoration: BoxDecoration(
                         border: Border.all(
                           color: Colors.blue
                         )
                       ),
                       height: 100,
                       width: 100,

                     ),

                 ),
               ),
             )
           ]
         )



    );
  }

}

【问题讨论】:

    标签: flutter button webview onclick click


    【解决方案1】:

    您可以通过计时器自动执行此操作,一段时间后此计时器将调用您的函数。 像这样:

    bool? isLoading;
    
    adClickedRunner() {
        Timer(
          Duration(seconds: 5), //example: after 5sec will call your task
          () async {
            isLoading = true; //to show circularProgressIndicatior for your button
            Scaffold.of(context).showSnackBar(SnackBar(
              content: Text('Ad is clicked'),));
            isLoading = false;
          },
        );
      }
    

    【讨论】:

      猜你喜欢
      • 2021-06-05
      • 1970-01-01
      • 2021-06-10
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      • 1970-01-01
      • 2020-09-23
      • 2021-08-11
      相关资源
      最近更新 更多