fixxed pin switch + other stuff
parent
79380eb2e0
commit
dbba93411a
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:moody/utils/SlideDirection.dart';
|
||||
import 'package:moody/utils/widgets/QuestionSliderWidget.dart';
|
||||
import 'package:moody/views/color_page/color_page.dart';
|
||||
import 'package:moody/views/entry_view/entry_page.dart';
|
||||
import 'package:moody/views/first_page/first_page.dart';
|
||||
|
@ -52,8 +53,8 @@ final GoRouter _router = GoRouter(
|
|||
GoRoute(
|
||||
path: '/write',
|
||||
builder: (context, state) {
|
||||
final moodPercentage = state.extra as double;
|
||||
return WritePage(moodPercentage: moodPercentage);
|
||||
final sliderdata = state.extra as SliderChangeData;
|
||||
return WritePage(sliderData: sliderdata);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
|
|
|
@ -9,6 +9,7 @@ class QuestionSliderWidget extends StatefulWidget {
|
|||
final bool isSliderEnabled;
|
||||
final ValueChanged<SliderChangeData> onSliderChanged;
|
||||
final ValueChanged<double> onSliderPositionChanged;
|
||||
final Color sliderColor; // parameter for the color
|
||||
|
||||
QuestionSliderWidget({
|
||||
Key? key,
|
||||
|
@ -18,6 +19,7 @@ class QuestionSliderWidget extends StatefulWidget {
|
|||
required this.isSliderEnabled,
|
||||
required this.onSliderChanged,
|
||||
required this.onSliderPositionChanged,
|
||||
required this.sliderColor, // Initialize the color
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
|
@ -69,7 +71,7 @@ class _QuestionSliderWidgetState extends State<QuestionSliderWidget> {
|
|||
child: SliderTheme(
|
||||
data: SliderTheme.of(context).copyWith(
|
||||
disabledThumbColor: Colors.transparent,
|
||||
activeTrackColor: Colors.black,
|
||||
activeTrackColor: widget.sliderColor,
|
||||
trackShape: RectangularSliderTrackShape(),
|
||||
inactiveTickMarkColor: Colors.red,
|
||||
inactiveTrackColor: Colors.transparent,
|
||||
|
@ -114,11 +116,13 @@ class _QuestionSliderWidgetState extends State<QuestionSliderWidget> {
|
|||
child: _showDragText
|
||||
? Text(
|
||||
"Drag Me -->",
|
||||
style: TextStyle(fontSize: 16),
|
||||
style: TextStyle(
|
||||
fontSize: 16, color: widget.sliderColor),
|
||||
)
|
||||
: Text(
|
||||
"${_sliderData.value.toStringAsFixed(0)}%",
|
||||
style: TextStyle(fontSize: 20),
|
||||
style: TextStyle(
|
||||
fontSize: 20, color: widget.sliderColor),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
|
@ -13,7 +13,6 @@ class FirstPage extends StatefulWidget {
|
|||
|
||||
class _FirstPageState extends State<FirstPage> {
|
||||
SliderChangeData sliderData = SliderChangeData(0, 0);
|
||||
double _sliderValue = 0.0;
|
||||
bool _sliderChanged = false;
|
||||
PreferencesService _prefsService = PreferencesService();
|
||||
|
||||
|
@ -39,7 +38,7 @@ class _FirstPageState extends State<FirstPage> {
|
|||
List<String> texts = [];
|
||||
DiaryEntry entry = DiaryEntry(
|
||||
date: DateTime.now(), // or some date picker value
|
||||
percentValue: _sliderValue.toInt(),
|
||||
percentValue: sliderData.value.toInt(),
|
||||
texts: texts,
|
||||
);
|
||||
|
||||
|
@ -79,6 +78,7 @@ class _FirstPageState extends State<FirstPage> {
|
|||
onSliderPositionChanged: (value) {
|
||||
print("sliderposchanged");
|
||||
},
|
||||
sliderColor: textColor,
|
||||
date: DateTime.now(),
|
||||
questionText: "",
|
||||
initialSliderValue: 0,
|
||||
|
@ -95,9 +95,16 @@ class _FirstPageState extends State<FirstPage> {
|
|||
_sliderChanged
|
||||
? TextButton(
|
||||
onPressed: () {
|
||||
context.go('/write', extra: sliderData.value);
|
||||
context.go('/write', extra: sliderData);
|
||||
},
|
||||
child: Text("warum?"),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 25),
|
||||
child: Text(
|
||||
"warum?",
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontSize: 18),
|
||||
),
|
||||
),
|
||||
)
|
||||
: SizedBox.shrink(),
|
||||
],
|
||||
|
@ -116,7 +123,13 @@ class _FirstPageState extends State<FirstPage> {
|
|||
context.go('/home', extra: 0);
|
||||
}
|
||||
},
|
||||
child: Text(_sliderChanged ? "Save" : "Skip"),
|
||||
child: _sliderChanged
|
||||
? Text("save.",
|
||||
style:
|
||||
TextStyle(fontSize: 18, color: textColor))
|
||||
: Text("skip",
|
||||
style: TextStyle(
|
||||
fontSize: 18, color: Colors.grey)),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
|
|
@ -78,6 +78,7 @@ class _HomePageState extends State<HomePage> {
|
|||
onSliderPositionChanged: (value) {
|
||||
print("sliderposchanged");
|
||||
},
|
||||
sliderColor: Colors.purple,
|
||||
date: DateTime.now(),
|
||||
questionText: 'this is how it is:',
|
||||
initialSliderValue: _sliderValue,
|
||||
|
|
|
@ -1,12 +1,33 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../utils/logic/PreferencesService.dart';
|
||||
import '../../utils/widgets/BottomNavigationWidget.dart';
|
||||
import 'widgets/CustomDivider.dart';
|
||||
import 'widgets/SetPinPopup.dart';
|
||||
import 'widgets/TextSwitchContainer.dart';
|
||||
|
||||
class SettingsPage extends StatelessWidget {
|
||||
class SettingsPage extends StatefulWidget {
|
||||
@override
|
||||
_SettingsPageState createState() => _SettingsPageState();
|
||||
}
|
||||
|
||||
class _SettingsPageState extends State<SettingsPage> {
|
||||
bool isPinEnabled = false; // Default to false
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadPinEnabledState();
|
||||
}
|
||||
|
||||
void _loadPinEnabledState() async {
|
||||
isPinEnabled = await PreferencesService().isPinEnabled();
|
||||
print("isPinenabled2");
|
||||
print(isPinEnabled);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
|
@ -34,11 +55,29 @@ class SettingsPage extends StatelessWidget {
|
|||
onTap: () => context.go("/color"),
|
||||
),
|
||||
CustomDivider(),
|
||||
TextSwitchContainer(
|
||||
leftText: "pin",
|
||||
hasSwitch: true,
|
||||
onTap: () => {showSetPinPopup(context)},
|
||||
onSwitchToggle: (value) => print('Switch toggled: $value'),
|
||||
FutureBuilder<bool>(
|
||||
future: PreferencesService().isPinEnabled(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return CircularProgressIndicator(); // or some other placeholder
|
||||
}
|
||||
bool pinEnabled =
|
||||
snapshot.data ?? false; // Default to false if null
|
||||
return TextSwitchContainer(
|
||||
leftText: "pin",
|
||||
hasSwitch: true,
|
||||
onTap: () => {showSetPinPopup(context)},
|
||||
onSwitchToggle: (value) {
|
||||
if (value) {
|
||||
PreferencesService().enablePin();
|
||||
} else {
|
||||
PreferencesService().disablePin();
|
||||
}
|
||||
// Consider updating the state here or using other state management
|
||||
},
|
||||
switchDefaultValue: pinEnabled,
|
||||
);
|
||||
},
|
||||
),
|
||||
CustomDivider(),
|
||||
TextSwitchContainer(
|
||||
|
|
|
@ -7,6 +7,7 @@ class TextSwitchContainer extends StatefulWidget {
|
|||
final bool hasSwitch;
|
||||
final Function onTap;
|
||||
final Function(bool)? onSwitchToggle;
|
||||
final bool switchDefaultValue; // Added parameter for the default switch value
|
||||
|
||||
TextSwitchContainer({
|
||||
required this.leftText,
|
||||
|
@ -14,14 +15,19 @@ class TextSwitchContainer extends StatefulWidget {
|
|||
this.hasSwitch = false,
|
||||
required this.onTap,
|
||||
this.onSwitchToggle,
|
||||
this.switchDefaultValue = false,
|
||||
});
|
||||
|
||||
@override
|
||||
_TextSwitchContainerState createState() => _TextSwitchContainerState();
|
||||
_TextSwitchContainerState createState() =>
|
||||
_TextSwitchContainerState(switchValue: this.switchDefaultValue);
|
||||
}
|
||||
|
||||
class _TextSwitchContainerState extends State<TextSwitchContainer> {
|
||||
bool switchValue = false;
|
||||
bool switchValue; // No longer explicitly initialized here
|
||||
|
||||
_TextSwitchContainerState(
|
||||
{required this.switchValue}); // Constructor takes the initial switch value
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
|
|
@ -113,6 +113,13 @@ class _CalendarWidgetState extends State<CalendarWidget> {
|
|||
// Fetching diary entry percentage value
|
||||
DiaryEntry? entry =
|
||||
diaryEntries[DateFormat('yyyy-MM-dd').format(date)];
|
||||
if (entry != null) {
|
||||
print(entry);
|
||||
print(entry!.date.toString());
|
||||
print(entry!.percentValue);
|
||||
print(entry!.texts);
|
||||
}
|
||||
|
||||
double fillPercentage =
|
||||
entry != null ? entry.percentValue / 100.0 : 0.0;
|
||||
|
||||
|
|
|
@ -7,15 +7,15 @@ import '../../utils/logic/PreferencesService.dart';
|
|||
import '../../utils/widgets/QuestionSliderWidget.dart';
|
||||
|
||||
class WritePage extends StatefulWidget {
|
||||
final double moodPercentage;
|
||||
final SliderChangeData sliderData;
|
||||
|
||||
const WritePage({Key? key, required this.moodPercentage}) : super(key: key);
|
||||
const WritePage({Key? key, required this.sliderData}) : super(key: key);
|
||||
@override
|
||||
_WritePageState createState() => _WritePageState();
|
||||
}
|
||||
|
||||
class _WritePageState extends State<WritePage> {
|
||||
double _sliderValue = 0.0;
|
||||
SliderChangeData _sliderData = SliderChangeData(0, 0);
|
||||
bool _sliderChanged = true;
|
||||
final PreferencesService _prefsService = PreferencesService();
|
||||
TextEditingController _textController = TextEditingController(text: "why? ");
|
||||
|
@ -23,7 +23,7 @@ class _WritePageState extends State<WritePage> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_sliderValue = widget.moodPercentage; // Set the value here
|
||||
_sliderData = widget.sliderData; // Set the value here
|
||||
}
|
||||
|
||||
void _saveEntry() async {
|
||||
|
@ -33,7 +33,7 @@ class _WritePageState extends State<WritePage> {
|
|||
_textController.text.isEmpty ? [] : [_textController.text];
|
||||
DiaryEntry entry = DiaryEntry(
|
||||
date: DateTime.now(), // or some date picker value
|
||||
percentValue: _sliderValue.toInt(),
|
||||
percentValue: _sliderData.value.toInt(),
|
||||
texts: texts,
|
||||
);
|
||||
|
||||
|
@ -58,7 +58,8 @@ class _WritePageState extends State<WritePage> {
|
|||
// Background circle
|
||||
Positioned.fill(
|
||||
child: CustomPaint(
|
||||
painter: CirclePainter(_sliderValue, Colors.yellowAccent),
|
||||
painter:
|
||||
CirclePainter(_sliderData.value, Colors.yellowAccent),
|
||||
),
|
||||
),
|
||||
// Main content
|
||||
|
@ -73,6 +74,7 @@ class _WritePageState extends State<WritePage> {
|
|||
onSliderPositionChanged: (value) {
|
||||
print("sliderposchanged");
|
||||
},
|
||||
sliderColor: Colors.lightBlue,
|
||||
date: DateTime.now(),
|
||||
questionText: "How are you today",
|
||||
initialSliderValue: 0,
|
||||
|
@ -84,7 +86,7 @@ class _WritePageState extends State<WritePage> {
|
|||
}),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
context.go('/write', extra: _sliderValue);
|
||||
context.go('/write', extra: _sliderData);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(25, 0, 25, 25),
|
||||
|
@ -100,6 +102,7 @@ class _WritePageState extends State<WritePage> {
|
|||
right: 20,
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
_saveEntry();
|
||||
context.go("/home");
|
||||
},
|
||||
child: Text(_sliderChanged ? "Save" : "Skip"),
|
||||
|
|
Loading…
Reference in New Issue