如何通过在 flutter 中点击 RichText 导航到相应的页面

How to navigate to respective page by tapping RichText in flutter

我正在实现 RichText,其中在点击文本时我需要导航到相应的页面,我已经使用识别器完成了它,但无法导航,任何真正有用的建议,请建议

 RichText(
                        text: TextSpan(children: [
                      TextSpan(
                          text: ' ALREADY HAVE AN ACCOUNT ? ',
                          style: TextStyle(color: Colors.grey)),
                      TextSpan(
                          text: 'LOG IN',
                          recognizer: new TapGestureRecognizer()..onTap = () => {
                            Navigator.push(context, MaterialPageRoute(
                                builder: (context) => LoginPage()),
                            )
                          },
                          style: TextStyle(color: Colors.deepPurpleAccent)),
                    ]))

如何将 RichText 包装在 InkWell 中:

import 'package:flutter/material.dart';

class TextInkwellpage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Text InkWell'),
      ),
      body: Center(
        child: InkWell( // child tapped will fire onTap
          child: RichText(
            text: TextSpan(text: 'Inside RichText....', style: DefaultTextStyle.of(context).style),
          ),
          onTap: () => Navigator.of(context).push(MaterialPageRoute(builder: (context) => SomePage())),
          // ↑ Navigate to new page here
        ),
      )
    );
  }
}

试试这个:

RichText(text: TextSpan(children: [
  TextSpan(
                      text: ' ALREADY HAVE AN ACCOUNT ? ',
                      style: TextStyle(color: Colors.grey)),
  WidgetSpan(child: GestureDetector(child:Text('LOG IN', style: TextStyle(color: Colors.deepPurpleAccent),), onTap: (){
     Navigator.push(context, MaterialPageRoute(
                            builder: (context) => LoginPage()),
                        );
  },)
]),)