パッケージ、リポジトリ、アプリカテゴリを検索

flutter_syntax_view のカバー
パッケージ詳細v4.1.7

flutter_syntax_view

ネイティブなDartコードを使用して、プログラミング言語の構文に従ってコードテキストを強調表示する静的構文ハイライター・ウィジェットです。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
1.1万
いいね数
101
Pub ポイント
150

パッケージをインストール

flutter pub add flutter_syntax_view

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

純粋なDart実装を使用してコードスニペットの構文強調を提供するFlutterウィジェットです。複数のプログラミング言語をサポートし、外部依存関係に頼らず効率的にハイライトテキストをレンダリングします。Flutterアプリ内のドキュメント、チュートリアル、または開発ツールでコードを表示するのに最適です。このウィジェットは軽量であり、モバイル、Web、デスクトップを含むすべての主要プラットフォームで互換性があります。

用途

  • アプリでコード例を表示する
  • ドキュメント内の構文を強調表示する
  • コードエディタコンポーネントの構築
  • コードスニペット付きの教育アプリ
  • プログラミングチュートリアルの紹介

主な機能

  • 純粋な Dart 実装
  • 複数のプログラミング言語をサポートしています
  • クロスプラットフォーム互換性
  • 軽量で効率的
  • ネイティブな依存関係なし
  • カスタマイズ可能なテーマ

適している対象

  • 教育アプリを開発する開発者
  • ドキュメンテーションとチュートリアルアプリ
  • コード共有プラットフォーム
  • 内部開発者ツール
  • 構文ハイライト付きコードを必要とするUI

注意事項

  • 静的テキスト(編集不可)に制限
  • リアルタイム編集をサポートしていません
  • テーマのカスタマイズには手動での設定が必要です
  • 非常に大きなコードブロックではパフォーマンスが異なる場合があります

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

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.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

このパッケージを使用しているプロジェクト