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)),
              ),
            );
          }
      );
    }
    

      

  • 相关阅读:
    偶遇this之坑
    程序员的职业素养——读后感
    我怎么没想到——读后感
    黑客与画家——读后感
    漫谈认证与授权
    动手造轮子:实现一个简单的依赖注入(二) --- 服务注册优化
    动手造轮子:实现简单的 EventQueue
    asp.net core 自定义 Policy 替换 AllowAnonymous 的行为
    SQL Server 中 `JSON_MODIFY` 的使用
    WeihanLi.Npoi 近期更新
  • 原文地址:https://www.cnblogs.com/pythonClub/p/10669289.html
Copyright © 2011-2022 走看看