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

      

  • 相关阅读:
    浅谈ASP.NET核心对象
    介绍ASP.NET服务器控件之视图状态++
    详述Asp.net的加密解密技巧(1)
    详述Asp.net的加密解密技巧(2)
    ASP.NET性能优化之构建自定义文件缓存
    介绍ASP.NET服务器控件之视图状态
    详细介绍ASP.NET的实用技巧
    扩展RBAC用户角色权限设计方案
    String...
    基于XMPP协议的手机多方多端即时通讯方案
  • 原文地址:https://www.cnblogs.com/pythonClub/p/10669289.html
Copyright © 2020-2023  润新知