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) {
  return Scaffold(
    appBar: AppBar(
      title: const Text('Common Material index page'),
    ),
    body: ListView(
      children: <Widget>[
        const SizedBox(
          height: 16,
        ),
        NavigationListTile(
          page: CommonMaterialWidgetsPage(
            label: 'Buttons',
            materialWidgets: <BasicShowcaseWidget>[
              BasicShowcaseWidget(
                label: 'Elevated button - focused',
                child: ElevatedButton(
                  onPressed: () {},
                  autofocus: true,
                  child: const Text('Test me'),
                ),
              ),
              const BasicShowcaseWidget(
                label: 'Elevated button inactive',
                child: ElevatedButton(
                  onPressed: null,
                  child: Text("Can't hit me"),
                ),
              ),
              BasicShowcaseWidget(
                label: 'Elevated button',
                child: ElevatedButton(
                  onPressed: () {},
                  child: const Text('Test me'),
                ),
              ),
              BasicShowcaseWidget(
                label: 'Filled button - focused',
                child: FilledButton(
                  onPressed: () {},
                  autofocus: true,
                  child: const Text('Test me'),
                ),
              ),
              BasicShowcaseWidget(
                label: 'Filled button',
                child: FilledButton(
                  onPressed: () {},
                  child: const Text('Test me'),
                ),
              ),
              const BasicShowcaseWidget(
                label: 'Filled button - inactive',
                child: FilledButton(
                  onPressed: null,
                  child: Text("Can't hit me"),
                ),
              ),
              // Filled button tonal
              BasicShowcaseWidget(
                label: 'Filled tonal button - focused',
                child: FilledButton.tonal(
                  onPressed: () {},
                  autofocus: true,
                  child: const Text('Test me'),
                ),
              ),
              BasicShowcaseWidget(
                label: 'Filled tonal button',
                child: FilledButton.tonal(
                  onPressed: () {},
                  child: const Text('Test me'),
                ),
              ),
              const BasicShowcaseWidget(
                label: 'Filled tonal button - inactive',
                child: FilledButton.tonal(
                  onPressed: null,
                  child: Text("Can't hit me"),
                ),
              ),
              // outlined button
              BasicShowcaseWidget(
                label: 'OutlinedButton - focused',
                child: OutlinedButton(
                  onPressed: () {},
                  autofocus: true,
                  child: const Text('Test me'),
                ),
              ),
              BasicShowcaseWidget(
                label: 'OutlinedButton button',
                child: OutlinedButton(
                  onPressed: () {},
                  child: const Text('Test me'),
                ),
              ),
              const BasicShowcaseWidget(
                label: 'OutlinedButton - inactive',
                child: OutlinedButton(
                  onPressed: null,
                  child: Text("Can't hit me"),
                ),
              ),
              // Text button
              BasicShowcaseWidget(
                label: 'TextButton - focused',
                child: TextButton(
                  onPressed: () {},
                  autofocus: true,
                  child: const Text('Test me'),
                ),
              ),
              BasicShowcaseWidget(
                label: 'TextButton button',
                child: TextButton(
                  onPressed: () {},
                  child: const Text('Test me'),
                ),
              ),
              const BasicShowcaseWidget(
                label: 'TextButton - inactive',
                child: TextButton(
                  onPressed: null,
                  child: Text("Can't hit me"),
                ),
              ),

              // Text button
              BasicShowcaseWidget(
                label: 'IconButton - focused',
                child: IconButton(
                  onPressed: () {},
                  autofocus: true,
                  icon: const Icon(Icons.hearing),
                  tooltip: 'Tengo tooltip',
                ),
              ),
              BasicShowcaseWidget(
                label: 'IconButton button',
                child: IconButton(
                  onPressed: () {},
                  icon: const Icon(Icons.save),
                  tooltip: 'Tengo tooltip',
                ),
              ),
              const BasicShowcaseWidget(
                label: 'IconButton - inactive',
                child: IconButton(
                  onPressed: null,
                  icon: Icon(Icons.heart_broken),
                  tooltip: 'Tengo tooltip',
                ),
              ),
              BasicShowcaseWidget(
                label: 'Segmented button',
                child: SegmentedButton<int>(
                  onSelectionChanged: (Set<int> value) {},
                  segments: const <ButtonSegment<int>>[
                    ButtonSegment<int>(
                      value: 1,
                      label: Text('D'),
                      icon: Icon(Icons.calendar_view_day),
                    ),
                    ButtonSegment<int>(
                      value: 2,
                      label: Text('W'),
                      icon: Icon(Icons.calendar_view_week),
                    ),
                    ButtonSegment<int>(
                      value: 3,
                      label: Text('M'),
                      icon: Icon(Icons.calendar_view_month),
                    ),
                    ButtonSegment<int>(
                      value: 4,
                      label: Text('Y'),
                      icon: Icon(Icons.calendar_today),
                    ),
                  ],
                  selected: const <int>{1, 3},
                  multiSelectionEnabled: true,
                ),
              ),
            ],
          ),
          title: 'Buttons',
          subTitle: 'Showcase your buttons main components.',
        ),

        NavigationListTile(
          page: CommonMaterialWidgetsPage(
            label: 'Communication widgets',
            materialWidgets: <BasicShowcaseWidget>[
              BasicShowcaseWidget(
                label: 'Badge',
                child: Badge(
                  label: const Text('1'),
                  child: Container(
                    width: 50,
                    height: 50,
                    alignment: Alignment.center,
                    decoration: BoxDecoration(
                      color: Theme.of(context).splashColor,
                      borderRadius: BorderRadius.circular(25),
                    ),
                    child: const Icon(Icons.heart_broken),
                  ),
                ),
              ),
              const BasicShowcaseWidget(
                label: 'LinearProgressIndicator',
                child: Center(
                  child: AnimatedLinearProgressIndicatorWidget(),
                ),
              ),
              const BasicShowcaseWidget(
                label: 'Dialog Example',
                child: DialogExample(),
              ),
              BasicShowcaseWidget(
                label: 'ListTile',
                child: ColoredBox(
                  color: Theme.of(context).primaryColorLight,
                  child: const ListTile(
                    title: Text('One list tile'),
                  ),
                ),
              ),
              BasicShowcaseWidget(
                label: 'ListTile',
                child: ColoredBox(
                  color: Theme.of(context).primaryColorLight,
                  child: const ListTile(
                    trailing: Icon(Icons.arrow_forward_ios),
                    title: Text('One list tile trailing'),
                  ),
                ),
              ),
              BasicShowcaseWidget(
                label: 'ListTile',
                child: ColoredBox(
                  color: Theme.of(context).primaryColorLight,
                  child: const ListTile(
                    trailing: Icon(Icons.arrow_forward_ios),
                    title: Text('One list tile trailing'),
                  ),
                ),
              ),
              BasicShowcaseWidget(
                label: 'ListTile',
                child: ColoredBox(
                  color: Theme.of(context).primaryColorLight,
                  child: const ListTile(
                    leading: FlutterLogo(),
                    title: Text('One list tile leading'),
                    subtitle: Text('This is the subtitle'),
                  ),
                ),
              ),
              BasicShowcaseWidget(
                label: 'ListTile',
                child: ColoredBox(
                  color: Theme.of(context).primaryColorLight,
                  child: const ListTile(
                    leading: FlutterLogo(),
                    title: Text('One list tile leading'),
                    subtitle: Text('This is the subtitle\nThird line'),
                  ),
                ),
              ),
              BasicShowcaseWidget(
                label: 'Divider',
                child: Center(
                  child: Column(
                    children: <Widget>[
                      Expanded(
                        child: Container(
                          alignment: Alignment.center,
                          width: double.maxFinite,
                          color: Theme.of(context).primaryColor,
                          child: const Text('above'),
                        ),
                      ),
                      const Divider(
                        height: 20,
                        thickness: 5,
                        endIndent: 5,
                        indent: 5,
                      ),
                      Expanded(
                        child: Container(
                          alignment: Alignment.center,
                          width: double.maxFinite,
                          color: Theme.of(context).primaryColorLight,
                          child: const Text('below'),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              BasicShowcaseWidget(
                label: 'Card',
                child: Card(
                  elevation: 5.0,
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      const ListTile(
                        leading: Icon(Icons.album),
                        title: Text('The Enchanted Nightingale'),
                        subtitle: Text(
                          'Music by Julie Gable. Lyrics by Sidney Stein.',
                        ),
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: <Widget>[
                          TextButton(
                            child: const Text('BUY TICKETS'),
                            onPressed: () {},
                          ),
                          const SizedBox(width: 8),
                          TextButton(
                            child: const Text('LISTEN'),
                            onPressed: () {},
                          ),
                          const SizedBox(width: 8),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
              BasicShowcaseWidget(
                label: 'Card',
                child: Card(
                  elevation: 0.0,
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      const ListTile(
                        leading: Icon(Icons.heart_broken),
                        title: Text('No elevation'),
                        subtitle: Text(
                          'Music by Flow GPT.',
                        ),
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: <Widget>[
                          const Expanded(child: SizedBox(width: 8)),
                          TextButton(
                            child: const Text('+ Info'),
                            onPressed: () {},
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
          title: 'Communication widgets',
          subTitle: 'Items used for communicate actions to the user',
        ),

        NavigationListTile(
          title: 'Selection',
          subTitle: 'Used for user interaction',
          page: CommonMaterialWidgetsPage(
            label: 'Selection widgets',
            materialWidgets: <BasicShowcaseWidget>[
              const BasicShowcaseWidget(
                label: 'Checkbox',
                child: CheckboxExample(),
              ),
              const BasicShowcaseWidget(
                label: 'Date Picker',
                child: DatePickerExample(restorationId: 'main'),
              ),
              const BasicShowcaseWidget(
                label: 'Pop menĂº',
                child: PopupMenuExample(),
              ),
              BasicShowcaseWidget(
                label: 'Checkbox',
                child: Chip(
                  avatar: CircleAvatar(
                    backgroundColor: Theme.of(context).primaryColorDark,
                    child: Icon(
                      Icons.person,
                      size: 20.0,
                      color: Theme.of(context).canvasColor,
                    ),
                  ),
                  label: const Text('Aaron Burr'),
                ),
              ),
            ],
          ),
        ),
        //
      ],
    ),
  );
}