openFontScaleBottomSheet method

void openFontScaleBottomSheet()

Displays a range slider for adjusting the line width of the painting tool.

This method shows a range slider in a modal bottom sheet for adjusting the line width of the painting tool.

Implementation

void openFontScaleBottomSheet() {
  final presetFontScale = fontScale;
  showModalBottomSheet(
    context: context,
    backgroundColor:
        imageEditorTheme.paintingEditor.lineWidthBottomSheetColor,
    builder: (BuildContext context) {
      return Material(
        color: Colors.transparent,
        textStyle: platformTextStyle(context, designMode),
        child: SingleChildScrollView(
          physics: const ClampingScrollPhysics(),
          child: Padding(
            padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
            child: StatefulBuilder(builder: (context, setState) {
              void updateFontScaleScale(double value) {
                fontScale = (value * 10).ceilToDouble() / 10;
                setState(() {});
                textEditorCallbacks?.handleFontScaleChanged(value);
                this.setState(() {});
              }

              return Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.stretch,
                children: [
                  BottomSheetHeaderRow(
                    title: '${i18n.textEditor.fontScale} ${fontScale}x',
                    theme: widget.theme,
                  ),
                  Row(
                    children: [
                      Expanded(
                        child: Slider.adaptive(
                          max: textEditorConfigs.maxFontScale,
                          min: textEditorConfigs.minFontScale,
                          divisions: (textEditorConfigs.maxFontScale -
                                  textEditorConfigs.minFontScale) ~/
                              0.1,
                          value: fontScale,
                          onChanged: updateFontScaleScale,
                        ),
                      ),
                      const SizedBox(width: 8),
                      IconTheme(
                        data: Theme.of(context).primaryIconTheme,
                        child: AnimatedSwitcher(
                          duration: const Duration(milliseconds: 150),
                          child: fontScale != presetFontScale
                              ? IconButton(
                                  onPressed: () {
                                    updateFontScaleScale(presetFontScale);
                                  },
                                  icon: Icon(icons.textEditor.resetFontScale),
                                )
                              : IconButton(
                                  key: UniqueKey(),
                                  color: Colors.transparent,
                                  onPressed: null,
                                  icon: Icon(icons.textEditor.resetFontScale),
                                ),
                        ),
                      ),
                      const SizedBox(width: 2),
                    ],
                  ),
                ],
              );
            }),
          ),
        ),
      );
    },
  );
}