aboutsummaryrefslogtreecommitdiffstats
path: root/lib/widgets/nlu_engine_choice.dart
blob: 1e8ca52037bbc6c421a9401f71b6a3e2945c6761 (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
// import 'package:flutter/material.dart';

// enum NLUEngine { snips, rasa }

// class NLUEngineChoice extends StatefulWidget {
//   final Function(NLUEngine) onEngineChanged;

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

//   @override
//   State<NLUEngineChoice> createState() => _NLUEngineChoiceState();
// }

// class _NLUEngineChoiceState extends State<NLUEngineChoice> {
//   NLUEngine nluView = NLUEngine.snips;

//   @override
//   Widget build(BuildContext context) {
//     return SegmentedButton<NLUEngine>(
//       segments: const <ButtonSegment<NLUEngine>>[
//         ButtonSegment<NLUEngine>(
//             value: NLUEngine.snips,
//             label: Text('Snips'),
//             icon: Icon(Icons.settings_suggest)),
//         ButtonSegment<NLUEngine>(
//             value: NLUEngine.rasa,
//             label: Text('RASA'),
//             icon: Icon(Icons.settings_suggest)),
//       ],
//       selected: <NLUEngine>{nluView},
//       onSelectionChanged: (Set<NLUEngine> newSelection) {
//         final newEngine = newSelection.first;
//         setState(() {
//           // By default there is only a single segment that can be
//           // selected at one time, so its value is always the first
//           // item in the selected set.
//           nluView = newEngine;
//         });
//         // Call the callback function to notify the mode change
//         widget.onEngineChanged(newEngine);
//       },
//       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 NLUEngine { snips, rasa }

class NLUEngineChoice extends StatefulWidget {
  final Function(NLUEngine) onEngineChanged;

  const NLUEngineChoice({Key? key, required this.onEngineChanged})
      : super(key: key);

  @override
  State<NLUEngineChoice> createState() => _NLUEngineChoiceState();
}

class _NLUEngineChoiceState extends State<NLUEngineChoice> {
  late NLUEngine _selectedEngine;

  @override
  void initState() {
    super.initState();
    _selectedEngine = NLUEngine.snips; // Initialize the selection
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        InkWell(
          onTap: () => _onEngineChanged(NLUEngine.snips),
          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: _selectedEngine == NLUEngine.snips
                  ? Colors.green
                  : Colors.white,
              border: Border.all(
                color: Colors.transparent,
              ),
            ),
            child: Row(
              children: [
                Icon(
                  _selectedEngine == NLUEngine.snips
                      ? Icons.check
                      : Icons.settings_suggest,
                  color: _selectedEngine == NLUEngine.snips
                      ? Colors.white
                      : Colors.green,
                ),
                SizedBox(width: 8),
                Text(
                  'Snips',
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 18,
                    color: _selectedEngine == NLUEngine.snips
                        ? Colors.white
                        : Colors.green,
                  ),
                ),
              ],
            ),
          ),
        ),
        InkWell(
          onTap: () => _onEngineChanged(NLUEngine.rasa),
          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: _selectedEngine == NLUEngine.rasa
                  ? Colors.green
                  : Colors.white,
              border: Border.all(
                color: Colors.transparent,
              ),
            ),
            child: Row(
              children: [
                Icon(
                  _selectedEngine == NLUEngine.rasa
                      ? Icons.check
                      : Icons.settings_suggest,
                  color: _selectedEngine == NLUEngine.rasa
                      ? Colors.white
                      : Colors.green,
                ),
                SizedBox(width: 8),
                Text(
                  'RASA',
                  style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 18,
                    color: _selectedEngine == NLUEngine.rasa
                        ? Colors.white
                        : Colors.green,
                  ),
                ),
              ],
            ),
          ),
        ),
      ],
    );
  }

  void _onEngineChanged(NLUEngine newEngine) {
    setState(() {
      _selectedEngine = newEngine;
    });

    // Call the callback function to notify the engine change
    widget.onEngineChanged(newEngine);
  }
}