how to display programming code as colorful and correctly formatted in flutter

405 Views Asked by At

I want to display the content of this url in flutter application with code viewer, is that possible to do that? I am not talking about only dart code.

I tried to show it with flutter_markdown, and I think it is basic

1

There are 1 best solutions below

1
Christian Godoy On

you can use syntax_highlighter package.

dependencies:
  syntax_highlighter: ^1.0.0

import 'package:syntax_highlighter/syntax_highlighter.dart';

To display a block of code, use SyntaxHighlighter widget. You can specify the language of the code using the language parameter, and the actual code to be displayed using the text parameter. like example:

SyntaxHighlighter(
  language: 'dart',
  text: '''
void main() {
  print('Hello!');
}
''',
)