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.

Home Page:https://akvelon.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to change font family

MrCyjaneK opened this issue · comments

commented

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.

commented

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.

commented

that.. that solved all my issues. Thanks.