decorate method

  1. @override
List<Decorator> decorate(
  1. BuildContext context
)
override

Implementation

@override
List<Decorator> decorate(BuildContext context) {
  return [
    Decorator(
      (context, story) {
        return ListenableBuilder(
          listenable: this,
          builder: (context, child) {
            if (value) {
              return ConstrainedBox(
                constraints: BoxConstraints.tight(MediaQuery.sizeOf(context)),
                child: Flex(
                  // TODO(@melvspace): 03/06/25 add direction change support.
                  direction: Axis.horizontal,
                  children: [
                    for (final brightness in Brightness.values) //
                      Expanded(
                        child: MediaQuery(
                          data: MediaQuery.of(context).copyWith(
                            platformBrightness: brightness,
                          ),
                          child: Builder(builder: (context) {
                            final materialApp =
                                context.findAncestorStateOfType<
                                    State<MaterialApp>>();

                            return Theme(
                              data: switch (brightness) {
                                Brightness.light => lightTheme ??
                                    materialApp!.widget.theme ??
                                    ThemeData.light(),
                                Brightness.dark => darkTheme ??
                                    materialApp!.widget.darkTheme ??
                                    ThemeData.dark(),
                              },
                              child: child!,
                            );
                          }),
                        ),
                      ),
                  ],
                ),
              );
            }

            return child!;
          },
          child: story,
        );
      },
    )
  ];
}