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
|
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/app_state.dart';
enum OnlineModeEnum{
enabled,
disabled
}
class OnlineModeChoice extends StatefulWidget {
final Function(OnlineModeEnum) onModeChanged;
final String theme;
const OnlineModeChoice({
Key? key,
required this.onModeChanged,
required this.theme
}) : super(key: key);
@override
State<OnlineModeChoice> createState() => _OnlineModeChoiceState();
}
class _OnlineModeChoiceState extends State<OnlineModeChoice> {
late OnlineModeEnum _selectedMode;
late String _theme;
@override
void initState() {
super.initState();
final appState = context.read<AppState>();
_selectedMode = appState.onlineMode ? OnlineModeEnum.enabled : OnlineModeEnum.disabled;
_theme = widget.theme;
}
@override
Widget build(BuildContext context) {
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
InkWell(
onTap: () => _onModelChanged(OnlineModeEnum.disabled),
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 == OnlineModeEnum.disabled
? Colors.green
: _theme == "dark" || _theme == "textured-dark"
? Colors.black
: Colors.white,
border: Border.all(
color: Colors.transparent,
),
),
child: Row(
children: [
Icon(
_selectedMode == OnlineModeEnum.disabled
? Icons.check
: Icons.cloud_off_outlined,
color: _selectedMode == OnlineModeEnum.disabled
? Colors.white
: Colors.green,
),
SizedBox(width: 8),
Text(
'Disabled',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 17,
color: _selectedMode == OnlineModeEnum.disabled
? Colors.white
: Colors.green,
),
),
],
),
),
),
InkWell(
onTap: () => _onModelChanged(OnlineModeEnum.enabled),
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 == OnlineModeEnum.enabled
? Colors.green
: _theme == "dark" || _theme == "textured-dark"
? Colors.black
: Colors.white,
border: Border.all(
color: Colors.transparent,
),
),
child: Row(
children: [
Icon(
_selectedMode == OnlineModeEnum.enabled
? Icons.check
: Icons.cloud_done_outlined,
color: _selectedMode == OnlineModeEnum.enabled
? Colors.white
: Colors.green,
),
SizedBox(width: 8),
Text(
'Enabled',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 17,
color: _selectedMode == OnlineModeEnum.enabled
? Colors.white
: Colors.green,
),
),
],
),
),
),
],
);
}
void _onModelChanged(OnlineModeEnum newMode) {
setState(() {
_selectedMode = newMode;
});
// Call the callback function to notify the engine change
widget.onModeChanged(newMode);
}
}
|