Created
August 8, 2023 17:16
-
-
Save dutsky/20e7b12f67fe102577c2af65691d6b11 to your computer and use it in GitHub Desktop.
editing_controller_recognizer_failure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| import 'package:flutter/gestures.dart'; | |
| const Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
| void main() { | |
| runApp(MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| theme: ThemeData.dark().copyWith( | |
| scaffoldBackgroundColor: darkBlue, | |
| ), | |
| debugShowCheckedModeBanner: false, | |
| home: Scaffold( | |
| body: Center( | |
| child: MyWidget(), | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class MyWidget extends StatefulWidget { | |
| @override | |
| State<MyWidget> createState() => _MyWidgetState(); | |
| } | |
| class _MyWidgetState extends State<MyWidget> { | |
| late TextEditingController _controller; | |
| @override | |
| void initState() { | |
| super.initState(); | |
| _controller = BestTextEditingController(text: 'Hello'); | |
| } | |
| @override | |
| void dispose() { | |
| _controller.dispose(); | |
| super.dispose(); | |
| } | |
| @override | |
| Widget build(BuildContext context) { | |
| return Column( | |
| mainAxisSize: MainAxisSize.min, | |
| children: [ | |
| RichText( | |
| text: TextSpan( | |
| text: 'Hello ', | |
| style: Theme.of(context).textTheme.headlineMedium, | |
| children: [ | |
| TextSpan( | |
| text: 'World!', | |
| style: Theme.of(context).textTheme.headlineMedium?.copyWith( | |
| decoration: TextDecoration.underline, | |
| ), | |
| recognizer: TapGestureRecognizer() | |
| ..onTap = () => print('Hello, world!'), | |
| ) | |
| ], | |
| ), | |
| ), | |
| TextField( | |
| controller: _controller, | |
| style: Theme.of(context).textTheme.headlineMedium, | |
| maxLines: 10, | |
| minLines: 10, | |
| ), | |
| ], | |
| ); | |
| } | |
| } | |
| class BestTextEditingController extends TextEditingController { | |
| BestTextEditingController({super.text}); | |
| @override | |
| TextSpan buildTextSpan({ | |
| required BuildContext context, | |
| TextStyle? style, | |
| required bool withComposing, | |
| }) { | |
| return TextSpan( | |
| style: style, | |
| children: [ | |
| TextSpan( | |
| text: text, | |
| style: Theme.of(context).textTheme.headlineMedium?.copyWith( | |
| decoration: TextDecoration.underline, | |
| ), | |
| // recognizer: TapGestureRecognizer() | |
| // ..onTap = () => print('Hello, world!'), | |
| ), | |
| ], | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment