순수한 Dart 구현을 사용하여 코드 스니펫에 대한 구문 강조를 제공하는 플러터 위젯입니다. 여러 프로그래밍 언어를 지원하며 외부 종속성 없이 효율적으로 하이라이트된 텍스트를 렌더링합니다. 플러터 앱 내 문서, 튜토리얼 또는 개발 도구에서 코드를 표시하는 데 이상적입니다. 이 위젯은 가볍고 모바일, 웹, 데스크톱을 포함한 모든 주요 플랫폼과 호환됩니다.
사용 사례
앱에서 코드 예제 표시
문서에서 구문 강조하기
코드 편집기 컴포넌트 빌드
코드 조각이 포함된 교육용 앱
프로그래밍 튜토리얼 전시
주요 기능
순수 Dart 구현
여러 프로그래밍 언어를 지원합니다
크로스 플랫폼 호환성
경량이고 효율적
네이티브 종속성 없음
사용자 정의 테마
적합한 대상
교육용 앱을 개발하는 개발자
문서 및 튜토리얼 앱
코드 공유 플랫폼
내부 개발자 도구
구문 강조 코드가 필요한 UI
고려 사항
정적 텍스트(편집 불가)로 제한
실시간 편집을 지원하지 않습니다
테마 사용자 정의는 수동 구성이 필요합니다
매우 큰 코드 블록에서는 성능이 달라질 수 있습니다
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
flutter_syntax_view
Flutter Syntax Highlighter
Basic Usage
classHomePageextendsStatelessWidget{
constHomePage({super.key});
finalString 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! */
""";
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
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
classAppColors{
staticconstColor backgroundColor = Color(0xff1A1A19);
staticconstColor linesCountColor = Color(0xffEFE9D5);
staticconstColor commentStyle = Color(0xffEEDF7A);
staticconstColor zoomIconColor = Color(0xff77CDFF);
staticconstColor stringStyle = Color(0xffF87A53);
staticconstColor baseStyle = Color(0xffF5F5F5);
staticconstColor keywordStyle = Color(0xffCAE0BC);
staticconstColor classStyle = Color(0xffB9E5E8);
}
classHomePageextendsStatelessWidget{
HomePage({super.key});
staticconstString 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 */""";
finalSyntaxTheme myCustomTheme = SyntaxTheme.standard().copyWith(
backgroundColor : AppColors.backgroundColor,
linesCountColor : AppColors.linesCountColor,
commentStyle : constTextStyle(color: AppColors.commentStyle),
zoomIconColor : AppColors.zoomIconColor,
stringStyle : constTextStyle(color: AppColors.stringStyle),
baseStyle : constTextStyle(color: AppColors.baseStyle),
keywordStyle : constTextStyle(color: AppColors.keywordStyle),
punctuationStyle: constTextStyle(color: AppColors.keywordStyle),
classStyle : constTextStyle(color: AppColors.classStyle),
);
@overrideWidgetbuild(BuildContext context) {
returnScaffold(
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
),
),
);
}
}
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.