// 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 { // @override // Widget build(BuildContext context) { // final appState = context.watch(); // Watch the app state // return SegmentedButton( // segments: const >[ // ButtonSegment( // value: AssistantMode.wakeWord, // label: Text('Wake Word'), // icon: Icon(Icons.graphic_eq)), // ButtonSegment( // value: AssistantMode.manual, // label: Text('Manual'), // icon: Icon(Icons.graphic_eq)), // ], // selected: { // appState.isWakeWordMode ? AssistantMode.wakeWord : AssistantMode.manual // }, // Use app state // onSelectionChanged: (Set 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( // width: 0, // Remove border width // color: Colors.transparent, // Make border transparent // ), // ), // backgroundColor: MaterialStateProperty.resolveWith( // (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((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 { 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: [ 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); } }