简体   繁体   中英

how to make selected text underline in flutter

How do i implement something like this in flutter在此处输入图像描述

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class HomePage extends StatefulWidget {
  @override
  _HomePage createState() => _HomePage();
}

class _HomePage extends State<HomePage> {
  var text = 'test';
  bool isSelect= false;

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        body: Column(
          children: [
            GestureDetector(
                onTap: (){
                  if(isSelect == false){
                    setState(() {
                      isSelect= true;
                    });
                  }else{
                    setState(() {
                      isSelect = false;
                    });
                  }
                },
                child: isSelect == false ? Center(child: Text(text,style: const TextStyle(fontSize: 50,fontWeight: FontWeight.bold),)): isSelect == true ? Center(child: Text(text,style: const TextStyle(decoration: TextDecoration.underline,fontSize: 50,fontWeight: FontWeight.bold,color: Colors.red),)):Text('')),
          ],
        ),
      ),
    );
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM