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:flutter/material.dart'; 7 : 8 : class TextWrapper extends StatelessWidget { 9 : final String text; 10 : final TextStyle? style; 11 : final int maxLines; 12 : final String tooltip; 13 : 14 0 : const TextWrapper( 15 : this.text, { 16 : super.key, 17 : String? tooltip, 18 : this.style = const TextStyle(), 19 : this.maxLines = 1, 20 : }) : tooltip = tooltip ?? text; 21 : 22 0 : @override 23 : Widget build(BuildContext context) { 24 0 : return LayoutBuilder( 25 0 : builder: (context, constraints) { 26 0 : if (ThemeHelper.isTextExceedWidth(text, style, constraints.maxWidth)) { 27 0 : return Tooltip( 28 0 : message: tooltip, 29 0 : child: Text( 30 0 : text, 31 0 : style: style, 32 0 : maxLines: maxLines, 33 : overflow: TextOverflow.ellipsis, 34 0 : textDirection: AppDesign.getAlignment<TextDirection>(), 35 : ), 36 : ); 37 : } else { 38 0 : return Text( 39 0 : text, 40 0 : style: style, 41 0 : maxLines: maxLines, 42 : overflow: TextOverflow.ellipsis, 43 0 : textDirection: AppDesign.getAlignment<TextDirection>(), 44 : ); 45 : } 46 : }, 47 : ); 48 : } 49 : }