Skip to content

Commit

Permalink
routine addEdit scroll 방식 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
ljyo2o9 committed Aug 21, 2024
1 parent 61fa7b9 commit 6b258b0
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class PosePartWidget extends StatelessWidget {
poseData: poseData,
repetitionsController: TextEditingController(text: "10"),
setsController: TextEditingController(text: "1"),
repetitionsNode: FocusNode(),
setsNode: FocusNode(),
),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ class PoseRecommendWidgetBottom extends StatelessWidget {
poseData: poseData,
repetitionsController: TextEditingController(text: "10"),
setsController: TextEditingController(text: "1"),
repetitionsNode: FocusNode(),
setsNode: FocusNode(),
),
);
MaeumNavigator.pop(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@ class RoutineAddPoseListStateModel {
PoseEntity poseData;
/// 포즈 repetitions의 값을 관리하는 컨트롤러
final TextEditingController repetitionsController;
final FocusNode repetitionsNode;
/// 포즈 sets의 값을 관리하는 컨트롤러
final TextEditingController setsController;
final FocusNode setsNode;


RoutineAddPoseListStateModel({
required this.poseData,
required this.repetitionsController,
required this.repetitionsNode,
required this.setsController,
required this.setsNode,
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ class AddToRoutineDetailScreen extends StatefulWidget {
}

class _AddToRoutineDetailScreenState extends State<AddToRoutineDetailScreen> {
//final int repetitions, sets;
late final TextEditingController _repetitionsController;
late final FocusNode _repetitionsNode;

late final TextEditingController _setsController;
late final FocusNode _setsNode;

@override
void initState() {
Expand All @@ -52,24 +49,19 @@ class _AddToRoutineDetailScreenState extends State<AddToRoutineDetailScreen> {
_repetitionsController.text = "10";
}
});
_repetitionsNode = FocusNode();

_setsController = TextEditingController(text: "1")..addListener(() {
if(_setsController.text.isEmpty){
_setsController.text = "1";
}
});
_setsNode = FocusNode();
}

@override
void dispose() {
super.dispose();
_repetitionsController.dispose();
_repetitionsNode.dispose();

_repetitionsController.dispose();;
_setsController.dispose();
_setsNode.dispose();
}

@override
Expand Down Expand Up @@ -138,15 +130,13 @@ class _AddToRoutineDetailScreenState extends State<AddToRoutineDetailScreen> {
RoutineAddEditPoseItemCountWidget(
title: "횟수",
controller: _repetitionsController,
focusNode: _repetitionsNode,
),

SizedBox(height: 24.h),

RoutineAddEditPoseItemCountWidget(
title: "세트",
controller: _setsController,
focusNode: _setsNode,
),
],
),
Expand Down
47 changes: 24 additions & 23 deletions lib/presentation/routine/ui/view/routine_add_edit_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ class _RoutineAddEditScreenState extends State<RoutineAddEditScreen> {
.map((e) => RoutineAddPoseListStateModel(
poseData: e.pose,
repetitionsController: TextEditingController(text: e.repetitions.toString()),
repetitionsNode: FocusNode(),
setsController: TextEditingController(text: e.sets.toString()),
setsNode: FocusNode())).toList();
setsController: TextEditingController(text: e.sets.toString()))).toList();
context.read<RoutineAddPoseListStateCubit>().init(initList: initList);
} else {
context.read<RoutineAddPoseListStateCubit>().init(initList: []);
Expand Down Expand Up @@ -93,26 +91,29 @@ class _RoutineAddEditScreenState extends State<RoutineAddEditScreen> {
routineId: widget.routineData != null ? widget.routineData!.id : 0,
routineTitleController: _routineTitleController,
),
body: Padding(
padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 24.h),
child: Column(
children: [
/// 제목 입력 TextField
RoutineTitleTextField(
routineTitleController: _routineTitleController,
routineFocusNode: _routineFocusNode,
),

SizedBox(height: 32.h),

/// DayOfWeekWidget
const RoutineDayOfWeekWidget(),

SizedBox(height: 32.h),

/// 추가할 Routine을 모아둔 List
const RoutineAddEditPoseListWidget(),
],
body: SingleChildScrollView(
// physics: const NeverScrollableScrollPhysics(),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 24.h),
child: Column(
children: [
/// 제목 입력 TextField
RoutineTitleTextField(
routineTitleController: _routineTitleController,
routineFocusNode: _routineFocusNode,
),

SizedBox(height: 32.h),

/// DayOfWeekWidget
const RoutineDayOfWeekWidget(),

SizedBox(height: 32.h),

/// 추가할 Routine을 모아둔 List
const RoutineAddEditPoseListWidget(),
],
),
),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ class RoutineAddEditPoseListWidget extends StatelessWidget {
return BlocBuilder<RoutineAddPoseListStateCubit, List<RoutineAddPoseListStateModel>>(
builder: (_, state) {
return SizedBox(
height: 500.h,
height: 220.h * state.length + 50.h,
child: ListView.builder(
physics: const NeverScrollableScrollPhysics(),
itemCount: state.length,
itemBuilder: (_, index) {
return Padding(
Expand Down Expand Up @@ -69,15 +70,13 @@ class RoutineAddEditPoseListWidget extends StatelessWidget {
RoutineAddEditPoseItemCountWidget(
title: "횟수",
controller: state[index].repetitionsController,
focusNode: state[index].repetitionsNode,
),

SizedBox(height: 12.h),

RoutineAddEditPoseItemCountWidget(
title: "세트",
controller: state[index].setsController,
focusNode: state[index].setsNode,
),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,51 @@ import 'package:maeumgagym_flutter/core/maeum/maeum_text.dart';
import '../../../../component/image_widget.dart';
import '../../../../core/images.dart';

class RoutineAddEditPoseItemCountWidget extends StatelessWidget {
class RoutineAddEditPoseItemCountWidget extends StatefulWidget {
final String title;
final TextEditingController controller;
final FocusNode focusNode;

const RoutineAddEditPoseItemCountWidget({
super.key,
required this.title,
required this.controller,
required this.focusNode,
});

void incrementControllerValue() {
/// controller.text를 int로 변환할 수 있다면 변환 값을 반환, 아니면 null => 0,
int currentValue = int.tryParse(controller.text) ?? 0;
controller.text = (currentValue + 1).toString();
}

void decrementControllerValue() {
int currentValue = int.tryParse(controller.text) ?? 0;
@override
State<RoutineAddEditPoseItemCountWidget> createState() => _RoutineAddEditPoseItemCountWidgetState();
}

/// 횟수가 최솟값인 1보다 작을 수 없기 때문.
if (currentValue > 1) {
controller.text = (currentValue - 1).toString();
}
class _RoutineAddEditPoseItemCountWidgetState extends State<RoutineAddEditPoseItemCountWidget> {
@override
void initState() {
super.initState();
widget.controller.addListener(() {
if(widget.controller.text.isEmpty){
widget.controller.text = "1";
}
});
}

@override
Widget build(BuildContext context) {
final String title = widget.title;
final TextEditingController controller = widget.controller;

void incrementControllerValue() {
/// controller.text를 int로 변환할 수 있다면 변환 값을 반환, 아니면 null => 0,
int currentValue = int.tryParse(controller.text) ?? 0;
controller.text = (currentValue + 1).toString();
}

void decrementControllerValue() {
int currentValue = int.tryParse(controller.text) ?? 0;

/// 횟수가 최솟값인 1보다 작을 수 없기 때문.
if (currentValue > 1) {
controller.text = (currentValue - 1).toString();
}
}

return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expand Down Expand Up @@ -88,9 +104,7 @@ class RoutineAddEditPoseItemCountWidget extends StatelessWidget {
Expanded(
child: TextFormField(
controller: controller,
focusNode: focusNode,
textInputAction: TextInputAction.done,
onTapOutside: (_) => focusNode.unfocus(),
onChanged: (value) {
if (value.isNotEmpty) {
int parsedValue = int.tryParse(value) ?? 0;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A new Flutter project.

publish_to: 'none'

version: 0.9.92+121
version: 0.9.92+122

environment:
sdk: '>=3.0.6 <4.0.0'
Expand Down

0 comments on commit 6b258b0

Please sign in to comment.