build method

  1. @override
Widget build(
  1. BuildContext ctx
)
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 ctx) => FloatingGlassView(
  child: Padding(
    padding: const EdgeInsets.symmetric(
      vertical: 10,
      horizontal: 10,
    ),
    child: Row(
      // The Row widget in Flutter does not have a 'spacing' property directly.
      // You might want to use mainAxisAlignment or wrap children with Padding/SizedBox.
      // For now, I will keep it as is since it's not the primary error,
      // but this will likely cause a different error or unexpected layout.
      // Consider using mainAxisAlignment: MainAxisAlignment.spaceAround or similar,
      // or use a List.generate with Padding for spacing if this was custom.
      // If 'spacing' is from a custom Row-like widget, then it's fine.
      // Assuming it's a standard Flutter Row, this is a potential issue.
      // For now, focusing on the appCtrl error.
      // To make it compile if it's a standard Row, I will remove 'spacing: 5'.
      // If 'spacing' is intended, you might be using a custom widget or need to adjust.
      // For now, let's assume it was a typo for a standard Row and remove it
      // or replace it with something like MainAxisAlignment.
      mainAxisAlignment: MainAxisAlignment.spaceBetween, // Example replacement for spacing
      children: [
        Flexible(
          flex: 1,
          fit: FlexFit.tight,
          child: components.MediaDeviceContextBuilder(
            builder: (context, roomCtx, mediaDeviceCtx) => FloatingGlassButton(
              sfIcon: mediaDeviceCtx.microphoneOpened
                  ? sf.SFIcons.sf_microphone_fill
                  : sf.SFIcons.sf_microphone_slash_fill,
              subWidget: components.ParticipantSelector(
                filter: (identifier) => identifier.isAudio && identifier.isLocal,
                builder: (context, identifier) => const SizedBox(
                  width: 15,
                  height: 15,
                  child: components.AudioVisualizerWidget(
                    options: components.AudioVisualizerWidgetOptions(
                      barCount: 5,
                      spacing: 1,
                      // color: Theme.of(context).colorScheme.primary,
                    ),
                  ),
                ),
              ),
              onTap: () {
                mediaDeviceCtx.microphoneOpened
                    ? mediaDeviceCtx.disableMicrophone()
                    : mediaDeviceCtx.enableMicrophone();
              },
            ),
          ),
        ),
        Flexible(
          flex: 1,
          fit: FlexFit.tight,
          child: components.MediaDeviceContextBuilder(
            builder: (context, roomCtx, mediaDeviceCtx) => FloatingGlassButton(
              sfIcon: mediaDeviceCtx.cameraOpened ? sf.SFIcons.sf_video_fill : sf.SFIcons.sf_video_slash_fill,
              // ***** CORRECTED THIS LINE *****
              onTap: () => ctx.read<AppCtrl>().toggleUserCamera(mediaDeviceCtx),
            ),
          ),
        ),
        Flexible( // Added const here
          flex: 1,
          fit: FlexFit.tight,
          child: FloatingGlassButton(
            sfIcon: sf.SFIcons.sf_arrow_up_square_fill,
            // If you uncomment this, it also needs to use ctx.read<AppCtrl>()
            // onTap: () => ctx.read<AppCtrl>().toggleScreenShare(),
          ),
        ),
        Selector<AppCtrl, AgentScreenState>(
          selector: (selectorContext, appCtrlInstance) => appCtrlInstance.agentScreenState,
          builder: (builderContext, agentScreenStateValue, child) => Flexible(
            flex: 1,
            fit: FlexFit.tight,
            child: FloatingGlassButton(
              isActive: agentScreenStateValue == AgentScreenState.transcription,
              sfIcon: sf.SFIcons.sf_ellipsis_message_fill,
              // Use the context from the builder for read, or the outer ctx
              onTap: () => builderContext.read<AppCtrl>().toggleAgentScreenMode(),
            ),
          ),
        ),
        Flexible(
          flex: 1,
          fit: FlexFit.tight,
          child: FloatingGlassButton(
            iconColor: LKColorPaletteLight().fgModerate,
            sfIcon: sf.SFIcons.sf_phone_down_fill,
            onTap: () => ctx.read<AppCtrl>().disconnect(),
          ),
        ),
      ],
    ),
  ),
);