import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../settings_theme.dart'; class StorageAction extends StatelessWidget { const StorageAction({ super.key, required this.label, required this.onPressed, this.destructive = false, }); final String label; final VoidCallback? onPressed; final bool destructive; @override Widget build(BuildContext context) => usesCupertinoControls(context) ? CupertinoButton( onPressed: onPressed, child: Text( label, style: destructive ? TextStyle( color: CupertinoColors.destructiveRed.resolveFrom(context), ) : null, ), ) : TextButton( onPressed: onPressed, style: destructive ? TextButton.styleFrom( foregroundColor: Theme.of(context).colorScheme.error, ) : null, child: Text(label), ); } class StorageSwitch extends StatelessWidget { const StorageSwitch({ super.key, required this.label, required this.value, required this.onChanged, }); final String label; final bool value; final ValueChanged? onChanged; @override Widget build(BuildContext context) => Row( children: [ Expanded(child: Text(label)), Semantics( label: label, child: usesCupertinoControls(context) ? CupertinoSwitch(value: value, onChanged: onChanged) : Switch(value: value, onChanged: onChanged), ), ], ); } class StorageInput extends StatelessWidget { const StorageInput({ super.key, required this.label, required this.controller, required this.onChanged, required this.enabled, this.decimal = false, }); final String label; final TextEditingController controller; final ValueChanged onChanged; final bool enabled; final bool decimal; @override Widget build(BuildContext context) { final keyboard = TextInputType.numberWithOptions(decimal: decimal); return usesCupertinoControls(context) ? Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Text(label), const SizedBox(height: 8), Semantics( label: label, child: CupertinoTextField( controller: controller, enabled: enabled, keyboardType: keyboard, onChanged: onChanged, placeholder: 'No limit', ), ), ], ) : TextField( controller: controller, enabled: enabled, keyboardType: keyboard, onChanged: onChanged, decoration: InputDecoration( labelText: label, hintText: 'No limit', border: const OutlineInputBorder(), ), ); } } Widget storagePadding(Widget child) => Padding(padding: const EdgeInsets.all(16), child: child);