패키지, 저장소 및 앱 카테고리 검색

flutter_syntax_view 표지
패키지 상세v4.1.7

flutter_syntax_view

프로그래밍 언어 구문에 따라 코드 텍스트를 강조 표시하는 정적 구문 하이라이터 위젯으로, 네이티브 Dart 코드를 사용합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
1.1만
좋아요
101
Pub 점수
150

패키지 설치

flutter pub add flutter_syntax_view

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

순수한 Dart 구현을 사용하여 코드 스니펫에 대한 구문 강조를 제공하는 플러터 위젯입니다. 여러 프로그래밍 언어를 지원하며 외부 종속성 없이 효율적으로 하이라이트된 텍스트를 렌더링합니다. 플러터 앱 내 문서, 튜토리얼 또는 개발 도구에서 코드를 표시하는 데 이상적입니다. 이 위젯은 가볍고 모바일, 웹, 데스크톱을 포함한 모든 주요 플랫폼과 호환됩니다.

사용 사례

  • 앱에서 코드 예제 표시
  • 문서에서 구문 강조하기
  • 코드 편집기 컴포넌트 빌드
  • 코드 조각이 포함된 교육용 앱
  • 프로그래밍 튜토리얼 전시

주요 기능

  • 순수 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 개

소스 저장소

이 패키지를 사용하는 프로젝트