Untitled

 avatar
user_7176186
plain_text
a year ago
24 kB
0
Indexable
Never
// ignore_for_file: unused_element, prefer_final_fields

part of 'pages.dart';

class ProductRegisterPage extends StatefulWidget {
  const ProductRegisterPage({super.key});

  @override
  State<ProductRegisterPage> createState() => _ProductRegisterPageState();
}

class _ProductRegisterPageState extends State<ProductRegisterPage> {
  List<File> _images = [];
  List<File> _videos = [];
  final picker = ImagePicker();

  Future getImages() async {
    final pickedFiles =
        await picker.getMultiImage(imageQuality: 50, maxWidth: 800);

    setState(() {
      if (pickedFiles != null) {
        _images.addAll(
            pickedFiles.map((pickedFile) => File(pickedFile.path)).toList());
      } else {
        print("No Image selected");
      }
    });
    print("berhasil masukkan foto");
  }

  Future<void> getVideos() async {
    List<PlatformFile> result = [];
    try {
      result = (await FilePicker.platform.pickFiles(
        type: FileType.video,
        allowMultiple: true,
        allowCompression: true,
        withData: false,
        withReadStream: true,
        onFileLoading: (task) => print(task.toString()),
      ))!
          .files
          .cast<PlatformFile>()
          .toList();

      if (result == null || result.isEmpty) {
        print("No video selected");
        return;
      }
    } on Exception catch (e) {
      print(e.toString());
    }
    setState(() {
      _videos.addAll(result.map((e) => File(e.path!)).toList());
    });
    print("masukkan video");
  }

  

  final _formKey = GlobalKey<FormState>();
  late TextEditingController nameProductController;
  late TextEditingController meetController;
  late TextEditingController deskripsiController;
  late TextEditingController imageController;
  late TextEditingController dateController;
  TextEditingController dateInpuController = TextEditingController();
  TextEditingController dateInpuLastController = TextEditingController();
  TextEditingController dateInpuSelectController = TextEditingController();

  @override
  void initState() {
    nameProductController = TextEditingController();
    meetController = TextEditingController();
    deskripsiController = TextEditingController();
    imageController = TextEditingController();
    dateController = TextEditingController();

    dateInpuController.text = "";
    super.initState();
  }

  @override
  void dispose() {
    nameProductController.dispose();
    meetController.dispose();
    deskripsiController.dispose();
    imageController.dispose();
    dateController.dispose();
    dateInpuController.dispose();
    dateInpuLastController.dispose();
    dateInpuSelectController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Scaffold(
        body: Padding(
          padding: const EdgeInsets.all(35.0),
          child: SingleChildScrollView(
            child: Form(
              key: _formKey,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  AppbarPrimary(
                    title: "Register as Merchant",
                  ),
                  const SizedBox(
                    height: 16,
                  ),
                  Text(
                    "Please fill this register form correctly!",
                    style: TextThemes.regular.copyWith(
                      fontSize: 10,
                      color: Colors.black,
                    ),
                  ),
                  const SizedBox(
                    height: 12,
                  ),
                  Text(
                    "Product Detail",
                    style: TextThemes.regular.copyWith(
                      fontSize: 10,
                      fontWeight: FontWeight.bold,
                      color: Palette.mediumBlue,
                    ),
                  ),
                  const SizedBox(
                    height: 12,
                  ),
                  TextFormFiledCustom(
                    controller: nameProductController,
                    label: "Nama Product",
                    isMandatory: true,
                    hintText: "Nama Product",
                    validator: (value) {
                      if (value == null || value.isEmpty) {
                        return "Please enter your name product";
                      }
                      if (value.length <= 6 || value.length >= 20) {
                        return "Please enter your name until 6 karakter";
                      }
                      return null;
                    },
                  ),
                  const SizedBox(
                    height: 12,
                  ),
                  TextFormFiledCustom(
                    controller: meetController,
                    label: "Meeting Point",
                    isMandatory: true,
                    hintText: "business address",
                    validator: (value) {
                      if (value == null || value.isEmpty) {
                        return "please enter your address meet point";
                      }
                      return null;
                    },
                  ),
                  const SizedBox(
                    height: 12,
                  ),
                  const FormTextLabel(
                    label: "Deskripsi Product",
                    isRequired: true,
                  ),
                  Container(
                    width: 344,
                    height: 145,
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(14),
                        border: Border.all(color: Palette.mediumBlue)),
                    child: TextFormField(
                      controller: deskripsiController,
                      maxLines: null,
                      decoration: const InputDecoration(
                          hintText: "Deskripsi product",
                          focusedBorder:
                              OutlineInputBorder(borderSide: BorderSide.none),
                          enabledBorder:
                              OutlineInputBorder(borderSide: BorderSide.none)),
                      validator: (value) {
                        if (value == null || value.isEmpty) {
                          return "Produk harus diisi";
                        }
                        if (value.length < 20) {
                          return "deskripsi harus di isi lebih dari 20 karakter";
                        }
                        return null;
                      },
                    ),
                  ),
                  const SizedBox(
                    height: 12,
                  ),
                  const FormTextLabel(
                    label: "Highlight product(min.3 poin)",
                    isRequired: true,
                  ),
                  TextFormDropdown(
                    defaultSelectedValue: "-- Pilih Higlight --",
                    icon: Image.asset(
                      "assets/icons/ic_dropdown.png",
                      width: 24,
                      height: 26,
                    ),
                  ),
                  TextFormDropdown(
                    defaultSelectedValue: "-- Pilih Higlight --",
                    hintText: "hastag",
                    icon: Image.asset(
                      "assets/icons/ic_dropdown.png",
                      width: 24,
                      height: 26,
                    ),
                  ),
                  TextFormDropdown(
                    defaultSelectedValue: "-- Pilih Higlight --",
                    icon: Image.asset(
                      "assets/icons/ic_dropdown.png",
                      width: 24,
                      height: 26,
                    ),
                  ),
                  const SizedBox(
                    height: 12,
                  ),
                  const FormTextLabel(
                    label: "Foto Produk(min.3 foto)",
                    isRequired: true,
                  ),
                  SizedBox(
                    width: MediaQuery.of(context).size.width,
                    height: 100,
                    child: Row(children: [
                      Center(
                        child: Container(
                          width: 100,
                          height: 100,
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(14),
                            border: Border.all(color: Palette.mediumBlue),
                          ),
                          child: IconButton(
                            onPressed: getImages,
                            icon: const Icon(Icons.add_a_photo),
                          ),
                        ),
                      ),
                      Expanded(
                        child: GridView.count(
                          scrollDirection: Axis.horizontal,
                          crossAxisCount: 1,
                          children: List.generate(
                            _images.length,
                            (index) {
                              return Padding(
                                padding: const EdgeInsets.all(8.0),
                                child: ClipRRect(
                                  borderRadius: BorderRadius.circular(14),
                                  child: Image.file(
                                    _images[index],
                                    width: 100,
                                    height: 100,
                                    fit: BoxFit.cover,
                                  ),
                                ),
                              );
                            },
                          ),
                        ),
                      ),
                    ]

                      
                        ),
                  ),
                  const SizedBox(
                    height: 12,
                  ),
                  const FormTextLabel(
                    label: "video Produk(min.3 foto)",
                    isRequired: false,
                  ),
                  SizedBox(
                    width: MediaQuery.of(context).size.width,
                    height: 100,
                    child: Row(
                      children: [
                        SizedBox(
                          height: 100,
                          child: Center(
                            child: Container(
                              width: 100,
                              height: 100,
                              decoration: BoxDecoration(
                                borderRadius: BorderRadius.circular(14),
                                border: Border.all(color: Colors.blue),
                              ),
                              child: IconButton(
                                onPressed: getVideos,
                                icon: const Icon(Icons.video_file),
                              ),
                            ),
                          ),
                        ),
                        Expanded(
                          child: Container(
                            child: ListView.builder(
                                scrollDirection: Axis.horizontal,
                                itemCount: _videos.length,
                                itemBuilder: (BuildContext contex, int index) {
                                  return Padding(
                                    padding: const EdgeInsets.all(8.0),
                                    child: AspectRatio(
                                      aspectRatio: VideoPlayerController.file(
                                              _videos[index])
                                          .value
                                          .aspectRatio,
                                      child: ClipRRect(
                                        borderRadius: BorderRadius.circular(14),
                                        child: Stack(
                                            alignment: Alignment.center,
                                            children: [
                                              VideoPlayer(
                                                VideoPlayerController.file(
                                                    _videos[index])
                                                  ..initialize().then((_) {
                                                    // Ensure all other videos are not muted
                                                    VideoPlayerController.file(
                                                            _videos[index])
                                                        .setVolume(1);
                                                  }),
                                              ),
                                              IconButton(
                                                onPressed: () {},
                                                icon: const Icon(
                                                  Icons.play_arrow,
                                                  color: Colors.white,
                                                  size: 30.0,
                                                ),
                                              ),
                                            ]),
                                      ),
                                    ),
                                  );
                                }),
                          ),
                        ),
                      ],
                    ),
                  ),
                  const SizedBox(
                    height: 12,
                  ),
                  const FormTextLabel(
                    label: "Validity",
                    isRequired: true,
                  ),
                  Row(
                    children: [
                      Expanded(
                        child: TextFormIcon(
                          hintText: "Validity",
                          icon: Image.asset(
                            "assets/icons/Vector.png",
                            width: 24,
                            height: 26,
                          ),
                          controller: dateInpuController,
                          onTap: () async {
                            DateTime? pickDate = await showDatePicker(
                              context: context,
                              initialDate: DateTime.now(),
                              firstDate: DateTime(2000),
                              lastDate: DateTime(2120),
                            );
                            if (pickDate != null) {
                              print(pickDate);
                              String formatDate =
                                  DateFormat('yyyy-MM-dd').format(pickDate);
                              print(formatDate);
                              setState(() {
                                dateInpuController.text = formatDate;
                              });
                            } else {
                              print("date is not selected");
                            }
                          },
                        ),
                      ),
                      Container(
                        margin: const EdgeInsets.symmetric(horizontal: 10),
                        width: 15,
                        height: 3,
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(5),
                            color: Palette.bgContainer),
                      ),
                      Expanded(
                        child: TextFormIcon(
                          hintText: "Validity",
                          icon: Image.asset(
                            "assets/icons/Vector.png",
                            width: 24,
                            height: 26,
                          ),
                          controller: dateInpuLastController,
                          onTap: () async {
                            DateTime? pickDate = await showDatePicker(
                              context: context,
                              initialDate: DateTime.now(),
                              firstDate: DateTime(2000),
                              lastDate: DateTime(2120),
                            );
                            if (pickDate != null) {
                              print(pickDate);
                              String formatDate =
                                  DateFormat('yyyy-MM-dd').format(pickDate);
                              print(formatDate);
                              setState(() {
                                dateInpuLastController.text = formatDate;
                              });
                            }
                            print('date not is selected');
                          },
                        ),
                      ),
                    ],
                  ),
                  const SizedBox(
                    height: 12,
                  ),
                  TextFormFiledCustom(
                    controller: dateController,
                    label: "Black out Dates",
                    hintText: "Black out Dates",
                  ),
                  const SizedBox(
                    height: 12,
                  ),
                  const FormTextLabel(
                    label: "Jadwal Operasioanl",
                    isRequired: true,
                  ),
                  GridView.count(
                      padding: EdgeInsets.zero,
                      childAspectRatio: 2.5,
                      crossAxisCount: 2,
                      crossAxisSpacing: 6,
                      mainAxisSpacing: 6,
                      shrinkWrap: true,
                      physics: ScrollPhysics(),
                      children: items
                          .map((data) => GestureDetector(
                                onTap: () {},
                                child: Container(
                                  color: data.color,
                                  child: Row(
                                    children: [
                                      Container(
                                        width: 5,
                                        height: 80,
                                        decoration: const BoxDecoration(
                                          color: Colors.grey,
                                          borderRadius: BorderRadius.only(
                                              topRight: Radius.circular(20),
                                              bottomRight: Radius.circular(20)),
                                        ),
                                      ),
                                      const SizedBox(
                                        width: 16,
                                      ),
                                      Container(
                                        padding: const EdgeInsets.only(top: 10),
                                        child: Column(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: [
                                            Text(data.title),
                                            const SizedBox(
                                              height: 5,
                                            ),
                                            GestureDetector(
                                                onTap: () async {
                                                  TimeRange result =
                                                      await showTimeRangePicker(
                                                    context: context,
                                                    start: const TimeOfDay(
                                                        hour: 9, minute: 0),
                                                    end: const TimeOfDay(
                                                        hour: 18, minute: 0),
                                                    disabledTime: TimeRange(
                                                      startTime:
                                                          const TimeOfDay(
                                                              hour: 12,
                                                              minute: 0),
                                                      endTime: const TimeOfDay(
                                                        hour: 13,
                                                        minute: 0,
                                                      ),
                                                    ),
                                                    interval: const Duration(
                                                        minutes: 5),
                                                  );
                                                  if (result != null) {
                                                    String formatTime =
                                                        '${result.startTime.format(context)} - ${result.endTime.format(context)}';
                                                    setState(() {
                                                      dateInpuSelectController
                                                          .text = formatTime;
                                                      data.selectedTimeRange =
                                                          result;
                                                    });
                                                  }
                                                },
                                                child: data.selectedTimeRange !=
                                                        null
                                                    ? Text(
                                                        '${data.selectedTimeRange!.startTime.format(context)} - ${data.selectedTimeRange!.endTime.format(context)}',
                                                      )
                                                    : Text(
                                                        data.subtitle,
                                                        style: const TextStyle(
                                                            color: Palette
                                                                .fontgrey),
                                                      )),
                                          ],
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                              ))
                          .toList()),
                  const SizedBox(
                    height: 12,
                  ),
                  ButtonPrimary(
                      label: "Next",
                      onPressed: () {
                        Get.toNamed(Routes.PRODUCT_PRICE);
                      })
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}