solex
 · CEO at DropDeli

Opening and closing time function

Custom Code
  • Hello team Good day 😊

  • Please am currently building an app that required opening and closing time function from everyday in flutterflow and I have actually made some code but is not working as I expected because it's taking the date and time instead of time only and that made the custom code not to work as I expected... Here's the code below ⬇⬇⬇

  • Please I need some help with this please

  • import 'dart:convert';
    import 'dart:math' as math;
    
    import 'package:flutter/material.dart';
    import 'package:google_fonts/google_fonts.dart';
    import 'package:intl/intl.dart';
    import 'package:timeago/timeago.dart' as timeago;
    import '/flutter_flow/lat_lng.dart';
    import '/flutter_flow/place.dart';
    import '/flutter_flow/uploaded_file.dart';
    import '/flutter_flow/custom_functions.dart';
    import '/backend/backend.dart';
    import 'package:cloud_firestore/cloud_firestore.dart';
    import '/backend/schema/structs/index.dart';
    import '/auth/firebase_auth/auth_util.dart';
    
    bool? openingTimeClosingTime(
      DateTime? monOpen,
      DateTime? monClose,
      DateTime? turOpen,
      DateTime? turClose,
      DateTime? wenOpen,
      DateTime? wenClose,
      DateTime? thurOpen,
      DateTime? thurClose,
      DateTime? fryOpen,
      DateTime? fryClose,
      DateTime? sarOpen,
      DateTime? sarClose,
      DateTime? sunOpen,
      DateTime? sunClose,
    ) {
      /// MODIFY CODE ONLY BELOW THIS LINE
    
      // If opening time is within the closing time return true. In everyday Like 8 am to 10pm
      DateTime now = DateTime.now();
      int dayOfWeek = now.weekday;
    
      switch (dayOfWeek) {
        case 1:
          return monOpen != null &&
              monClose != null &&
              now.isAfter(monOpen) &&
              now.isBefore(monClose);
        case 2:
          return turOpen != null &&
              turClose != null &&
              now.isAfter(turOpen) &&
              now.isBefore(turClose);
        case 3:
          return wenOpen != null &&
              wenClose != null &&
              now.isAfter(wenOpen) &&
              now.isBefore(wenClose);
        case 4:
          return thurOpen != null &&
              thurClose != null &&
              now.isAfter(thurOpen) &&
              now.isBefore(thurClose);
        case 5:
          return fryOpen != null &&
              fryClose != null &&
              now.isAfter(fryOpen) &&
              now.isBefore(fryClose);
        case 6:
          return sarOpen != null &&
              sarClose != null &&
              now.isAfter(sarOpen) &&
              now.isBefore(sarClose);
        case 7:
          return sunOpen != null &&
              sunClose != null &&
              now.isAfter(sunOpen) &&
              now.isBefore(sunClose);
        default:
          return false;
      }
    
      /// MODIFY CODE ONLY ABOVE THIS LINE
    }
What have you tried so far?

I have a code already but is not working like example if today is Monday and I set Monday opening and closing time it will work but next week Monday it won't work because it's not the same date but the same time.. So I think the date is affecting it 🙏

Did you check FlutterFlow's Documentation for this topic?
Yes
8 replies