Search packages, repositories and app categories

Package detailsv0.1.1

syntax_highlighter

syntax highlighter for show your dart code in the application.

30-day downloads
1.2K
Likes
19
Pub points
40

Install package

flutter pub add syntax_highlighter

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

A Flutter package that provides syntax highlighting for Dart code within applications. It enables developers to display formatted, color-coded Dart code snippets with proper indentation and keyword recognition. Designed for use in documentation, tutorials, or code-sharing features, it enhances readability and visual appeal. The package integrates seamlessly into Flutter widgets and supports custom themes. It is lightweight and focused on rendering Dart code accurately.

Use cases

  • Displaying code examples in apps
  • Enhancing documentation UIs
  • Creating interactive coding tutorials
  • Showcasing code snippets in blogs
  • Building developer tooling interfaces

Key features

  • Dart-specific syntax highlighting
  • Customizable themes
  • Lightweight and easy integration
  • Supports code formatting and indentation
  • Built for Flutter widgets

Suitable for

  • Flutter apps with code displays
  • Educational or tutorial apps
  • Developer-facing dashboards
  • Documentation platforms
  • Code sharing features

Considerations

  • Limited to Dart language only
  • No support for other programming languages
  • Requires manual code input or loading
  • Not designed for full IDE-like editing
  • No built-in line numbering or copy functionality

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

syntax_highlighter

syntax highlighter for show your code in the app

How to Use It

Step 2

add your code in your file

String _exampleCode =
      "class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key); final String title; @override _MyHomePageState createState() => _MyHomePageState();}";
Step 2

add SyntaxHighlighterStyle in your build method

final SyntaxHighlighterStyle style =
        Theme.of(context).brightness == Brightness.dark
            ? SyntaxHighlighterStyle.darkThemeStyle()
            : SyntaxHighlighterStyle.lightThemeStyle();
Step 3

add this code

            RichText(
              text: TextSpan(
                style: const TextStyle(fontFamily: 'monospace', fontSize: 10.0),
                children: <TextSpan>[
                  DartSyntaxHighlighter(style).format(_exampleCode),
                ],
              ),

Full Example

check Full Example code in example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:syntax_highlighter/syntax_highlighter.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Syntax Highlighter Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyHomePage(title: 'Syntax Highlighter Example'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);
  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String _exampleCode =
      "class MyHomePage extends StatefulWidget { MyHomePage({Key key, this.title}) : super(key: key); final String title; @override _MyHomePageState createState() => _MyHomePageState();}";

  @override
  Widget build(BuildContext context) {
    final SyntaxHighlighterStyle style =
        Theme.of(context).brightness == Brightness.dark
            ? SyntaxHighlighterStyle.darkThemeStyle()
            : SyntaxHighlighterStyle.lightThemeStyle();
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: SingleChildScrollView(
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: RichText(
              text: TextSpan(
                style: const TextStyle(fontFamily: 'monospace', fontSize: 10.0),
                children: <TextSpan>[
                  DartSyntaxHighlighter(style).format(_exampleCode),
                ],
              ),
            ),
          ),
        ));
  }
}

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package

No data available yet.