From 210fcbf6f53516ea0efa52028b181d30b7e9a2d3 Mon Sep 17 00:00:00 2001 From: peron Date: Tue, 20 Feb 2024 20:22:23 +0000 Subject: [PATCH] feat: use custom code block --- lib/widgets/message_tile.dart | 40 ++++++++++++++++++----------------- pubspec.lock | 22 +++++++++---------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/lib/widgets/message_tile.dart b/lib/widgets/message_tile.dart index 715c610..574c148 100644 --- a/lib/widgets/message_tile.dart +++ b/lib/widgets/message_tile.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; +import 'package:flutter_highlighter/flutter_highlighter.dart'; import 'package:flutter_highlighter/themes/atom-one-dark.dart'; import 'package:get/get.dart'; import 'package:google_fonts/google_fonts.dart'; @@ -117,22 +118,14 @@ class MessageTile extends StatelessWidget { inlineSyntaxList: [LatexSyntax()], generators: [latexGenerator]), config: MarkdownConfig(configs: [ PreConfig( - margin: const EdgeInsets.all(0), - decoration: const BoxDecoration( - color: Color(0xff282c34), - borderRadius: - BorderRadius.vertical(bottom: Radius.circular(8.0))), - theme: atomOneDarkTheme, - textStyle: GoogleFonts.robotoMono(), - styleNotMatched: GoogleFonts.robotoMono(), - wrapper: (child, code, language) => Column( - children: [ - Container( - decoration: BoxDecoration( - color: Colors.grey[900], - borderRadius: const BorderRadius.vertical( - top: Radius.circular(8.0))), - child: Padding( + builder: (code, language) => Container( + decoration: BoxDecoration( + color: Colors.grey[900], + borderRadius: BorderRadius.circular(8)), + clipBehavior: Clip.antiAlias, + child: Column( + children: [ + Padding( padding: const EdgeInsets.only(left: 16), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, @@ -148,9 +141,18 @@ class MessageTile extends StatelessWidget { ], ), ), - ), - child - ], + SizedBox( + width: double.infinity, + child: HighlightView( + code, + language: language, + theme: atomOneDarkTheme, + textStyle: GoogleFonts.robotoMono(), + tabSize: 4, + padding: const EdgeInsets.fromLTRB(16, 16, 16, 0), + )) + ], + ), ), ), CodeConfig(style: GoogleFonts.robotoMono()), diff --git a/pubspec.lock b/pubspec.lock index 9328d69..ee4e439 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -261,26 +261,26 @@ packages: dependency: transitive description: name: leak_tracker - sha256: "78eb209deea09858f5269f5a5b02be4049535f568c07b275096836f01ea323fa" + sha256: cdd14e3836065a1f6302a236ec8b5f700695c803c57ae11a1c84df31e6bcf831 url: "https://pub.dev" source: hosted - version: "10.0.0" + version: "10.0.3" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: b46c5e37c19120a8a01918cfaf293547f47269f7cb4b0058f21531c2465d6ef0 + sha256: "9b2ef90589911d665277464e0482b209d39882dffaaf4ef69a3561a3354b2ebc" url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.2" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: a597f72a664dbd293f3bfc51f9ba69816f84dcd403cdac7066cb3f6003f3ab47 + sha256: fd3cd66cb2bcd7b50dcd3b413af49d78051f809c8b3f6e047962765c15a0d23d url: "https://pub.dev" source: hosted - version: "2.0.1" + version: "3.0.0" lints: dependency: transitive description: @@ -539,10 +539,10 @@ packages: dependency: transitive description: name: test_api - sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b" + sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f" url: "https://pub.dev" source: hosted - version: "0.6.1" + version: "0.7.0" tuple: dependency: transitive description: @@ -675,10 +675,10 @@ packages: dependency: transitive description: name: vm_service - sha256: b3d56ff4341b8f182b96aceb2fa20e3dcb336b9f867bc0eafc0de10f1048e957 + sha256: a2662fb1f114f4296cf3f5a50786a2d888268d7776cf681aa17d660ffa23b246 url: "https://pub.dev" source: hosted - version: "13.0.0" + version: "14.0.0" web: dependency: transitive description: @@ -713,4 +713,4 @@ packages: version: "6.5.0" sdks: dart: ">=3.3.0-279.1.beta <4.0.0" - flutter: ">=3.16.0" + flutter: ">=3.18.0-18.0.pre.54"