We will see how to use Switch widget that we can use for profile.
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class ProfileButton extends StatelessWidget {
final IconData icon;
final String title;
final bool isButtonActive;
final Function onTap;
ProfileButton({@required this.icon, @required this.title, @required this.onTap, this.isButtonActive});
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onTap,
child: Container(
padding: EdgeInsets.symmetric(
horizontal: Dimensions.PADDING_SIZE_SMALL,
vertical: isButtonActive != null ? 5 : 15,
),
decoration: BoxDecoration(
color: Theme.of(context).cardColor,
borderRadius: BorderRadius.circular(5),
boxShadow: [BoxShadow(color: Colors.grey[ 200], spreadRadius: 1, blurRadius: 5)],
),
child: Row(children: [
Icon(icon, size: 25),
SizedBox(width: 10),
Expanded(child: Text(title, style: robotoRegular)),
isButtonActive != null ? Switch(
value: isButtonActive,
onChanged: (bool isActive) => onTap(),
activeColor: Theme.of(context).primaryColor,
activeTrackColor: Theme.of(context).primaryColor.withOpacity(0.5),
) : SizedBox(),
]),
),
);
}
}
Switch widget takes a few parameters
Switch(
value: isButtonActive,
onChanged: (bool isActive) => onTap(),
activeColor: Theme.of(context).primaryColor,
activeTrackColor: Theme.of(context).primaryColor.withOpacity(0.5),
)