build method

  1. @override
Widget build(
  1. BuildContext context
)
override

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:

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) {
  MPLocalizations? locale = MPLocalizations.of(context);
  return SafeArea(
    child: SingleChildScrollView(
      padding: const EdgeInsets.symmetric(horizontal: 20.0, vertical: 16.0),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          // Preparation title
          Text(
            locale?.translate('preparation') ?? 'Test preparation',
            style: TextStyle(fontSize: 28, fontWeight: FontWeight.bold),
          ),
          const SizedBox(height: 20),
          // Required equipment section
          Text(
            locale?.translate('required_equipment') ?? 'Required equipment',
            style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
            textAlign: TextAlign.left,
          ),
          const SizedBox(height: 20),
          // Equipment visualization row
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              // Chair requirement column
              Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Center(
                    child: Text(
                      locale?.translate('chair') ?? 'Chair without armrests',
                      style: TextStyle(fontSize: 16),
                    ),
                  ),
                  const SizedBox(height: 10),
                  Center(
                    child: SvgPicture.asset(
                      'assets/images/chair_without_armrests.svg',
                      package: 'carp_mobility_package',
                      width: 150,
                      height: 150,
                    ),
                  ),
                ],
              ),
              // Marker requirement column
              Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Center(
                    child: Text(
                      locale?.translate('marker') ?? 'Any item as marker',
                      style: TextStyle(fontSize: 16),
                    ),
                  ),
                  const SizedBox(height: 10),
                  Center(
                    child: Image.asset(
                      'assets/images/cone.png',
                      package: 'carp_mobility_package',
                      width: 150,
                      height: 150,
                    ),
                  ),
                ],
              ),
            ],
          ),
          const SizedBox(height: 20),
          Text(
            locale?.translate('wearing_the_device') ?? 'Wearing the device',
            style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
          ),
          Center(
            child: ClipRRect(
              borderRadius: BorderRadius.circular(8),
              child:
                  step.isMovesense()
                      ? Image.asset(
                        'assets/images/sts_movesense_on_chest.png',
                        package: 'carp_mobility_package',
                        height: 225,
                      )
                      : Image.asset(
                        'assets/images/phone_placement_chest.jpg',
                        package: 'carp_mobility_package',
                        height: 225,
                      ),
            ),
          ),
          const SizedBox(height: 8),
          ...(step.isMovesense()
              ? [
                BulletItem(
                  locale?.translate('movesense_chest_preparation_sensor') ??
                      'Equip the Movesense to your chest with the strap according to the image above',
                ),
                BulletItem(
                  locale?.translate(
                        'movesense_preparation_logo_orientation',
                      ) ??
                      'Wear the sensor so that the "Movesense" logo is visible and oriented so you can read it normally (not upside down)',
                ),
              ]
              : [
                BulletItem(
                  locale?.translate('phone_chest_preparation_sensor') ??
                      'Place your phone in a secure holder on your chest',
                ),
                BulletItem(
                  locale?.translate(
                        'phone_chest_preparation_logo_orientation',
                      ) ??
                      'Ensure the phone screen is facing outward',
                ),
              ]),
          const SizedBox(height: 20),
          // Positioning instructions section
          Text(
            locale?.translate('position_yourself') ??
                'Position yourself correctly',
            style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
          ),
          const SizedBox(height: 4),
          // Seating position guidance
          BulletItem(
            locale?.translate('sit_straight') ??
                'Sit in the middle of the chair with your back straight',
          ),
          // Walking aid allowance note
          BulletItem(
            locale?.translate('walking_aid_allowed') ??
                'You can use walking aids if needed',
          ),
          const SizedBox(height: 20),
          Text(
            locale?.translate('safety') ?? 'Safety',
            style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
          ),
          const SizedBox(height: 4),
          BulletItem(
            locale?.translate('safety_instruction') ??
                'To reduce fall risk, perform the test near a table or have a supervisor present',
          ),
        ],
      ),
    ),
  );
}