Flutter:onPressed在按钮右侧显示文本

问题描述 投票:1回答:1

我创建了一个带有字母'M'的圆形按钮。轻按此按钮后,我想在其右侧显示文本。最初,按钮右侧不应该有文本,只有在轻按按钮时才显示。我将如何使用它?

}

class _SelectDaysState extends State<SelectDays> {
  bool selectedDay = false;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Container(
      height: MediaQuery.of(context).size.height,
      width: MediaQuery.of(context).size.width,
      decoration: BoxDecoration(
        gradient: LinearGradient(colors: [
          Theme.of(context).colorScheme.charcoalGrey,
          Theme.of(context).colorScheme.black
        ], begin: Alignment.topCenter, end: Alignment.bottomCenter),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          const SizedBox(height: 60),
          Padding(
            padding: const EdgeInsets.only(left: 20, bottom: 70),
            child: Text(
              'Select your days!',
              style: h1,
            ),
          ),
          Row(
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.only(left: 20),
              ),
              Column(
                children: <Widget>[
                  Row(
                    children: <Widget>[
                      Container(
                        child: SizedBox.fromSize(
                          size: Size(56, 56),
                          child: ClipOval(
                            child: Material(
                              color: Theme.of(context).colorScheme.watermelon,
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: <Widget>[
                                  RaisedButton(
                                                  child: Text('Selected',
                                                  style: TextStyle(
                                                  color: Colors.white),
                                                  ),
                                                  onPressed: () {
                                                    setState(() {
                                                      selectedDay = true;
                                                    });

flutter flutter-layout
1个回答
0
投票

您可以仅根据selectedDay的值来设置Text()的文本属性。

Text(
  selectedDay ? 'Hello World' : '', // When true, "Hello World" is shown, otherwhise nothing
),
© www.soinside.com 2019 - 2024. All rights reserved.