/*
 * @Author       : WuWei
 * @LastEditors: wjc
 * @Date         : 2021-04-08 16:51:56
 * @LastEditTime: 2022-12-13 10:30:41
 * @FilePath     : /wisdom-huiguanjia-app/wisdom_cli/lib/src/form_widget/components/switch.dart
 * @Description  : Do not edit
 */
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

import 'form_layout.dart';

///单项选择
class WFSwitch extends StatelessWidget {
  const WFSwitch({
    Key? key,
    this.isRequired,
    this.title,
    this.initialValue,
    this.onChanged,
  }) : super(key: key);

  ///是否必须
  final bool? isRequired;
  final Widget? title;
  final initialValue;

  ///选择
  final void Function(dynamic value)? onChanged;

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    var _initialValue = initialValue ?? false;
    return WisFormLayoutComponent(
      title: title,
      isRequired: isRequired,
      axis: Axis.horizontal,
      child: StatefulBuilder(
        builder: (BuildContext context, setState) {
          return Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              Switch.adaptive(
                activeColor: colorScheme.primary,
                inactiveThumbColor: colorScheme.grey,
                value: _initialValue,
                onChanged: (v) => onChanged!(v),
              )
            ],
          );
        },
      ),
    );
  }
}
