搜索插件、代码仓与 APP 分类

GitHub 代码仓baderouaich/flutter_syntax_view

flutter_syntax_view

Flutter 语法高亮

flutter_syntax_view 项目封面
星标
103
复刻
30
最近推送(UTC)
2025年3月9日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

flutter_syntax_view

Flutter Syntax Highlighter

Basic Usage

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  final String code = """
// Importing core libraries
import 'dart:math';
int fibonacci(int n) {
  if (n == 0 || n == 1) return n;
  return fibonacci(n - 1) + fibonacci(n - 2);
}          
final int result = fibonacci(20);
/* and there 
    you have it! */
""";

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SyntaxView(
            code: code, // Code text
            syntax: Syntax.DART, // Language
            syntaxTheme: SyntaxTheme.vscodeDark(), // Theme
            fontSize: 12.0, // Font size
            withZoom: true, // Enable/Disable zoom icon controls
            withLinesCount: true, // Enable/Disable line number
            expanded: false, // Enable/Disable container expansion
            selectable: true // Enable/Disable code text selection
            ),
      ),
    );
  }
}

Create a Custom SyntaxTheme

class AppColors{

  static const Color backgroundColor = Color(0xff1A1A19);
  static const Color linesCountColor = Color(0xffEFE9D5);
  static const Color commentStyle    = Color(0xffEEDF7A);
  static const Color zoomIconColor   = Color(0xff77CDFF);
  static const Color stringStyle     = Color(0xffF87A53);
  static const Color baseStyle       = Color(0xffF5F5F5);
  static const Color keywordStyle    = Color(0xffCAE0BC);
  static const Color classStyle      = Color(0xffB9E5E8);

}

class HomePage extends StatelessWidget {
   HomePage({super.key});

 static const String code = r"""
import 'dart:math' as math;

// Coffee class is the best!
class Coffee {
  late int _temperature;

  void heat() => _temperature = 100;
  void chill() => _temperature = -5;

  void sip() {
    final bool isTooHot = math.max(37, _temperature) > 37;
    if (isTooHot)
      print("myyy liiips!");
    else
      print("mmmmm refreshing!");
  }

  int? get temperature => temperature;
}
void main() {
  var coffee = Coffee();
  coffee.heat();
  coffee.sip();
  coffee.chill();
  coffee.sip();
}
/* And there
        you have it */""";


  final SyntaxTheme myCustomTheme = SyntaxTheme.standard().copyWith(
    backgroundColor : AppColors.backgroundColor,
    linesCountColor : AppColors.linesCountColor,
    commentStyle    : const TextStyle(color: AppColors.commentStyle),
    zoomIconColor   : AppColors.zoomIconColor,
    stringStyle     :  const TextStyle(color: AppColors.stringStyle),
    baseStyle       : const TextStyle(color: AppColors.baseStyle),
    keywordStyle    :  const TextStyle(color: AppColors.keywordStyle),
    punctuationStyle:  const TextStyle(color: AppColors.keywordStyle),
    classStyle      :  const TextStyle(color: AppColors.classStyle),
  );

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: SyntaxView(
            code: code, // Code text
            syntax: Syntax.DART, // Language
            syntaxTheme: myCustomTheme, // Theme
            fontSize: 12.0, // Font size
            withZoom: true, // Enable/Disable zoom icon controls
            withLinesCount: true, // Enable/Disable line number
            expanded: false, // Enable/Disable container expansion
            selectable: true // Enable/Disable code text selection
          ),
      ),
    );
  }
}

Supported Syntax

  • [x] Dart
  • [x] C
  • [x] C++
  • [x] Java
  • [x] Kotlin
  • [x] Swift
  • [x] JavaScript
  • [x] YAML
  • [x] Rust
  • [x] Lua
  • [x] Python

Themes

Installing

Package

Contributing

  • if you are familiar with Regular Expressions in Dart and would like contribute in adding further syntax support. it will be very appreciated!

Contributors ✨

Thanks goes to these wonderful people!

Features and bugs

If you face any problems feel free to open an issue at the issue tracker. If you feel the library is missing a feature, please raise a ticket on Github. Pull request are also welcome.

Bader GitHub avatar
GitHub 作者

Bader ↗

语言DartC++CMakeSwiftCHTMLJavaObjective-C

分类

此仓库发布的插件

使用的依赖

依赖清单 3 项

  • flutter{"sdk":"flutter"}
  • string_scanner^1.1.0
  • flutter_test开发依赖{"sdk":"flutter"}

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗