Input group
Use an input group for an editable value with a fixed unit or other context beside it. Include the unit in the field name so people can enter the right value by ear.
Weigh a parcel
#Enter the weight of a parcel. The kilogram unit stays in place when you edit the number or clear the field.
components/input-group/appliance/weigh_parcel.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class WeighParcel extends StatefulWidget {
const WeighParcel({super.key});
@override
State<WeighParcel> createState() => _WeighParcelState();
}
class _WeighParcelState extends State<WeighParcel> {
String weight = '';
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 360),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
ApplianceInputGroup(
label: 'Parcel weight in kilograms',
suffix: 'kg',
keyboardType: const TextInputType.numberWithOptions(decimal: true),
onChanged: (value) => setState(() => weight = value.trim()),
),
const SizedBox(height: 12),
Text(weight.isEmpty ? 'Parcel not weighed' : 'Entered: $weight kg'),
],
),
);
}
Parameters
ApplianceInputGroup API ↗label- Identifies the value and its unit.
suffix- Fixed kilogram unit beside the editable value.
onChanged- Receives only the editable portion.
keyboardType- Requests a keyboard with decimal input.
Shared behaviour
- Keyboard and focus. Tab into the field and edit the number. The unit is fixed text and has no separate action.
- Screen readers. The field name includes “kilograms”. The summary below repeats the entered amount with its unit.
- Direction and type. Watch the unit beside the field in RTL. At large text sizes the field and the summary still share the width of the phone frame.