Skip to content

A syntax highlighting package for Flutter, based on dart_prism.

License

Notifications You must be signed in to change notification settings

tagnote-app/flutter_prism

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A syntax highlighting package for Flutter, based on dart_prism.

Example

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

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    const code = '''
// Dart language
void main() {
    const message = "Hello World!";
    print(message);
}
''';
    final prism = Prism();
    final textSpans = prism.render(code, 'dart');

    return Scaffold(
      appBar: AppBar(
        title: const Text('dart_prism example'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(20),
        child: RichText(
          text: TextSpan(
            style: const TextStyle(
              color: Color(0xff06157D),
              height: 1.5,
              fontSize: 18,
              fontFamily: 'monospace',
            ),
            children: textSpans,
          ),
        ),
      ),
    );
  }
}

About

A syntax highlighting package for Flutter, based on dart_prism.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published