aboutsummaryrefslogtreecommitdiffstats
path: root/lib/widgets/assistant_mode_choice.dart
blob: ec175347774ca9626845acc6bf777fb06be5edb2 (plain)
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
190
191
192
193
194
195
196
197
198
199
200
201
202
// import 'package:flutter/material.dart';
// import 'package:provider/provider.dart';
// import '../models/app_state.dart';

// enum AssistantMode { wakeWord, manual }

// class AssistantModeChoice extends StatefulWidget {
//   final Function(AssistantMode) onModeChanged;

//   const AssistantModeChoice({Key? key, required this.onModeChanged})
//       : super(key: key);

//   @override
//   AssistantModeChoiceState createState() => AssistantModeChoiceState();
// }

// class AssistantModeChoiceState extends State<AssistantModeChoice> {
//   @override
//   Widget build(BuildContext context) {
//     final appState = context.watch<AppState>(); // Watch the app state

//     return SegmentedButton<AssistantMode>(
//       segments: const <ButtonSegment<AssistantMode>>[
//         ButtonSegment<AssistantMode>(
//             value: AssistantMode.wakeWord,
//             label: Text('Wake Word'),
//             icon: Icon(Icons.graphic_eq)),
//         ButtonSegment<AssistantMode>(
//             value: AssistantMode.manual,
//             label: Text('Manual'),
//             icon: Icon(Icons.graphic_eq)),
//       ],
//       selected: <AssistantMode>{
//         appState.isWakeWordMode ? AssistantMode.wakeWord : AssistantMode.manual
//       }, // Use app state
//       onSelectionChanged: (Set<AssistantMode> newSelection) {
//         final newMode = newSelection.first;
//         setState(() {
//           // Update the app state when the mode changes
//           appState.isWakeWordMode = newMode == AssistantMode.wakeWord;
//         });
//         // Call the callback function to notify the mode change
//         widget.onModeChanged(newMode);
//       },
//       style: ButtonStyle(
//           side: MaterialStateProperty.all<BorderSide>(
//             BorderSide(
//               width: 0, // Remove border width
//               color: Colors.transparent, // Make border transparent
//             ),
//           ),
//           backgroundColor: MaterialStateProperty.resolveWith<Color>(
//             (states) {
//               if (states.contains(MaterialState.selected)) {
//                 return Colors.green; // Color when pressed
//               }
//               // Add more conditions for other states as needed
//               return Colors.white; // Default color
//             },
//           ),
//           foregroundColor: MaterialStateProperty.resolveWith<Color>((states) {
//             if (states.contains(MaterialState.selected)) {
//               return Colors.white; // Color when pressed
//             }
//             // Add more conditions for other states as needed
//             return Colors.green;
//           })),
//     );
//   }
// }

import 'package:flutter/material.dart';

enum AssistantMode { wakeWord, manual }

class AssistantModeChoice extends StatefulWidget {
  final Function(AssistantMode) onModeChanged;

  const AssistantModeChoice({Key? key, required this.onModeChanged})
      : super(key: key);

  @override
  AssistantModeChoiceState createState() => AssistantModeChoiceState();
}

class AssistantModeChoiceState extends State<AssistantModeChoice> {
  late AssistantMode _selectedMode;

  @override
  void initState() {
    super.initState();
    _selectedMode = AssistantMode.manual; // Initialize the selection
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        InkWell(
          onTap: () => _onModeChanged(AssistantMode.wakeWord),
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(20.0),
            bottomLeft: Radius.circular(20.0),
          ),
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 17.5, vertical: 5.0),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(20.0),
                bottomLeft: Radius.circular(20.0),
              ),
              color: _selectedMode == AssistantMode.wakeWord
                  ? Colors.green
                  : Colors.white,
              border: Border.all(
                color: Colors.transparent,
              ),
            ),
            child: Row(
              children: [
                Icon(
                  _selectedMode == AssistantMode.wakeWord
                      ? Icons.check
                      : Icons.graphic_eq,
                  color: _selectedMode == AssistantMode.wakeWord
                      ? Colors.white
                      : Colors.green,
                ),
                SizedBox(width: 8),
                Text(
                  'Wake Word',
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 18,
                    color: _selectedMode == AssistantMode.wakeWord
                        ? Colors.white
                        : Colors.green,
                  ),
                ),
              ],
            ),
          ),
        ),
        InkWell(
          onTap: () => _onModeChanged(AssistantMode.manual),
          borderRadius: BorderRadius.only(
            topRight: Radius.circular(20.0),
            bottomRight: Radius.circular(20.0),
          ),
          child: Container(
            padding: EdgeInsets.symmetric(horizontal: 17.5, vertical: 5.0),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.only(
                topRight: Radius.circular(20.0),
                bottomRight: Radius.circular(20.0),
              ),
              color: _selectedMode == AssistantMode.manual
                  ? Colors.green
                  : Colors.white,
              border: Border.all(
                color: Colors.transparent,
              ),
            ),
            child: Row(
              children: [
                Icon(
                  _selectedMode == AssistantMode.manual
                      ? Icons.check
                      : Icons.graphic_eq,
                  color: _selectedMode == AssistantMode.manual
                      ? Colors.white
                      : Colors.green,
                ),
                SizedBox(width: 8),
                Text(
                  'Manual',
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 18,
                    color: _selectedMode == AssistantMode.manual
                        ? Colors.white
                        : Colors.green,
                  ),
                ),
              ],
            ),
          ),
        ),
      ],
    );
  }

  void _onModeChanged(AssistantMode newMode) {
    setState(() {
      _selectedMode = newMode;
    });

    // Call the callback function to notify the mode change
    widget.onModeChanged(newMode);
  }
}