How to add a TextButton inside ProfileListItem in flutter

how i create a text button inside profile list item?

please check the code and help to create a text button i edited previous code because 2 person said that they need to see my ProfileListItem

i tried to add a TextButton inside ProfileListItem but i can't. here is my code how i create a text button inside profile list item?

      Expanded(

            child: ListView(
             children: const <Widget>[

               ProfileListItem(
                 icon: LineAwesomeIcons.lock,
                 text: 'Privacy',
                 hasNavigation: true,
               ),


class ProfileListItem extends StatelessWidget {
  final IconData icon;
  final text;
  final bool hasNavigation;

  const ProfileListItem({
    Key? key,
    required this.icon,
    this.text,
    required this.hasNavigation,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
        height: kSpacingUnit.w * 5.5,
        margin: EdgeInsets.symmetric(horizontal: kSpacingUnit.w * 4)
            .copyWith(bottom: kSpacingUnit.w * 2),
        padding: EdgeInsets.symmetric(horizontal: kSpacingUnit.w * 2),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(kSpacingUnit.w * 3),
          //color: Theme.of(context).backgroundColor,
          color: AppColors.deep_orange,
        ),
        child: Row(children: <Widget>[
          Icon(
            this.icon,
            size: kSpacingUnit.w * 2.5,
          ),
          SizedBox(width: kSpacingUnit.w * 2.5),
        
 
            Text(
              this.text,
              style: kTitleTextStyle.copyWith(fontWeight: FontWeight.w500),
          
          ),
          Row(
            children: <Widget>[
              Icon(
                this.icon,
                size: kSpacingUnit.w * 2.5,
              ),
              SizedBox(width: kSpacingUnit.w * 2.5),
              Text(
                this.text,
                style: kTitleTextStyle.copyWith(fontWeight: FontWeight.w500),
              ),
             
            ],
          ),
        ]));
  }
}

Upvotes: -2

Views: 72

Answers (1)

Rahul Variya
Rahul Variya

Reputation: 1352

output

Please try the below code :

class ProfileListItem extends StatelessWidget {
  final IconData icon;
  final String? text;
  final bool hasNavigation;

  const ProfileListItem({
    Key? key,
    required this.icon,
    this.text,
    required this.hasNavigation,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
        height: 10.h,
        // margin:
        //     EdgeInsets.symmetric(horizontal: 10.w * 4).copyWith(bottom: 10 * 2),
        // padding: EdgeInsets.symmetric(horizontal: 10.w * 2),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(10 * 3),
          //color: Theme.of(context).backgroundColor,
          color: Colors.deepOrange,
        ),
        child: Row(children: [
          TextButton(
            onPressed: () {},
            child: Text(
              text ?? "",
              style: const TextStyle(fontSize: 12),
            ),
          ),
          Expanded(
            child: TextButton(
              onPressed: () {},
              child: Row(
                children: <Widget>[
                  Icon(
                    icon,
                    size: 20,
                    color: Colors.white,
                  ),
                  Text(
                    text ?? "",
                    style: const TextStyle(
                      fontSize: 12,
                      color: Colors.white,
                    ),
                  ),
                ],
              ),
            ),
          ),
        ]));
  }
}

For more detail see here : https://api.flutter.dev/flutter/material/TextButton-class.html

Upvotes: 0

Related Questions