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