Skip to content

Commit 6af1b2d

Browse files
author
alboom4ick
committed
Changed the FlatButtons to Elevated ones, because flutter no longer supports them.
1 parent e687ecb commit 6af1b2d

File tree

5 files changed

+156
-95
lines changed

5 files changed

+156
-95
lines changed

lib/components/ButtonDouble.dart

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class _ButtonState extends State<ButtonDoubleComponent> {
4444
return (Container(
4545
height: 60,
4646
width: 90,
47-
child: FlatButton(
47+
child: ElevatedButton(
4848
onPressed: () {
4949
_sendMessage(buttonClicado ? widget.comandOn! : widget.comandOff!);
5050
_changeButtonColor();
@@ -53,10 +53,15 @@ class _ButtonState extends State<ButtonDoubleComponent> {
5353
widget.buttonName!,
5454
style: TextStyle(color: Colors.white),
5555
),
56-
color: buttonClicado
57-
? Color.fromRGBO(237, 46, 39, 1)
58-
: Color.fromRGBO(0, 0, 0, 1),
59-
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
56+
style: ButtonStyle(
57+
backgroundColor: WidgetStatePropertyAll(
58+
buttonClicado
59+
? Color.fromRGBO(237, 46, 39, 1)
60+
: Color.fromRGBO(0, 0, 0, 1),
61+
),
62+
shape: WidgetStatePropertyAll(
63+
RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
64+
)),
6065
)));
6166
}
6267

lib/components/ButtonSingle.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,18 @@ class _ButtonState extends State<ButtonSingleComponent> {
3939
return (Container(
4040
height: 60,
4141
width: 80,
42-
child: FlatButton(
42+
child: ElevatedButton(
4343
onPressed: () {
4444
_sendMessage(widget.comandOn!);
4545
},
4646
child: Text(
4747
widget.buttonName!,
4848
style: TextStyle(color: Colors.white, fontSize: 25),
4949
),
50-
color: widget.colorButton!,
51-
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(5)),
50+
style: ButtonStyle(
51+
backgroundColor: WidgetStatePropertyAll(widget.colorButton!),
52+
shape: WidgetStatePropertyAll(RoundedRectangleBorder(
53+
borderRadius: BorderRadius.circular(5)))),
5254
)));
5355
}
5456

lib/components/CustomAppBar.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,10 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
6565
: Icons.bluetooth_disabled),
6666
style: ElevatedButton.styleFrom(
6767
shape: CircleBorder(),
68-
primary: StatusConnectionProvider.device != null
69-
? Color.fromRGBO(15, 171, 118, 1)
70-
: Colors.black),
68+
backgroundColor:
69+
StatusConnectionProvider.device != null
70+
? Color.fromRGBO(15, 171, 118, 1)
71+
: Colors.black),
7172
)
7273
: SizedBox.shrink());
7374
}),

lib/components/VoiceButtonPage.dart

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'dart:typed_data';
77
import 'package:flutter_bluetooth_serial/flutter_bluetooth_serial.dart';
88
import 'package:flutter_speech/flutter_speech.dart';
99

10-
1110
class VoiceButtonComponent extends StatefulWidget {
1211
final BluetoothConnection? connection;
1312
final int clientID;
@@ -18,7 +17,7 @@ class VoiceButtonComponent extends StatefulWidget {
1817
this.languageSelected,
1918
required this.clientID,
2019
}) : super(key: key);
21-
_VoiceButtonState createState() => _VoiceButtonState();
20+
_VoiceButtonState createState() => _VoiceButtonState();
2221
}
2322

2423
class Language {
@@ -41,12 +40,11 @@ class _Message {
4140
_Message(this.whom, this.text);
4241
}
4342

44-
4543
class _VoiceButtonState extends State<VoiceButtonComponent> {
4644
bool buttonClicado = false;
4745
final TextEditingController textEditingController = TextEditingController();
4846
List<_Message> messages = <_Message>[];
49-
47+
5048
late SpeechRecognition _speech;
5149
bool _speechRecognitionAvailable = false;
5250
bool _isListening = false;
@@ -65,7 +63,15 @@ class _VoiceButtonState extends State<VoiceButtonComponent> {
6563
_speech.setRecognitionResultHandler(onRecognitionResult);
6664
_speech.setRecognitionCompleteHandler(onRecognitionComplete);
6765
_speech.setErrorHandler(errorHandler);
68-
_speech.activate(languages.firstWhere((l) => l.code == (widget.languageSelected == null ? 'pt_BR' : widget.languageSelected!)).code).then((res) {
66+
_speech
67+
.activate(languages
68+
.firstWhere((l) =>
69+
l.code ==
70+
(widget.languageSelected == null
71+
? 'pt_BR'
72+
: widget.languageSelected!))
73+
.code)
74+
.then((res) {
6975
setState(() => _speechRecognitionAvailable = res);
7076
});
7177
}
@@ -89,9 +95,15 @@ class _VoiceButtonState extends State<VoiceButtonComponent> {
8995
}
9096
}
9197

92-
93-
void start() => _speech.activate(
94-
languages.firstWhere((l) => l.code == (widget.languageSelected == null ? 'pt_BR' : widget.languageSelected!)).code).then((_) {
98+
void start() => _speech
99+
.activate(languages
100+
.firstWhere((l) =>
101+
l.code ==
102+
(widget.languageSelected == null
103+
? 'pt_BR'
104+
: widget.languageSelected!))
105+
.code)
106+
.then((_) {
95107
return _speech.listen().then((result) {
96108
print('_MyAppState.start => result $result');
97109
setState(() {
@@ -110,7 +122,6 @@ class _VoiceButtonState extends State<VoiceButtonComponent> {
110122
void onSpeechAvailability(bool result) =>
111123
setState(() => _speechRecognitionAvailable = result);
112124

113-
114125
void onRecognitionStarted() {
115126
setState(() => _isListening = true);
116127
}
@@ -128,24 +139,16 @@ class _VoiceButtonState extends State<VoiceButtonComponent> {
128139
void errorHandler() => activateSpeechRecognizer();
129140

130141
Widget build(BuildContext context) {
131-
return (ElevatedButton(
132-
onPressed: _speechRecognitionAvailable && !_isListening
133-
? () => start()
134-
: null,
135-
child: Icon(
136-
_isListening
137-
? Icons.settings_voice
138-
: Icons.settings_voice_outlined,
139-
),
140-
style: ElevatedButton.styleFrom(
141-
shape: CircleBorder(),
142-
primary: _isListening
143-
? Color.fromRGBO(255, 255, 0, 1)
144-
: Colors.black),
145-
146-
));
142+
return (ElevatedButton(
143+
onPressed:
144+
_speechRecognitionAvailable && !_isListening ? () => start() : null,
145+
child: Icon(
146+
_isListening ? Icons.settings_voice : Icons.settings_voice_outlined,
147+
),
148+
style: ElevatedButton.styleFrom(
149+
shape: CircleBorder(),
150+
backgroundColor:
151+
_isListening ? Color.fromRGBO(255, 255, 0, 1) : Colors.black),
152+
));
147153
}
148-
149-
150-
151-
}
154+
}

0 commit comments

Comments
 (0)