akvelon / flutter-code-editor

Flutter Code Editor is a multi-platform code editor supporting syntax highlighting, code blocks folding, autocompletion, read-only code blocks, hiding specific code blocks, themes, and more.
https://akvelon.com
Apache License 2.0
197 stars 47 forks source link

Unable to change font family #237

Closed MrCyjaneK closed 1 year ago

MrCyjaneK commented 1 year ago

I've created a simple function to change all styles to use RobotoMono font in my app:

Map<String, TextStyle> getRobotoMonoFonts(Map<String, TextStyle> theme) {
  final Map<String, TextStyle> ret = {};
  for (var key in theme.keys) {
    ret[key] = theme[key]!.copyWith(fontFamily: "RobotoMono");
  }
  return ret;
}

and I call it in the following way:

CodeTheme(
  data: CodeThemeData(
    styles: getRobotoMonoFonts(monokaiSublimeTheme),
  ),
  child: SingleChildScrollView(
    child: CodeField(
      controller: codeCtrl,
    ),
  ),
),

obraz

But not every part of code is being updated to monospace. I've also tried manually editing these fields in CodeThemeData: commentStyle, functionStyle, keywordStyle, paramsStyle, quoteStyle, titleStyle, variableStyle but also without any success on getting the full code to switch to RobotoMono.

yescorp commented 1 year ago

Hello, @MrCyjaneK Please, try to pass a textStyle parameter to the CodeField and specify the fontFamily there.

CodeField(
  textStyle: const TextStyle(
    fontFamily: 'RobotoMono',
    fontSize: 12,
  ),
)

The text inside of a CodeField mainly has the style, passed to its constructor. Styles from CodeThemeData only override the styles for specific text, like comments, keywords, etc.

MrCyjaneK commented 1 year ago

that.. that solved all my issues. Thanks.