Loading files
import 'package:borneo_app/shared/widgets/rounded_icon_text_button.dart';
import 'package:flutter/material.dart';
class PowerButton extends StatefulWidget {
final bool enabled;
final bool value;
final void Function(bool)? onChanged;
final Widget label;
const PowerButton({super.key, required this.enabled, required this.value, required this.label, this.onChanged});
@override
_PowerButtonState createState() => _PowerButtonState();
}
class _PowerButtonState extends State<PowerButton> {
final bool _isLoading = false;
@override
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
final iconColor = widget.enabled
? widget.value
? Colors.green
: colorScheme.error
: null;
final loadingColor = colorScheme.onSurface;
return RoundedIconTextButton(
onPressed: _isLoading || widget.onChanged == null ? null : () => widget.onChanged?.call(widget.value),
borderColor: Theme.of(context).colorScheme.primary,
text: widget.value ? 'ON' : 'OFF',
buttonSize: 64,
icon: AnimatedSwitcher(
duration: Duration(milliseconds: 300),
child: _isLoading
? CircularProgressIndicator(color: loadingColor, key: ValueKey('loading'))
: Icon(
widget.value ? Icons.power_settings_new_outlined : Icons.power_settings_new,
key: ValueKey<bool>(widget.value),
size: 40,
color: iconColor,
),
),
);
}
}
8c2908ee5This file is pinned to the selected release. Download the original to open it in your design tool.