You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
220 lines
6.5 KiB
220 lines
6.5 KiB
import 'package:flutter/material.dart';
|
|
import 'package:sonnat/core/extensions/number_extension.dart';
|
|
import 'package:sonnat/core/theme/app_colors.dart';
|
|
import 'package:sonnat/core/theme/app_theme.dart';
|
|
import 'package:sonnat/core/theme/reader_theme.dart';
|
|
import 'package:sonnat/core/utils/app_utils.dart';
|
|
import 'package:sonnat/core/widgets/custom_rich_text.dart';
|
|
|
|
class QHeaderTextShower extends StatelessWidget {
|
|
final String title;
|
|
final bool hasFullWidth;
|
|
final double fontSizeFactor;
|
|
final String? searchHighLight;
|
|
|
|
const QHeaderTextShower({
|
|
super.key,
|
|
required this.title,
|
|
this.hasFullWidth = true,
|
|
this.fontSizeFactor = 1,
|
|
this.searchHighLight,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
width: hasFullWidth ? 1.sw : null,
|
|
margin: Utils.instance.singleMargin(top: 7, bottom: 7),
|
|
child: Container(
|
|
padding: const EdgeInsets.all(8),
|
|
decoration: const BoxDecoration(
|
|
color: AppColors.ahkamBlue2,
|
|
borderRadius: BorderRadius.all(
|
|
Radius.circular(8),
|
|
),
|
|
),
|
|
child: HighlightRichText(
|
|
text: title.replaceAll(':', '').trim(),
|
|
highlight: searchHighLight,
|
|
style: AppTheme.instance.fontCreator(fontSizeFactor * 15, FontWeights.bold, AppColors.white),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class QAnswerShower extends StatelessWidget {
|
|
final String title;
|
|
final bool hasFullWidth;
|
|
final ReaderTheme? theme;
|
|
|
|
final double fontSizeFactor;
|
|
final String? searchHighLight;
|
|
|
|
const QAnswerShower({
|
|
super.key,
|
|
required this.title,
|
|
this.hasFullWidth = true,
|
|
this.theme = ReaderTheme.light,
|
|
this.fontSizeFactor = 1,
|
|
this.searchHighLight,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
width: hasFullWidth ? 1.sw : null,
|
|
margin: Utils.instance.singleMargin(bottom: 7),
|
|
child: Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
boxShadow: [
|
|
BoxShadow(
|
|
offset: Offset(0.w, 3.h),
|
|
blurRadius: 6,
|
|
color: AppColors.shadowHomeIcon,
|
|
),
|
|
],
|
|
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
|
),
|
|
child: HighlightRichText(
|
|
text: title.trim(),
|
|
highlight: searchHighLight,
|
|
style: AppTheme.instance.fontCreator(
|
|
fontSizeFactor * 15,
|
|
FontWeights.medium,
|
|
theme!.isDarkMode ? AppColors.darkModeGreyText : AppColors.ahkamBlue3,
|
|
),
|
|
textAlign: Directionality.of(context) == TextDirection.rtl ? TextAlign.right : TextAlign.left,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class QTextShower extends StatelessWidget {
|
|
final String title;
|
|
final bool hasFullWidth;
|
|
final ReaderTheme? theme;
|
|
final double fontSizeFactor;
|
|
final String? searchHighLight;
|
|
|
|
const QTextShower({
|
|
super.key,
|
|
required this.title,
|
|
this.hasFullWidth = true,
|
|
this.theme = ReaderTheme.light,
|
|
this.fontSizeFactor = 1,
|
|
this.searchHighLight,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizedBox(
|
|
width: hasFullWidth ? 1.sw : null,
|
|
child: Container(
|
|
decoration: const BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(8)),
|
|
),
|
|
child: HighlightRichText(
|
|
text: title.trim(),
|
|
highlight: searchHighLight,
|
|
style: AppTheme.instance.fontCreator(
|
|
fontSizeFactor * 15,
|
|
FontWeights.medium,
|
|
theme!.color.red,
|
|
),
|
|
textAlign: Directionality.of(context) == TextDirection.rtl ? TextAlign.right : TextAlign.left,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class THeaderTextShower extends StatelessWidget {
|
|
final String title;
|
|
final bool hasFullWidth;
|
|
final ReaderTheme? theme;
|
|
final double fontSizeFactor;
|
|
final String? searchHighLight;
|
|
|
|
const THeaderTextShower({
|
|
super.key,
|
|
required this.title,
|
|
this.hasFullWidth = true,
|
|
this.theme = ReaderTheme.light,
|
|
this.fontSizeFactor = 1,
|
|
this.searchHighLight,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizedBox(
|
|
width: hasFullWidth ? 1.sw : null,
|
|
child: Container(
|
|
decoration: const BoxDecoration(
|
|
borderRadius: BorderRadius.all(Radius.circular(8)),
|
|
),
|
|
child: HighlightRichText(
|
|
text: title.trim(),
|
|
highlight: searchHighLight,
|
|
style: AppTheme.instance.fontCreator(
|
|
fontSizeFactor * 18,
|
|
FontWeights.bold,
|
|
theme!.isDarkMode ? AppColors.white : AppColors.ahkamBlue3,
|
|
),
|
|
textAlign: Directionality.of(context) == TextDirection.rtl ? TextAlign.right : TextAlign.left,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
extension ReplaceTag on String {
|
|
String replaceTHeader() {
|
|
return replaceAllMapped(
|
|
RegExp(r'<([a-z]+)[^>]*t-header[^>]*>(?:(?:<([a-z]+)[^>]*>[^><]*<\/(\2)>)|\n|[^><])*?<\/(\1)>'), (match) {
|
|
String result = match.group(0) ?? '';
|
|
result = result.replaceFirst(match.group(4).toString(), 't_header');
|
|
result = result.replaceAll('${match.group(4)}>', 't_header>');
|
|
return result;
|
|
});
|
|
}
|
|
|
|
String replaceQHeader() {
|
|
return replaceAllMapped(
|
|
RegExp(r'<([a-z]+)[^>]*q-header[^>]*>(?:(?:<([a-z]+)[^>]*>[^><]*<\/(\2)>)|\n|[^><])*?<\/(\1)>'), (match) {
|
|
String result = match.group(0) ?? '';
|
|
result = result.replaceFirst(match.group(4).toString(), 'q_header');
|
|
result = result.replaceAll('${match.group(4)}>', 'q_header>');
|
|
return result;
|
|
});
|
|
}
|
|
|
|
String replaceQText() {
|
|
return replaceAllMapped(
|
|
RegExp(r'<([a-z]+)[^>]*q-text[^>]*>(?:(?:<([a-z]+)[^>]*>[^><]*<\/(\2)>)|\n|[^><])*?<\/(\1)>'), (match) {
|
|
String result = match.group(0) ?? '';
|
|
result = result.replaceFirst(match.group(4).toString(), 'q_text');
|
|
result = result.replaceAll('${match.group(4)}>', 'q_text>');
|
|
return result;
|
|
});
|
|
}
|
|
|
|
String replaceQAnswer() {
|
|
return replaceAllMapped(
|
|
RegExp(r'<([a-z]+)[^>]*q-answer[^>]*>(?:(?:<([a-z]+)[^>]*>[^><]*<\/(\2)>)|\n|[^><])*?<\/(\1)>'), (match) {
|
|
String result = match.group(0) ?? '';
|
|
result = result.replaceFirst(match.group(4).toString(), 'q_answer');
|
|
result = result.replaceAll('${match.group(4)}>', 'q_answer>');
|
|
return result;
|
|
});
|
|
}
|
|
|
|
String replaceTextStyle() {
|
|
return replaceAll(RegExp(r'font-size: ?\d{1,2}px;'), '')
|
|
.replaceAll(RegExp(r'font-weight: ?[^;]*;'), '')
|
|
.replaceAll(RegExp(r'font-family: ?"[^/"]*"'), '');
|
|
}
|
|
}
|