-
Notifications
You must be signed in to change notification settings - Fork 69
/
Copy pathmain.dart
189 lines (183 loc) · 7.03 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_parsed_text/flutter_parsed_text.dart';
import 'package:url_launcher/url_launcher.dart' show canLaunch, launch;
main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'example_app',
home: MainApp(),
);
}
}
class MainApp extends StatefulWidget {
@override
_MainAppState createState() => _MainAppState();
}
class _MainAppState extends State<MainApp> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Column(
children: <Widget>[
SizedBox(
height: 40.0,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ParsedText(
selectable: true,
alignment: TextAlign.start,
// regexOptions: RegexOptions(
// caseSensitive: false,
// multiLine: true,
// dotAll: false,
// unicode: false,
// ),
text:
"[@michael:51515151] Hello --- spoiler ---\n\n spoiler content \n--- spoiler ---\n https://172.0.0.1 london this is https://apps.apple.com/id/app/facebook/id284882215 an example of the ParsedText, links like http://www.google.com or http://www.facebook.com are clickable and phone number 444-555-6666 can call too. But you can also do more with this package, for example Bob will change style and David too.\nAlso a US number example +1-(800)-831-1117. [email protected] And the magic number is 42! #flutter #flutterdev",
parse: <MatchText>[
MatchText(
type: ParsedType.EMAIL,
style: TextStyle(
color: Colors.red,
fontSize: 24,
),
onTap: (url) {
launch("mailto:" + url);
}),
MatchText(
type: ParsedType.URL,
style: TextStyle(
color: Colors.blue,
fontSize: 24,
),
onTap: (url) async {
var a = await canLaunch(url);
if (a) {
launch(url);
}
}),
MatchText(
type: ParsedType.PHONE,
style: TextStyle(
color: Colors.red,
fontSize: 24,
),
onTap: (url) {
launch("tel:" + url);
}),
MatchText(
type: ParsedType.CUSTOM,
pattern:
r"^(?:http|https):\/\/[\w\-_]+(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)",
style: TextStyle(color: Colors.lime),
onTap: (url) => print(url),
),
MatchText(
type: ParsedType.CUSTOM,
pattern:
"(---( )?(`)?spoiler(`)?( )?---)\n\n(.*?)\n( )?(---( )?(`)?spoiler(`)?( )?---)",
style: TextStyle(
color: Colors.purple,
fontSize: 50,
),
onTap: (url) {
launch("tel:" + url);
}),
MatchText(
pattern: r"\[(@[^:]+):([^\]]+)\]",
style: TextStyle(
color: Colors.green,
fontSize: 24,
),
renderText: ({required pattern, required str}) {
RegExp customRegExp = RegExp(r"\[(@[^:]+):([^\]]+)\]");
Match match = customRegExp.firstMatch(str)!;
print('test test: ${match[1]}');
// return Container(
// padding: EdgeInsets.all(5.0),
// color: Colors.amber,
// child: Text(match[1]!),
// );
//
return {'display': match[1]!};
},
onTap: (url) {
showDialog(
context: context,
builder: (BuildContext context) {
Map<String, String> map = Map<String, String>();
RegExp customRegExp = RegExp(r"\[(@[^:]+):([^\]]+)\]");
Match match = customRegExp.firstMatch(url)!;
// return object of type Dialog
return AlertDialog(
title: new Text("Mentions clicked"),
content: new Text("${match.group(1)!} clicked."),
actions: <Widget>[
// usually buttons at the bottom of the dialog
new FlatButton(
child: new Text("Close"),
onPressed: () {},
),
],
);
},
);
},
// onLongTap: (url) {
// print('long press');
// },
),
MatchText(
pattern: r"\B#+([\w]+)\b",
style: TextStyle(
color: Colors.pink,
fontSize: 24,
),
onTap: (url) async {
showDialog(
context: context,
builder: (BuildContext context) {
// return object of type Dialog
return AlertDialog(
title: new Text("Hashtag clicked"),
content: new Text("$url clicked."),
actions: <Widget>[
// usually buttons at the bottom of the dialog
new FlatButton(
child: new Text("Close"),
onPressed: () {},
),
],
);
},
);
},
// onLongTap: (url) {
// print('long press');
// },
),
MatchText(
pattern: r"lon",
style: TextStyle(
color: Colors.pink,
fontSize: 24,
),
onTap: (url) async {})
],
style: TextStyle(
fontSize: 24,
color: Colors.black,
),
),
)
],
),
);
}
}