build method
Describes the part of the user interface represented by this widget.
The framework calls this method when this widget is inserted into the tree in a given BuildContext and when the dependencies of this widget change (e.g., an InheritedWidget referenced by this widget changes). This method can potentially be called in every frame and should not have any side effects beyond building a widget.
The framework replaces the subtree below this widget with the widget returned by this method, either by updating the existing subtree or by removing the subtree and inflating a new subtree, depending on whether the widget returned by this method can update the root of the existing subtree, as determined by calling Widget.canUpdate.
Typically implementations return a newly created constellation of widgets that are configured with information from this widget's constructor and from the given BuildContext.
The given BuildContext contains information about the location in the tree at which this widget is being built. For example, the context provides the set of inherited widgets for this location in the tree. A given widget might be built with multiple different BuildContext arguments over time if the widget is moved around the tree or if the widget is inserted into the tree in multiple places at once.
The implementation of this method must only depend on:
- the fields of the widget, which themselves must not change over time, and
- any ambient state obtained from the
contextusing BuildContext.dependOnInheritedWidgetOfExactType.
If a widget's build method is to depend on anything else, use a StatefulWidget instead.
See also:
- StatelessWidget, which contains the discussion on performance considerations.
Implementation
@override
Widget build(BuildContext context) {
final isDark = Theme.of(context).brightness == Brightness.dark;
final cardBg = isDark ? const Color(0xFF1C2333) : Colors.white;
final divColor = isDark ? Colors.white12 : Colors.black12;
final labelColor = isDark ? Colors.white38 : Colors.black38;
final textColor = isDark ? Colors.white : Colors.black87;
final subTextColor = isDark ? Colors.white60 : Colors.black54;
final iconBg =
isDark ? const Color(0xFF252D3D) : const Color(0xFFF1F3F8);
return SingleChildScrollView(
child: Padding(
// extra bottom padding so the FAB/keyboard never covers the button
padding: const EdgeInsets.only(bottom: 24),
child: Container(
margin: const EdgeInsets.all(12),
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
decoration: BoxDecoration(
color: cardBg,
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: isDark ? Colors.white10 : Colors.black12,
width: 0.5,
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(isDark ? 0.3 : 0.06),
blurRadius: 24,
offset: const Offset(0, 4),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// ── Banner ──
_Banner(
initials: _initials,
active: data.active ?? false,
role: data.role ?? 'USER',
controller: controller,
data: data,
),
// ── Body ──
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 44), // space for the overlapping avatar
// Name
TextFormField(
controller: controller.fullNameController,
keyboardType: TextInputType.name,
decoration: customInputDecoration("Full Name"),
),
const SizedBox(height: 12),
// Designation
TextFormField(
controller: controller.designationController,
keyboardType: TextInputType.name,
decoration: customInputDecoration("Designation"),
),
const SizedBox(height: 12),
// Organization
TextFormField(
controller: controller.organizationController,
keyboardType: TextInputType.name,
decoration: customInputDecoration("Organization"),
),
const SizedBox(height: 12),
// Address
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(Icons.location_on_outlined,
size: 18, color: labelColor),
const SizedBox(width: 8),
// FIX: TextFormField must be wrapped in Expanded when
// placed inside a Row, otherwise it tries to take
// infinite width and throws a layout exception
// (which shows up as a blank/white screen in release
// builds).
Expanded(
child: TextFormField(
controller: controller.addressController,
keyboardType: TextInputType.streetAddress,
decoration: customInputDecoration("Address"),
),
),
],
),
_Divider(color: divColor),
/*TextFormField(
initialValue: data.email ?? '',
readOnly: true,
decoration: customInputDecoration("Email").copyWith(
prefixIcon: const Icon(Icons.email_outlined),
filled: true,
),
),*/
const SizedBox(height: 12),
TextFormField(
controller: controller.mobileController,
keyboardType: TextInputType.phone,
decoration: customInputDecoration("Mobile").copyWith(
prefixIcon: const Icon(Icons.phone_outlined),
),
),
_Divider(color: divColor),
// Meta row
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: _MetaRow(
userId: data.userId,
createdAt: data.createdAt,
updatedAt: data.updatedAt,
divColor: divColor,
labelColor: labelColor,
textColor: textColor,
),
),
),
const SizedBox(height: 16),
Obx(
() => SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: controller.isUpdating.value
? null
: controller.updateProfile,
child: controller.isUpdating.value
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
color: Colors.white,
),
)
: const Text("Update Profile"),
),
),
),
],
),
],
),
),
),
);
}