email_text.dart
4.22 KB
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
import 'dart:ui' as ui show PlaceholderAlignment;
import 'package:extended_text_library/extended_text_library.dart';
import 'package:flutter/material.dart';
class EmailText extends SpecialText {
EmailText(TextStyle? textStyle, SpecialTextGestureTapCallback? onTap,
{this.start, this.controller, this.context, required String startFlag})
: super(startFlag, ' ', textStyle, onTap: onTap);
final TextEditingController? controller;
final int? start;
final BuildContext? context;
@override
bool isEnd(String value) {
final int index = value.indexOf('@');
final int index1 = value.indexOf('.');
return index >= 0 &&
index1 >= 0 &&
index1 > index + 1 &&
super.isEnd(value);
}
@override
InlineSpan finishText() {
final String text = toString();
return ExtendedWidgetSpan(
actualText: text,
start: start!,
alignment: ui.PlaceholderAlignment.middle,
child: GestureDetector(
child: Padding(
padding: const EdgeInsets.only(right: 5.0, top: 2.0, bottom: 2.0),
child: ClipRRect(
borderRadius: const BorderRadius.all(Radius.circular(5.0)),
child: Container(
padding: const EdgeInsets.all(5.0),
color: Colors.orange,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
text.trim(),
//style: textStyle?.copyWith(color: Colors.orange),
),
const SizedBox(
width: 5.0,
),
InkWell(
child: const Icon(
Icons.close,
size: 15.0,
),
onTap: () {
controller!.value = controller!.value.copyWith(
text: controller!.text
.replaceRange(start!, start! + text.length, ''),
selection: TextSelection.fromPosition(
TextPosition(offset: start!)));
},
)
],
),
)),
),
onTap: () {
showDialog<void>(
context: context!,
barrierDismissible: true,
builder: (BuildContext c) {
final TextEditingController textEditingController =
TextEditingController()..text = text.trim();
return Column(
children: <Widget>[
Expanded(
child: Container(),
),
Material(
child: Padding(
padding: const EdgeInsets.all(10.0),
child: TextField(
controller: textEditingController,
decoration: InputDecoration(
suffixIcon: TextButton(
child: const Text('OK'),
onPressed: () {
controller!.value = controller!.value.copyWith(
text: controller!.text.replaceRange(
start!,
start! + text.length,
textEditingController.text + ' '),
selection: TextSelection.fromPosition(
TextPosition(
offset: start! +
(textEditingController.text + ' ')
.length)));
if (Navigator.canPop(context!)) {
Navigator.pop(context!);
}
},
)),
),
)),
Expanded(
child: Container(),
)
],
);
});
},
),
deleteAll: true,
);
}
}