zoukankan      html  css  js  c++  java
  • textspan 转连接

    import 'package:flutter/material.dart';
    import 'package:flutter/gestures.dart';
    import 'package:url_launcher/url_launcher.dart';
    import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
    
    class TestApp extends StatelessWidget {
    
      @override
      Widget build(BuildContext context) {
        // TODO: implement build
        return Scaffold(
          appBar: AppBar(
            title: Text('test'),
          ),
          body: Center(child:Container(
            child: RichText(
                text: TextSpan(
                  children: [
                    TextSpan(
                        text: 'just test',
                        style: TextStyle(color: Colors.black),
                      recognizer: TapGestureRecognizer()..onTap=()=>Navigator.of(context).push(MaterialPageRoute(builder: (_){
                        return WebTest();
                      })),
                    ),
                  ],
                ),
            ),
          )),
          floatingActionButton: FloatingActionButton(
              onPressed: (){
                Navigator.of(context).pushNamed('/web');
              },
          ),
        );
      }
    }
    
    
    class WebTest extends StatelessWidget {
    //  WebTest({this.url});
      final String url = 'http://www.v2ex.com';
    
      @override
      Widget build(BuildContext context) {
      print('press here');
        return WebviewScaffold(
          appBar: AppBar(title: Text('test'),),
          url: url,
        );
      }
    }
    
    class _LinkTextSpan extends TextSpan {
    
      // Beware!
      //
      // This class is only safe because the TapGestureRecognizer is not
      // given a deadline and therefore never allocates any resources.
      //
      // In any other situation -- setting a deadline, using any of the less trivial
      // recognizers, etc -- you would have to manage the gesture recognizer's
      // lifetime and call dispose() when the TextSpan was no longer being rendered.
      //
      // Since TextSpan itself is @immutable, this means that you would have to
      // manage the recognizer from outside the TextSpan, e.g. in the State of a
      // stateful widget that then hands the recognizer to the TextSpan.
    //  example:
    //  _LinkTextSpan(
    //      style: linkStyle,
    //      url: 'https://goo.gl/iv1p4G',
    //      text: 'flutter github repo',
    //  ),
    
      _LinkTextSpan({ TextStyle style, String url, String text }) : super(
          style: style,
    //      text: str ?? url,
        text:text,
          recognizer: TapGestureRecognizer()..onTap = () {
            print('tapped');
            return WebviewScaffold(
              url:url,
              appBar: AppBar(
                title: Text(text, style:TextStyle(color: Colors.red)),
              ),
            );
          }
      );
    }
    

      

  • 相关阅读:
    7个最好的免费杀毒软件下载
    VMware虚拟机扩容
    tomcat的JK和JK2
    面向对象——接口
    JPA入门样例(採用JPA的hibernate实现版本号)
    JAVA数组的定义及用法
    Styles and Themes
    OpenSSL再曝CCS注入漏洞-心伤未愈又成筛子
    纯文本抽出程序库DMC TEXT FILTER
    数据结构课程设计之通讯录管理系统
  • 原文地址:https://www.cnblogs.com/pythonClub/p/10669289.html
Copyright © 2011-2022 走看看