switch_button function

Widget switch_button({
  1. required String text,
  2. required bool value,
  3. required bool enabled,
  4. required Color active_track_color,
  5. required Color active_color,
  6. required Color inactive_color,
  7. required Color background_color,
  8. required dynamic callback(
    1. bool
    ),
  9. required double border_radius,
})

Implementation

Widget switch_button({
  required String text,
  required bool value,
  required bool enabled,
  required Color active_track_color,
  required Color active_color,
  required Color inactive_color,
  required Color background_color,
  required Function(bool) callback,
  required double border_radius,
}) {
  return Container(
    decoration: BoxDecoration(
      color: background_color,
      borderRadius: BorderRadius.all(
        Radius.circular(border_radius),
      ),
    ),
    child: Row(
      children: [
        Spacer(flex: 1),
        Expanded(
          flex: 9,
          child: Text(
            text,
            textAlign: TextAlign.center,
            style: TextStyle(
              color: Colors.white,
              fontSize: 12,
              fontWeight: FontWeight.bold,
            ),
          ),
        ),
        Expanded(
          flex: 4,
          child: Switch(
            value: value,
            onChanged: enabled
                ? (new_value) {
                    callback(new_value);
                  }
                : null,
            activeTrackColor: Colors.grey.withOpacity(0.5),
            inactiveTrackColor: Colors.grey.withOpacity(0.5),
            activeColor: active_color,
            inactiveThumbColor: inactive_color,
          ),
        ),
        Spacer(flex: 2),
      ],
    ),
  );
}