2023-12-22 21:23:24 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2024-08-26 00:00:23 +08:00
|
|
|
typedef OnChanged = void Function(bool value);
|
2023-12-22 21:23:24 +08:00
|
|
|
|
|
|
|
class AMapSwitchButton extends StatefulWidget {
|
|
|
|
const AMapSwitchButton({
|
2024-08-26 00:00:23 +08:00
|
|
|
super.key,
|
2023-12-22 21:23:24 +08:00
|
|
|
this.label,
|
|
|
|
this.onSwitchChanged,
|
|
|
|
this.defaultValue = true,
|
2024-08-26 00:00:23 +08:00
|
|
|
});
|
2023-12-22 21:23:24 +08:00
|
|
|
|
|
|
|
final Text? label;
|
|
|
|
final Function? onSwitchChanged;
|
|
|
|
final bool defaultValue;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _SwitchButtonState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SwitchButtonState extends State<AMapSwitchButton> {
|
|
|
|
late bool _localValue;
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_localValue = widget.defaultValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: <Widget>[
|
|
|
|
widget.label!,
|
|
|
|
Switch(
|
|
|
|
value: _localValue,
|
|
|
|
onChanged: (null != widget.onSwitchChanged)
|
|
|
|
? (value) {
|
|
|
|
setState(() {
|
|
|
|
_localValue = value;
|
|
|
|
});
|
|
|
|
widget.onSwitchChanged!(value);
|
|
|
|
}
|
|
|
|
: null,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|