forked from fossasia/magic-epaper-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_text_overlay_dialog.dart
More file actions
77 lines (75 loc) · 2.16 KB
/
add_text_overlay_dialog.dart
File metadata and controls
77 lines (75 loc) · 2.16 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
import 'package:flutter/material.dart';
import 'package:magic_epaper_app/draw_canvas/models/overlay_item.dart';
Widget buildTextOverlayDialog({
required BuildContext context,
required Color selectedColor,
required void Function(OverlayItem) onItemCreated,
}) {
TextEditingController controller = TextEditingController();
double selectedFontSize = 24;
String selectedFont = 'Roboto';
List<String> fontOptions = [
'Roboto',
'Open Sans',
'Lato',
'Montserrat',
'Oswald'
];
return StatefulBuilder(
builder: (context, setDialogState) => AlertDialog(
title: Text("Enter Text"),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(controller: controller),
const SizedBox(height: 10),
DropdownButton<String>(
value: selectedFont,
onChanged: (value) => setDialogState(() => selectedFont = value!),
items: fontOptions.map((font) {
return DropdownMenuItem(
value: font,
child: Text(font, style: TextStyle(fontFamily: font)),
);
}).toList(),
),
const SizedBox(height: 10),
Row(
children: [
Text("Font size: ${selectedFontSize.toInt()}"),
Expanded(
child: Slider(
value: selectedFontSize,
min: 12,
max: 48,
divisions: 12,
onChanged: (value) =>
setDialogState(() => selectedFontSize = value),
),
),
],
),
],
),
actions: [
TextButton(
onPressed: () {
final text = controller.text;
Navigator.pop(context);
if (text.isNotEmpty) {
onItemCreated(
OverlayItem.text(
text: text,
color: selectedColor,
font: selectedFont,
fontSize: selectedFontSize,
),
);
}
},
child: Text("Add"),
),
],
),
);
}