Clean up code

This commit is contained in:
2025-03-19 00:45:46 +01:00
parent 40d251f400
commit d00c20397f
7 changed files with 209 additions and 971 deletions

View File

@@ -22,8 +22,8 @@ class HtmlTooltip extends StatefulWidget {
super.key,
required this.child,
required this.content,
this.maxWidth = 300.0,
this.maxHeight = 400.0,
this.maxWidth = 800.0,
this.maxHeight = 800.0,
this.padding = const EdgeInsets.all(8.0),
this.showDuration = const Duration(milliseconds: 0),
this.fadeDuration = const Duration(milliseconds: 200),
@@ -45,7 +45,7 @@ class _HtmlTooltipState extends State<HtmlTooltip> {
bool _isMouseInside = false;
bool _isMouseInsideTooltip = false;
final ScrollController _scrollController = ScrollController();
@override
void dispose() {
_scrollController.dispose();
@@ -56,7 +56,7 @@ class _HtmlTooltipState extends State<HtmlTooltip> {
// Launch a URL
Future<void> _launchUrl(String? urlString) async {
if (urlString == null || urlString.isEmpty) return;
final Uri url = Uri.parse(urlString);
try {
if (await canLaunchUrl(url)) {
@@ -69,20 +69,14 @@ class _HtmlTooltipState extends State<HtmlTooltip> {
void _showTooltip(BuildContext context) {
if (_overlayEntry != null) return;
// Get render box of the trigger widget
final RenderBox box = context.findRenderObject() as RenderBox;
final Size childSize = box.size;
// Calculate appropriate width and position
final screenWidth = MediaQuery.of(context).size.width;
double tooltipWidth = widget.maxWidth;
// Adjust tooltip width for longer descriptions
if (widget.content.length > 1000) {
tooltipWidth = math.min(screenWidth * 0.5, 500.0);
}
// Use the specified maxWidth without adjusting based on content length
final double tooltipWidth = widget.maxWidth;
_overlayEntry = OverlayEntry(
builder: (context) {
return Positioned(
@@ -125,7 +119,9 @@ class _HtmlTooltipState extends State<HtmlTooltip> {
borderRadius: widget.borderRadius,
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(77), // Equivalent to 0.3 opacity
color: Colors.black.withAlpha(
77,
), // Equivalent to 0.3 opacity
blurRadius: 10.0,
spreadRadius: 0.0,
),
@@ -140,7 +136,10 @@ class _HtmlTooltipState extends State<HtmlTooltip> {
// Header
Container(
color: const Color(0xFF3D4A59),
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 8.0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
@@ -161,7 +160,9 @@ class _HtmlTooltipState extends State<HtmlTooltip> {
if (_scrollController.hasClients) {
_scrollController.animateTo(
0.0,
duration: const Duration(milliseconds: 300),
duration: const Duration(
milliseconds: 300,
),
curve: Curves.easeOut,
);
}
@@ -195,7 +196,7 @@ class _HtmlTooltipState extends State<HtmlTooltip> {
],
),
),
// Content
Flexible(
child: SingleChildScrollView(
@@ -216,10 +217,14 @@ class _HtmlTooltipState extends State<HtmlTooltip> {
textDecoration: TextDecoration.underline,
),
"blockquote": Style(
backgroundColor: Colors.grey.withAlpha(26), // Approx 0.1 opacity
backgroundColor: Colors.grey.withAlpha(
26,
), // Approx 0.1 opacity
border: Border(
left: BorderSide(
color: Colors.grey.withAlpha(128), // Approx 0.5 opacity
color: Colors.grey.withAlpha(
128,
), // Approx 0.5 opacity
width: 4.0,
),
),
@@ -227,28 +232,41 @@ class _HtmlTooltipState extends State<HtmlTooltip> {
margin: Margins.only(left: 0, right: 0),
),
"code": Style(
backgroundColor: Colors.grey.withAlpha(51), // Approx 0.2 opacity
backgroundColor: Colors.grey.withAlpha(
51,
), // Approx 0.2 opacity
padding: HtmlPaddings.all(2.0),
fontFamily: 'monospace',
),
"pre": Style(
backgroundColor: Colors.grey.withAlpha(51), // Approx 0.2 opacity
backgroundColor: Colors.grey.withAlpha(
51,
), // Approx 0.2 opacity
padding: HtmlPaddings.all(8.0),
fontFamily: 'monospace',
margin: Margins.only(bottom: 8.0, top: 8.0),
margin: Margins.only(
bottom: 8.0,
top: 8.0,
),
),
"table": Style(
border: Border.all(color: Colors.grey),
backgroundColor: Colors.transparent,
),
"td": Style(
border: Border.all(color: Colors.grey.withAlpha(128)), // Approx 0.5 opacity
border: Border.all(
color: Colors.grey.withAlpha(128),
), // Approx 0.5 opacity
padding: HtmlPaddings.all(4.0),
),
"th": Style(
border: Border.all(color: Colors.grey.withAlpha(128)), // Approx 0.5 opacity
border: Border.all(
color: Colors.grey.withAlpha(128),
), // Approx 0.5 opacity
padding: HtmlPaddings.all(4.0),
backgroundColor: Colors.grey.withAlpha(51), // Approx 0.2 opacity
backgroundColor: Colors.grey.withAlpha(
51,
), // Approx 0.2 opacity
),
},
onAnchorTap: (url, _, __) {
@@ -324,4 +342,4 @@ class _HtmlTooltipState extends State<HtmlTooltip> {
),
);
}
}
}