feat: form page

This commit is contained in:
efrilm
2025-08-13 12:55:27 +07:00
parent 83edfa61f1
commit d29486571a
12 changed files with 675 additions and 57 deletions
+1
View File
@@ -63,6 +63,7 @@ class ThemeApp {
letterSpacing: -0.5,
color: AppColor.white,
),
iconTheme: const IconThemeData(color: AppColor.white),
),
);
}
@@ -0,0 +1,470 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'dart:io';
import '../../../common/theme/theme.dart';
// Model untuk question item
class TaskQuestion {
final String id;
final String question;
bool? answer;
File? photo;
TaskQuestion({
required this.id,
required this.question,
this.answer,
this.photo,
});
}
// Model untuk task section
class TaskSection {
final String title;
final List<TaskQuestion> questions;
TaskSection({required this.title, required this.questions});
}
@RoutePage()
class DailyTasksFormPage extends StatefulWidget {
const DailyTasksFormPage({super.key});
@override
State<DailyTasksFormPage> createState() => _DailyTasksFormPageState();
}
class _DailyTasksFormPageState extends State<DailyTasksFormPage>
with SingleTickerProviderStateMixin {
late TabController _tabController;
final ImagePicker _picker = ImagePicker();
// Sample data untuk OPEN dan CLOSING tasks
List<TaskSection> taskSections = [
TaskSection(
title: "OPENING",
questions: [
TaskQuestion(id: "open_1", question: "Apakah meja sudah dibersihkan?"),
TaskQuestion(
id: "open_2",
question: "Apakah alat kerja sudah disiapkan?",
),
TaskQuestion(
id: "open_3",
question: "Apakah ruangan sudah dalam kondisi bersih?",
),
TaskQuestion(
id: "open_4",
question: "Apakah penerangan sudah memadai?",
),
],
),
TaskSection(
title: "CLOSING",
questions: [
TaskQuestion(
id: "close_1",
question: "Apakah meja sudah dibersihkan kembali?",
),
TaskQuestion(
id: "close_2",
question: "Apakah alat kerja sudah disimpan dengan rapi?",
),
TaskQuestion(id: "close_3", question: "Apakah lampu sudah dimatikan?"),
TaskQuestion(id: "close_4", question: "Apakah pintu sudah dikunci?"),
],
),
];
@override
void initState() {
super.initState();
_tabController = TabController(length: 2, vsync: this);
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
Future<void> _pickImage(TaskQuestion question) async {
try {
final XFile? image = await _picker.pickImage(
source: ImageSource.camera,
maxWidth: 1920,
maxHeight: 1080,
imageQuality: 85,
);
if (image != null) {
setState(() {
question.photo = File(image.path);
});
}
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Error mengambil foto: $e'),
backgroundColor: AppColor.error,
),
);
}
}
void _removePhoto(TaskQuestion question) {
setState(() {
question.photo = null;
});
}
bool _isFormComplete() {
for (var section in taskSections) {
for (var question in section.questions) {
if (question.answer == null || question.photo == null) {
return false;
}
}
}
return true;
}
void _submitForm() {
if (!_isFormComplete()) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Mohon lengkapi semua pertanyaan dan foto'),
backgroundColor: AppColor.error,
),
);
return;
}
// Logic untuk submit form
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Daily tasks berhasil disimpan!'),
backgroundColor: AppColor.success,
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColor.background,
appBar: AppBar(
title: const Text(
'Daily Tasks',
style: TextStyle(
color: AppColor.textWhite,
fontWeight: FontWeight.bold,
),
),
backgroundColor: AppColor.primary,
elevation: 0,
bottom: TabBar(
controller: _tabController,
indicatorColor: AppColor.textWhite,
labelColor: AppColor.textWhite,
unselectedLabelColor: AppColor.textWhite.withOpacity(0.7),
labelStyle: const TextStyle(fontWeight: FontWeight.bold),
tabs: taskSections
.map((section) => Tab(text: section.title))
.toList(),
),
),
body: Column(
children: [
Expanded(
child: TabBarView(
controller: _tabController,
children: taskSections.map((section) {
return SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildSectionHeader(section.title),
const SizedBox(height: 16),
...section.questions.map((question) {
return _buildQuestionCard(question);
}).toList(),
],
),
);
}).toList(),
),
),
_buildSubmitButton(),
],
),
);
}
Widget _buildSectionHeader(String title) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [AppColor.primary, AppColor.primaryLight],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Icon(
title == "OPENING" ? Icons.wb_sunny : Icons.nightlight_round,
color: AppColor.textWhite,
size: 24,
),
const SizedBox(width: 12),
Text(
'$title CHECKLIST',
style: const TextStyle(
color: AppColor.textWhite,
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
],
),
);
}
Widget _buildQuestionCard(TaskQuestion question) {
return Container(
margin: const EdgeInsets.only(bottom: 16),
decoration: BoxDecoration(
color: AppColor.white,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: AppColor.black.withOpacity(0.05),
blurRadius: 8,
offset: const Offset(0, 2),
),
],
),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
question.question,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: AppColor.textPrimary,
),
),
const SizedBox(height: 16),
// Yes/No buttons
Row(
children: [
Expanded(
child: _buildAnswerButton(
question: question,
value: true,
label: "YES",
icon: Icons.check_circle,
color: AppColor.success,
),
),
const SizedBox(width: 12),
Expanded(
child: _buildAnswerButton(
question: question,
value: false,
label: "NO",
icon: Icons.cancel,
color: AppColor.error,
),
),
],
),
const SizedBox(height: 16),
// Photo section
_buildPhotoSection(question),
],
),
),
);
}
Widget _buildAnswerButton({
required TaskQuestion question,
required bool value,
required String label,
required IconData icon,
required Color color,
}) {
bool isSelected = question.answer == value;
return GestureDetector(
onTap: () {
setState(() {
question.answer = value;
});
},
child: Container(
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 16),
decoration: BoxDecoration(
color: isSelected ? color : AppColor.backgroundLight,
border: Border.all(
color: isSelected ? color : AppColor.border,
width: 1.5,
),
borderRadius: BorderRadius.circular(8),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
icon,
color: isSelected ? AppColor.white : AppColor.textSecondary,
size: 20,
),
const SizedBox(width: 8),
Text(
label,
style: TextStyle(
color: isSelected ? AppColor.white : AppColor.textSecondary,
fontWeight: FontWeight.w600,
),
),
],
),
),
);
}
Widget _buildPhotoSection(TaskQuestion question) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(
Icons.camera_alt,
color: AppColor.textSecondary,
size: 18,
),
const SizedBox(width: 8),
const Text(
'Foto Bukti',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: AppColor.textSecondary,
),
),
const Text(' *', style: TextStyle(color: AppColor.error)),
],
),
const SizedBox(height: 8),
if (question.photo == null)
GestureDetector(
onTap: () => _pickImage(question),
child: Container(
height: 120,
width: double.infinity,
decoration: BoxDecoration(
color: AppColor.borderLight,
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: AppColor.border,
style: BorderStyle.solid,
),
),
child: const Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.add_a_photo, size: 32, color: AppColor.textLight),
SizedBox(height: 8),
Text(
'Tap untuk mengambil foto',
style: TextStyle(color: AppColor.textLight, fontSize: 14),
),
],
),
),
)
else
Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: Image.file(
question.photo!,
height: 200,
width: double.infinity,
fit: BoxFit.cover,
),
),
Positioned(
top: 8,
right: 8,
child: GestureDetector(
onTap: () => _removePhoto(question),
child: Container(
padding: const EdgeInsets.all(4),
decoration: const BoxDecoration(
color: AppColor.error,
shape: BoxShape.circle,
),
child: const Icon(
Icons.close,
color: AppColor.white,
size: 16,
),
),
),
),
],
),
],
);
}
Widget _buildSubmitButton() {
return Container(
padding: const EdgeInsets.all(16),
decoration: const BoxDecoration(
color: AppColor.white,
border: Border(top: BorderSide(color: AppColor.border, width: 1)),
),
child: SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: _submitForm,
style: ElevatedButton.styleFrom(
backgroundColor: AppColor.primary,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
elevation: 2,
),
child: const Text(
'SUBMIT DAILY TASKS',
style: TextStyle(
color: AppColor.textWhite,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
),
);
}
}
@@ -1,7 +1,9 @@
import 'package:auto_route/auto_route.dart';
import 'package:flutter/material.dart';
import 'package:line_icons/line_icons.dart';
import '../../../../common/theme/theme.dart';
import '../../../router/app_router.gr.dart';
import 'feature_tile.dart';
class HomeFeature extends StatelessWidget {
@@ -52,7 +54,7 @@ class HomeFeature extends StatelessWidget {
onTap: () {},
),
HomeFeatureTile(
title: 'Product',
title: 'Produk',
color: const Color(0xFFFF9800),
icon: LineIcons.box,
onTap: () {},
@@ -64,15 +66,15 @@ class HomeFeature extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
HomeFeatureTile(
title: 'Laporan',
title: 'Form',
color: const Color(0xFFE91E63),
icon: LineIcons.pieChart,
onTap: () {},
icon: LineIcons.fileAlt,
onTap: () => context.router.push(DailyTasksFormRoute()),
),
HomeFeatureTile(
title: 'Kas & Bank',
title: 'Jadwal',
color: const Color(0xFF9C27B0),
icon: LineIcons.university,
icon: LineIcons.calendar,
onTap: () {},
),
HomeFeatureTile(
+3
View File
@@ -24,5 +24,8 @@ class AppRouter extends RootStackRouter {
// Language
AutoRoute(page: LanguageRoute.page),
// Form
AutoRoute(page: DailyTasksFormRoute.page),
];
}
+69 -51
View File
@@ -9,148 +9,166 @@
// coverage:ignore-file
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:apskel_owner_flutter/presentation/pages/auth/login/login_page.dart'
as _i3;
import 'package:apskel_owner_flutter/presentation/pages/home/home_page.dart'
import 'package:apskel_owner_flutter/presentation/components/form/form_page.dart'
as _i1;
import 'package:apskel_owner_flutter/presentation/pages/language/language_page.dart'
as _i2;
import 'package:apskel_owner_flutter/presentation/pages/main/main_page.dart'
import 'package:apskel_owner_flutter/presentation/pages/auth/login/login_page.dart'
as _i4;
import 'package:apskel_owner_flutter/presentation/pages/profile/profile_page.dart'
import 'package:apskel_owner_flutter/presentation/pages/home/home_page.dart'
as _i2;
import 'package:apskel_owner_flutter/presentation/pages/language/language_page.dart'
as _i3;
import 'package:apskel_owner_flutter/presentation/pages/main/main_page.dart'
as _i5;
import 'package:apskel_owner_flutter/presentation/pages/report/report_page.dart'
import 'package:apskel_owner_flutter/presentation/pages/profile/profile_page.dart'
as _i6;
import 'package:apskel_owner_flutter/presentation/pages/splash/splash_page.dart'
import 'package:apskel_owner_flutter/presentation/pages/report/report_page.dart'
as _i7;
import 'package:apskel_owner_flutter/presentation/pages/transaction/transaction_page.dart'
import 'package:apskel_owner_flutter/presentation/pages/splash/splash_page.dart'
as _i8;
import 'package:auto_route/auto_route.dart' as _i9;
import 'package:apskel_owner_flutter/presentation/pages/transaction/transaction_page.dart'
as _i9;
import 'package:auto_route/auto_route.dart' as _i10;
/// generated route for
/// [_i1.HomePage]
class HomeRoute extends _i9.PageRouteInfo<void> {
const HomeRoute({List<_i9.PageRouteInfo>? children})
/// [_i1.DailyTasksFormPage]
class DailyTasksFormRoute extends _i10.PageRouteInfo<void> {
const DailyTasksFormRoute({List<_i10.PageRouteInfo>? children})
: super(DailyTasksFormRoute.name, initialChildren: children);
static const String name = 'DailyTasksFormRoute';
static _i10.PageInfo page = _i10.PageInfo(
name,
builder: (data) {
return const _i1.DailyTasksFormPage();
},
);
}
/// generated route for
/// [_i2.HomePage]
class HomeRoute extends _i10.PageRouteInfo<void> {
const HomeRoute({List<_i10.PageRouteInfo>? children})
: super(HomeRoute.name, initialChildren: children);
static const String name = 'HomeRoute';
static _i9.PageInfo page = _i9.PageInfo(
static _i10.PageInfo page = _i10.PageInfo(
name,
builder: (data) {
return const _i1.HomePage();
return const _i2.HomePage();
},
);
}
/// generated route for
/// [_i2.LanguagePage]
class LanguageRoute extends _i9.PageRouteInfo<void> {
const LanguageRoute({List<_i9.PageRouteInfo>? children})
/// [_i3.LanguagePage]
class LanguageRoute extends _i10.PageRouteInfo<void> {
const LanguageRoute({List<_i10.PageRouteInfo>? children})
: super(LanguageRoute.name, initialChildren: children);
static const String name = 'LanguageRoute';
static _i9.PageInfo page = _i9.PageInfo(
static _i10.PageInfo page = _i10.PageInfo(
name,
builder: (data) {
return const _i2.LanguagePage();
return const _i3.LanguagePage();
},
);
}
/// generated route for
/// [_i3.LoginPage]
class LoginRoute extends _i9.PageRouteInfo<void> {
const LoginRoute({List<_i9.PageRouteInfo>? children})
/// [_i4.LoginPage]
class LoginRoute extends _i10.PageRouteInfo<void> {
const LoginRoute({List<_i10.PageRouteInfo>? children})
: super(LoginRoute.name, initialChildren: children);
static const String name = 'LoginRoute';
static _i9.PageInfo page = _i9.PageInfo(
static _i10.PageInfo page = _i10.PageInfo(
name,
builder: (data) {
return const _i3.LoginPage();
return const _i4.LoginPage();
},
);
}
/// generated route for
/// [_i4.MainPage]
class MainRoute extends _i9.PageRouteInfo<void> {
const MainRoute({List<_i9.PageRouteInfo>? children})
/// [_i5.MainPage]
class MainRoute extends _i10.PageRouteInfo<void> {
const MainRoute({List<_i10.PageRouteInfo>? children})
: super(MainRoute.name, initialChildren: children);
static const String name = 'MainRoute';
static _i9.PageInfo page = _i9.PageInfo(
static _i10.PageInfo page = _i10.PageInfo(
name,
builder: (data) {
return const _i4.MainPage();
return const _i5.MainPage();
},
);
}
/// generated route for
/// [_i5.ProfilePage]
class ProfileRoute extends _i9.PageRouteInfo<void> {
const ProfileRoute({List<_i9.PageRouteInfo>? children})
/// [_i6.ProfilePage]
class ProfileRoute extends _i10.PageRouteInfo<void> {
const ProfileRoute({List<_i10.PageRouteInfo>? children})
: super(ProfileRoute.name, initialChildren: children);
static const String name = 'ProfileRoute';
static _i9.PageInfo page = _i9.PageInfo(
static _i10.PageInfo page = _i10.PageInfo(
name,
builder: (data) {
return const _i5.ProfilePage();
return const _i6.ProfilePage();
},
);
}
/// generated route for
/// [_i6.ReportPage]
class ReportRoute extends _i9.PageRouteInfo<void> {
const ReportRoute({List<_i9.PageRouteInfo>? children})
/// [_i7.ReportPage]
class ReportRoute extends _i10.PageRouteInfo<void> {
const ReportRoute({List<_i10.PageRouteInfo>? children})
: super(ReportRoute.name, initialChildren: children);
static const String name = 'ReportRoute';
static _i9.PageInfo page = _i9.PageInfo(
static _i10.PageInfo page = _i10.PageInfo(
name,
builder: (data) {
return const _i6.ReportPage();
return const _i7.ReportPage();
},
);
}
/// generated route for
/// [_i7.SplashPage]
class SplashRoute extends _i9.PageRouteInfo<void> {
const SplashRoute({List<_i9.PageRouteInfo>? children})
/// [_i8.SplashPage]
class SplashRoute extends _i10.PageRouteInfo<void> {
const SplashRoute({List<_i10.PageRouteInfo>? children})
: super(SplashRoute.name, initialChildren: children);
static const String name = 'SplashRoute';
static _i9.PageInfo page = _i9.PageInfo(
static _i10.PageInfo page = _i10.PageInfo(
name,
builder: (data) {
return const _i7.SplashPage();
return const _i8.SplashPage();
},
);
}
/// generated route for
/// [_i8.TransactionPage]
class TransactionRoute extends _i9.PageRouteInfo<void> {
const TransactionRoute({List<_i9.PageRouteInfo>? children})
/// [_i9.TransactionPage]
class TransactionRoute extends _i10.PageRouteInfo<void> {
const TransactionRoute({List<_i10.PageRouteInfo>? children})
: super(TransactionRoute.name, initialChildren: children);
static const String name = 'TransactionRoute';
static _i9.PageInfo page = _i9.PageInfo(
static _i10.PageInfo page = _i10.PageInfo(
name,
builder: (data) {
return const _i8.TransactionPage();
return const _i9.TransactionPage();
},
);
}