-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve: Update dialog is more informative now
- Loading branch information
Showing
2 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class AutoFormatText extends StatelessWidget { | ||
AutoFormatText({required this.text}); | ||
final String text; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final spans = <TextSpan>[]; | ||
|
||
final exp = RegExp(r'\*\*(.*?)\*\*'); | ||
final matches = exp.allMatches(text); | ||
|
||
var currentTextIndex = 0; | ||
|
||
for (final match in matches) { | ||
spans.add( | ||
TextSpan( | ||
text: text.substring(currentTextIndex, match.start), | ||
style: const TextStyle(fontSize: 16), | ||
), | ||
); | ||
|
||
spans.add( | ||
TextSpan( | ||
text: match.group(1), | ||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16), | ||
), | ||
); | ||
|
||
currentTextIndex = match.end; | ||
} | ||
|
||
spans.add( | ||
TextSpan( | ||
text: text.substring(currentTextIndex), | ||
style: const TextStyle(fontSize: 16), | ||
), | ||
); | ||
|
||
return RichText( | ||
textAlign: TextAlign.center, | ||
text: TextSpan(children: spans), | ||
); | ||
} | ||
} |