سلام
ویرایش رو انجام میده و سیو میکنم در صفحه اصلی تغییرات نمایش داده نمیشه اما دوباره که تسک رو باز میکنم هم متن ویرایش شده هم اولویت تغییر داده شده درسته با باز کردن مجدد برنامه هم ویرایشها پاک میشه. در افزودت تسک مشکلی نداره
کدهای صفحه EDIT
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:todolist/data.dart';
import 'package:todolist/main.dart';
class EditTaskScreen extends StatefulWidget {
final TaskEntity task;
EditTaskScreen({super.key, required this.task});
@override
State<EditTaskScreen> createState() => _EditTaskScreenState();
}
class _EditTaskScreenState extends State<EditTaskScreen> {
late final TextEditingController _controller = TextEditingController(text: widget.task.name);
@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context);
return Scaffold(
backgroundColor: themeData.colorScheme.surface,
appBar: AppBar(
elevation: 0,
backgroundColor: themeData.colorScheme.surface,
foregroundColor: themeData.colorScheme.onSurface,
title: Row(
children: [
const Text('Edit Task'),
],
),
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
widget.task.name = _controller.text;
widget.task.priority = widget.task.priority;
if (widget.task.isInBox) {
widget.task.save;
} else {
final Box<TaskEntity> box = Hive.box(taskBoxName);
box.add(widget.task);
}
Navigator.of(context).pop();
},
label: Row(
children: const [
Text('save change'),
Icon(
CupertinoIcons.check_mark,
size: 18,
)
],
)),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
Flex(
direction: Axis.horizontal,
children: [
Flexible(
flex: 1,
child: PriorityCheckBox(
label: 'High',
color: highPriority,
isSelected: widget.task.priority == Priority.high,
onTap: () {
setState(() {
widget.task.priority=Priority.high;
});
},
)),
SizedBox(
width: 8,
),
Flexible(
flex: 1,
child: PriorityCheckBox(
label: 'Normal',
color: normalPriority,
isSelected: widget.task.priority == Priority.normal,
onTap: () {
setState(() {
widget.task.priority=Priority.normal;
});
},
)),
SizedBox(
width: 8,
),
Flexible(
flex: 1,
child: PriorityCheckBox(
label: 'Low',
color: lowPriority,
isSelected: widget.task.priority == Priority.low,
onTap: () {
setState(() {
widget.task.priority=Priority.low;
});
},
)),
],
),
TextField(
controller: _controller,
decoration:
InputDecoration(label: Text('Add a task formtoday...',style: themeData.textTheme.bodyText1!.apply(fontSizeFactor: 1.4),)),
)
],
),
),
);
}
}
class PriorityCheckBox extends StatelessWidget {
final String label;
final Color color;
final bool isSelected;
final GestureTapCallback onTap;
const PriorityCheckBox(
{super.key,
required this.label,
required this.color,
required this.isSelected,
required this.onTap});
@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context);
return InkWell(
onTap: onTap,
child: Container(
height: 40,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(4),
border: Border.all(
width: 2, color: secondaryTextColor.withOpacity(0.2))),
child: Stack(
children: [
Center(
child: Text(label),
),
Positioned(
right: 8,
bottom: 0,
top: 0,
child: Center(
child: _CheckBoxShope(
value: isSelected,
color: color,
)))
],
),
),
);
}
}
class _CheckBoxShope extends StatelessWidget {
final bool value;
final Color color;
const _CheckBoxShope({super.key, required this.value, required this.color});
@override
Widget build(BuildContext context) {
final ThemeData themeData = Theme.of(context);
return Container(
height: 16,
width: 16,
decoration:
BoxDecoration(borderRadius: BorderRadius.circular(12), color: color),
child: value
? Icon(
CupertinoIcons.checkmark,
color: themeData.colorScheme.onPrimary,
size: 12,
)
: null,
);
}
}