appBar<T extends MarkdownFlutterPageStateGeneralFramework> static method

AppBar appBar<T extends MarkdownFlutterPageStateGeneralFramework>({
  1. Key? key,
  2. required bool isLoading,
  3. required BuildContext context,
  4. required T markdownFlutterPageStateGeneralFramework,
})

UncompleteDocumentation

Implementation

static AppBar appBar<T extends MarkdownFlutterPageStateGeneralFramework>({
  Key? key,
  required bool isLoading,
  required BuildContext context,
  required T markdownFlutterPageStateGeneralFramework,
}) {
  final bodySmall =
      (context.theme.textTheme.bodySmall ?? const TextStyle()).copyWith(
    color: context.theme.indicatorColor,
    shadows: context.extensionGeneralLibFlutterShadows(),
  );
  return AppBar(
    key: key,
    centerTitle: true,
    leading: (isLoading) ? const SizedBox.shrink() : null,
    title: Text(
      markdownFlutterPageStateGeneralFramework.widget.title.trim(),
      style: context.theme.textTheme.titleLarge?.copyWith(
        shadows: context.extensionGeneralLibFlutterShadows(),
      ),
    ),
    backgroundColor: context.theme.primaryColor,
    actions: [
      ...markdownFlutterPageStateGeneralFramework.widget
          .markdownFlutterAppBarActionsGeneralFrameworkFunctionBuilder(
              context, markdownFlutterPageStateGeneralFramework),
      PopupMenuButton(
        iconSize: 20,
        position: PopupMenuPosition.under,
        color: context.theme.primaryColor,
        itemBuilder: (context) {
          return [
            PopupMenuItem(
              onTap: () {
                if (isLoading) {
                  return;
                }
                markdownFlutterPageStateGeneralFramework.handleFunction(
                  onFunction: (context, statefulWidget) async {
                    await markdownFlutterPageStateGeneralFramework.refresh();
                  },
                );
              },
              child: () {
                if (isLoading) {
                  return CircularProgressIndicator(
                    color: context.theme.indicatorColor,
                  );
                }
                return Row(
                  children: [
                    IconButton(
                      onPressed: null,
                      icon: Icon(
                        Icons.refresh,
                        color: context.theme.indicatorColor,
                        shadows: context.extensionGeneralLibFlutterShadows(),
                      ),
                    ),
                    Text(
                      "Refresh / Reload",
                      style: bodySmall,
                    ),
                  ],
                );
              }(),
            ),
            PopupMenuItem(
              onTap: () {
                if (isLoading) {
                  return;
                }
                markdownFlutterPageStateGeneralFramework.handleFunction(
                  onFunction: (context, statefulWidget) async {
                    if (markdownFlutterPageStateGeneralFramework.textToSpeech
                            .isSupport() ==
                        false) {
                      context.showAlertGeneralFramework(
                        alertGeneralFrameworkOptions:
                            AlertGeneralFrameworkOptions(
                          title: "Unsupported",
                          isShowCancelButton: false,
                          isShowCloseButton: false,
                          builder: (context, alertGeneralFrameworkOptions) {
                            return "Maaf device anda saat ini tidak support text to speech, tunggu beberapa hari ya sampai kami bisa develop text to speech pada device anda";
                          },
                        ),
                      );
                      return;
                    }

                    for (final element in [
                      markdownFlutterPageStateGeneralFramework
                          .markdownFlutterContentGeneralFramework.title
                          .trim(),
                      markdownFlutterPageStateGeneralFramework
                          .markdownFlutterContentGeneralFramework.content
                          .trim(),
                    ]) {
                      if (element.isNotEmpty) {
                        final text = markdownFlutterPageStateGeneralFramework
                            .textToSpeech
                            .utils_removeHtmlOrMarkdown(text: element);
                        if (text.isNotEmpty) {
                          await markdownFlutterPageStateGeneralFramework
                              .textToSpeech
                              .speak(text: element);
                        }
                      }
                    }
                  },
                );
              },
              child: () {
                if (isLoading) {
                  return CircularProgressIndicator(
                    color: context.theme.indicatorColor,
                  );
                }
                return Row(
                  children: [
                    IconButton(
                      onPressed: null,
                      icon: Icon(
                        Icons.speaker,
                        color: context.theme.indicatorColor,
                        shadows: context.extensionGeneralLibFlutterShadows(),
                      ),
                    ),
                    Text(
                      "Speak",
                      style: bodySmall,
                    ),
                  ],
                );
              }(),
            ),
            PopupMenuItem(
              onTap: () {
                if (isLoading) {
                  return;
                }

                markdownFlutterPageStateGeneralFramework.handleFunction(
                    onFunction: (context, statefulWidget) async {
                  final LanguageGeneralFrameworkController
                      languageGeneralFrameworkController =
                      LanguageGeneralFrameworkController(
                    countryCodeId: markdownFlutterPageStateGeneralFramework
                        .markdownFlutterContentGeneralFramework
                        .languageCodeId,
                    languageSupports: [],
                  );
                  await LanguageGeneralFramework.show(
                    context: context,
                    languageGeneralFrameworkOptions:
                        LanguageGeneralFrameworkOptions(
                      applicationIcon: null,
                      applicationTitle: "",
                      isApplicationFullScreen: false,
                      generalLibFlutterApp:
                          markdownFlutterPageStateGeneralFramework
                              .widget.generalLibFlutterApp,
                      languageGeneralFrameworkType:
                          LanguageGeneralFrameworkType.dialog,
                      onSelect: (context, languageCodeDataDetail) async {
                        if (markdownFlutterPageStateGeneralFramework
                                .markdownFlutterContentGeneralFramework
                                .languageCodeId ==
                            languageCodeDataDetail.code) {
                          context.navigator().pop();

                          return;
                        }
                        final LoadingGeneralFrameworkController
                            loadingGeneralFrameworkController =
                            LoadingGeneralFrameworkController(
                          loadingText: "Translating",
                        );
                        LoadingGeneralFramework.show(
                          context: context,
                          loadingGeneralFrameworkController:
                              loadingGeneralFrameworkController,
                        );
                        loadingGeneralFrameworkController.update(
                            loadingText:
                                "Translating Title to ${languageCodeDataDetail.flag} ${languageCodeDataDetail.name}");
                        final title_translate =
                            await TranslateClient.translate(
                          text: markdownFlutterPageStateGeneralFramework
                              .markdownFlutterContentGeneralFramework.content,
                          toLanguageCode: languageCodeDataDetail.code ?? "",
                          ignoreError: true,
                        );
                        loadingGeneralFrameworkController.update(
                            loadingText:
                                "Translating Content to ${languageCodeDataDetail.flag} ${languageCodeDataDetail.name}");

                        final content_translate =
                            await TranslateClient.translate(
                          text: markdownFlutterPageStateGeneralFramework
                              .markdownFlutterContentGeneralFramework.content,
                          toLanguageCode: languageCodeDataDetail.code ?? "",
                          ignoreError: true,
                        );
                        loadingGeneralFrameworkController.update(
                            loadingText:
                                "Finished Translate to ${languageCodeDataDetail.flag} ${languageCodeDataDetail.name}");

                        markdownFlutterPageStateGeneralFramework
                                .markdownFlutterContentGeneralFramework =
                            MarkdownFlutterContentGeneralFramework(
                          title: title_translate,
                          content: content_translate,
                          languageCodeId: languageCodeDataDetail.code ?? "",
                        );
                        context.navigator().pop();
                        context.navigator().pop();
                        markdownFlutterPageStateGeneralFramework
                            .setStateWithIgnoreError(
                          fn: () {},
                        );
                      },
                      languageGeneralFrameworkController:
                          languageGeneralFrameworkController,
                    ),
                  );
                  languageGeneralFrameworkController.dispose();
                });
              },
              child: () {
                if (isLoading) {
                  return CircularProgressIndicator(
                    color: context.theme.indicatorColor,
                  );
                }
                return Row(
                  children: [
                    IconButton(
                        onPressed: null,
                        icon: Icon(
                          Icons.translate,
                          color: context.theme.indicatorColor,
                        )),
                    Text(
                      "Translate",
                      style: bodySmall,
                    ),
                  ],
                );
              }(),
            ),
            ...markdownFlutterPageStateGeneralFramework.widget
                .markdownFlutterPopupMenuItemsGeneralFrameworkBuilder(context,
                    markdownFlutterPageStateGeneralFramework, bodySmall),
          ];
        },
      ),
    ],
  );
}