Line data Source code
1 : // Copyright 2023 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'package:app_finance/_classes/herald/app_design.dart';
5 : import 'package:app_finance/_configs/theme_helper.dart';
6 : import 'package:material_ui/material_ui.dart';
7 :
8 : class TextWrapper extends StatelessWidget {
9 : final String text;
10 : final TextStyle? style;
11 : final int maxLines;
12 : final String tooltip;
13 : final double? maxWidth;
14 :
15 6 : const TextWrapper(
16 : this.text, {
17 : super.key,
18 : String? tooltip,
19 : this.maxWidth,
20 : this.style = const TextStyle(),
21 : this.maxLines = 1,
22 : }) : tooltip = tooltip ?? text;
23 :
24 6 : @override
25 : Widget build(BuildContext context) {
26 6 : return LayoutBuilder(
27 6 : builder: (context, constraints) {
28 12 : final width = maxWidth ?? constraints.maxWidth;
29 18 : if (ThemeHelper.isTextExceedWidth(text, style, width)) {
30 0 : return SizedBox(
31 : width: width,
32 0 : child: Tooltip(
33 0 : message: tooltip,
34 0 : child: Text(
35 0 : text,
36 0 : style: style,
37 0 : maxLines: maxLines,
38 : overflow: TextOverflow.ellipsis,
39 0 : textDirection: AppDesign.getAlignment<TextDirection>(),
40 : ),
41 : ),
42 : );
43 : } else {
44 6 : return Text(
45 6 : text,
46 6 : style: style,
47 6 : maxLines: maxLines,
48 : overflow: TextOverflow.ellipsis,
49 6 : textDirection: AppDesign.getAlignment<TextDirection>(),
50 : );
51 : }
52 : },
53 : );
54 : }
55 : }
|