Skip to content

Commit beada5b

Browse files
author
gamerestrin217
committed
se añadio text to speech
1 parent 5908c67 commit beada5b

5 files changed

Lines changed: 45 additions & 14 deletions

File tree

blueprint.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,7 @@ This document outlines the design and features of a modern, intuitive note-takin
6161
- **Font Size & Style:** Users can adjust the font size and apply **bold** and *italic* styles to the note's content.
6262
- **Checklists:** Users can create interactive checklists directly within the note content.
6363
- **Live Preview:** All text style and checklist changes are reflected in real-time in the editor.
64+
65+
- **Text-to-Speech:**
66+
- **Implementation:** A new `volume_up` icon button is added to the `BottomAppBar` in the editor.
67+
- **Functionality:** When pressed, the app uses the `flutter_tts` package to read the note's title and content aloud.

lib/editor_screen.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
44
import 'package:flutter_quill/flutter_quill.dart' as quill;
55
import 'package:image_picker/image_picker.dart';
66
import 'package:share_plus/share_plus.dart';
7+
import 'package:flutter_tts/flutter_tts.dart';
78
import 'list_item.dart';
89

910
class EditorScreen extends StatefulWidget {
@@ -18,6 +19,7 @@ class EditorScreen extends StatefulWidget {
1819
class _EditorScreenState extends State<EditorScreen> {
1920
late TextEditingController _titleController;
2021
late quill.QuillController _contentController;
22+
late FlutterTts _flutterTts;
2123

2224
int? _backgroundColorValue;
2325
String? _backgroundImagePath;
@@ -30,6 +32,7 @@ class _EditorScreenState extends State<EditorScreen> {
3032
document: widget.item.document,
3133
selection: const TextSelection.collapsed(offset: 0),
3234
);
35+
_flutterTts = FlutterTts();
3336

3437
_backgroundColorValue = widget.item.backgroundColor;
3538
_backgroundImagePath = widget.item.backgroundImagePath;
@@ -39,6 +42,7 @@ class _EditorScreenState extends State<EditorScreen> {
3942
void dispose() {
4043
_titleController.dispose();
4144
_contentController.dispose();
45+
_flutterTts.stop();
4246
super.dispose();
4347
}
4448

@@ -73,6 +77,17 @@ class _EditorScreenState extends State<EditorScreen> {
7377
Navigator.pop(context, "DELETE");
7478
}
7579

80+
Future<void> _speak() async {
81+
final title = _titleController.text;
82+
final content = _contentController.document.toPlainText();
83+
if (title.isNotEmpty) {
84+
await _flutterTts.speak(title);
85+
}
86+
if (content.isNotEmpty) {
87+
await _flutterTts.speak(content);
88+
}
89+
}
90+
7691
void _showEditorMenu() {
7792
showModalBottomSheet(
7893
context: context,
@@ -286,6 +301,9 @@ class _EditorScreenState extends State<EditorScreen> {
286301
IconButton(
287302
icon: Icon(Icons.text_fields, color: textColor),
288303
onPressed: _showTextTools),
304+
IconButton(
305+
icon: Icon(Icons.volume_up, color: textColor),
306+
onPressed: _speak),
289307
],
290308
),
291309
),

lib/main.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class _MyHomePageState extends State<MyHomePage> {
169169
setState(() {
170170
_filteredItems = _items.where((item) {
171171
final titleMatch = item.title.toLowerCase().contains(query);
172-
final summaryMatch = item.summary.toLowerCase().contains(query);
172+
final summaryMatch = item.document.toPlainText().toLowerCase().contains(query);
173173
return titleMatch || summaryMatch;
174174
}).toList();
175175
_sortFilteredItems();
@@ -220,7 +220,7 @@ class _MyHomePageState extends State<MyHomePage> {
220220
setState(() {
221221
final index = _items.indexWhere((i) => i.id == result.id);
222222

223-
if (result.title.isEmpty && result.summary.isEmpty) {
223+
if (result.title.trim().isEmpty && result.document.length <= 1) {
224224
if (index != -1) {
225225
_items.removeAt(index);
226226
}
@@ -279,13 +279,13 @@ class _MyHomePageState extends State<MyHomePage> {
279279
}
280280

281281
void _shareSelectedItems() {
282-
final content = _selectedItems.map((item) => "${item.title}\n${item.summary}").join('\n\n---\n\n');
282+
final content = _selectedItems.map((item) => "${item.title}\n${item.document.toPlainText()}").join('\n\n---\n\n');
283283
SharePlus.instance.share(
284284
ShareParams(
285285
text: content,
286-
subject: 'My Notes',
287-
),
288-
);
286+
subject: 'My Notes',
287+
),
288+
);
289289
_exitSelectionMode();
290290
}
291291

@@ -386,7 +386,7 @@ class _MyHomePageState extends State<MyHomePage> {
386386
children: <Widget>[
387387
DrawerHeader(
388388
decoration: BoxDecoration(color: Theme.of(context).colorScheme.primaryContainer),
389-
child: const Text('Menu', style: TextStyle(color: Colors.white, fontSize: 24)),
389+
child: Text('Menu', style: TextStyle(color: Theme.of(context).colorScheme.onPrimaryContainer, fontSize: 24)),
390390
),
391391
ListTile(
392392
leading: const Icon(Icons.home),
@@ -448,8 +448,8 @@ class _MyHomePageState extends State<MyHomePage> {
448448
maxLines: 1,
449449
overflow: TextOverflow.ellipsis,
450450
),
451-
if (item.title.isNotEmpty && item.summary.isNotEmpty) const SizedBox(height: 8),
452-
if (item.summary.isNotEmpty)
451+
if (item.title.isNotEmpty && item.document.length > 1) const SizedBox(height: 8),
452+
if (item.document.length > 1)
453453
isListView
454454
? Text(
455455
plainTextSummary,

pubspec.lock

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ packages:
234234
dependency: "direct dev"
235235
description:
236236
name: flutter_lints
237-
sha256: "5398f14efa795ffb7a33e9b6a08798b26a180edac4ad7db3f231e40f82ce11e1"
237+
sha256: "3105dc8492f6183fb076ccf1f351ac3d60564bff92e20bfc4af9cc1651f4e7e1"
238238
url: "https://pub.dev"
239239
source: hosted
240-
version: "5.0.0"
240+
version: "6.0.0"
241241
flutter_localizations:
242242
dependency: "direct main"
243243
description: flutter
@@ -272,6 +272,14 @@ packages:
272272
description: flutter
273273
source: sdk
274274
version: "0.0.0"
275+
flutter_tts:
276+
dependency: "direct main"
277+
description:
278+
name: flutter_tts
279+
sha256: ce5eb209b40e95f2f4a1397116c87ab2fcdff32257d04ed7a764e75894c03775
280+
url: "https://pub.dev"
281+
source: hosted
282+
version: "4.2.5"
275283
flutter_web_plugins:
276284
dependency: transitive
277285
description: flutter
@@ -401,10 +409,10 @@ packages:
401409
dependency: transitive
402410
description:
403411
name: lints
404-
sha256: c35bb79562d980e9a453fc715854e1ed39e24e7d0297a880ef54e17f9874a9d7
412+
sha256: "12f842a479589fea194fe5c5a3095abc7be0c1f2ddfa9a0e76aed1dbd26a87df"
405413
url: "https://pub.dev"
406414
source: hosted
407-
version: "5.1.1"
415+
version: "6.1.0"
408416
markdown:
409417
dependency: transitive
410418
description:

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ dependencies:
4343
path_provider: ^2.1.5
4444
provider: ^6.1.5+1
4545
dynamic_color: ^1.8.1
46+
flutter_tts: ^4.2.5
4647

4748
dev_dependencies:
4849
flutter_test:
@@ -53,7 +54,7 @@ dev_dependencies:
5354
# activated in the `analysis_options.yaml` file located at the root of your
5455
# package. See that file for information about deactivating specific lint
5556
# rules and activating additional ones.
56-
flutter_lints: ^5.0.0
57+
flutter_lints: ^6.0.0
5758

5859
# For information on the generic Dart part of this file, see the
5960
# following page: https://dart.dev/tools/pub/pubspec

0 commit comments

Comments
 (0)