From d63f679d0d7b2facc143e6feb9fcb58074a2b0d9 Mon Sep 17 00:00:00 2001 From: Ashish Bailkeri Date: Sat, 25 Feb 2023 22:27:02 -0500 Subject: [PATCH] Sellers Filtering --- ios/Flutter/Debug.xcconfig | 1 + ios/Flutter/Release.xcconfig | 1 + ios/Podfile | 41 ++++++++++++++++ lib/auth_gate.dart | 35 +++++++++++++- lib/main_screen.dart | 9 ++-- lib/meetings.dart | 47 ++++++++++++++++++ macos/Flutter/Flutter-Debug.xcconfig | 1 + macos/Flutter/Flutter-Release.xcconfig | 1 + macos/Flutter/GeneratedPluginRegistrant.swift | 2 + macos/Podfile | 40 ++++++++++++++++ pubspec.lock | 48 +++++++++++++++++++ pubspec.yaml | 1 + .../flutter/generated_plugin_registrant.cc | 3 ++ windows/flutter/generated_plugins.cmake | 1 + 14 files changed, 226 insertions(+), 5 deletions(-) create mode 100644 ios/Podfile create mode 100644 lib/meetings.dart create mode 100644 macos/Podfile diff --git a/ios/Flutter/Debug.xcconfig b/ios/Flutter/Debug.xcconfig index 592ceee..ec97fc6 100644 --- a/ios/Flutter/Debug.xcconfig +++ b/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/ios/Flutter/Release.xcconfig b/ios/Flutter/Release.xcconfig index 592ceee..c4855bf 100644 --- a/ios/Flutter/Release.xcconfig +++ b/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/ios/Podfile b/ios/Podfile new file mode 100644 index 0000000..88359b2 --- /dev/null +++ b/ios/Podfile @@ -0,0 +1,41 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '11.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/lib/auth_gate.dart b/lib/auth_gate.dart index 1f3352a..3f49fbc 100644 --- a/lib/auth_gate.dart +++ b/lib/auth_gate.dart @@ -1,9 +1,26 @@ import 'package:firebase_auth/firebase_auth.dart'; import 'package:flutter/material.dart'; import 'package:flutterfire_ui/auth.dart'; +import 'package:firebase_database/firebase_database.dart'; +import 'package:cloud_firestore/cloud_firestore.dart'; import 'home.dart'; +final FirebaseAuth auth = FirebaseAuth.instance; + +Future addUser(String? name, String uid) async { + final CollectionReference users = + FirebaseFirestore.instance.collection('users'); + return await users + .add({ + 'name': name, + 'uid': uid, + 'swipes': 0, + }) + .then((value) => print("")) + .catchError((error) => print("ERROR ADDING DATA: $error")); +} + class AuthGate extends StatelessWidget { const AuthGate({super.key}); @@ -33,7 +50,9 @@ class AuthGate extends StatelessWidget { subtitleBuilder: (context, action) { return Padding( padding: const EdgeInsets.symmetric(vertical: 8.0), - child: action == AuthAction.signIn ? const Text('Welcome to RUSwipeShare, please sign in!') : const Text('Welcome to RUSwipeShare, please sign up!'), + child: action == AuthAction.signIn + ? const Text('Welcome to RUSwipeShare, please sign in!') + : const Text('Welcome to RUSwipeShare, please sign up!'), ); }, footerBuilder: (context, action) { @@ -48,6 +67,20 @@ class AuthGate extends StatelessWidget { ); } + User? user = auth.currentUser; + + if (user != null) { + bool isNewUser = + user.metadata.creationTime == user.metadata.lastSignInTime; + + if (isNewUser) { + final name = user.displayName; + final uid = user.uid; + + addUser(name, uid); + } + } + return const HomeScreen(); }, ); diff --git a/lib/main_screen.dart b/lib/main_screen.dart index e2af9bb..8dac8fb 100644 --- a/lib/main_screen.dart +++ b/lib/main_screen.dart @@ -1,7 +1,8 @@ import 'package:flutter/material.dart'; +import 'meetings.dart'; class MainScreen extends StatefulWidget { - const MainScreen({ Key? key }) : super(key: key); + const MainScreen({Key? key}) : super(key: key); @override _MainScreenState createState() => _MainScreenState(); @@ -12,11 +13,11 @@ class _MainScreenState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: const Text("Main Screen"), + title: const Text("Main Beens"), ), body: const Center( - child: Text("Main Screen"), + child: Text("Main Green"), ), ); } -} \ No newline at end of file +} diff --git a/lib/meetings.dart b/lib/meetings.dart new file mode 100644 index 0000000..f09c4e6 --- /dev/null +++ b/lib/meetings.dart @@ -0,0 +1,47 @@ +import 'dart:ffi'; + +import 'package:cloud_firestore/cloud_firestore.dart'; + +class TimeRange { + late DateTime startTime; + late DateTime endTime; + + TimeRange(this.startTime, this.endTime); +} + +class Seller { + String name = ""; + String uid = ""; + String location = ""; + TimeRange availableTime; + Int64 price; + + Seller(this.name, this.uid, this.location, this.availableTime, this.price); +} + +class Filter { + String? location; + Int64? price; + TimeRange? meetingTime; + + Filter(this.location, this.price, this.meetingTime); +} + +Future> getSellers(Filter filter) async { + CollectionReference users = FirebaseFirestore.instance.collection('sellers'); + List sellers = List.empty(); + + final Query query = users + .where('location', isEqualTo: filter.location) + .where('price', isEqualTo: filter.price) + .where('start-time', + isGreaterThanOrEqualTo: filter.meetingTime?.startTime) + .where('end-time', isLessThanOrEqualTo: filter.meetingTime?.endTime); + + final QuerySnapshot snapshot = await query.get(); + for (var doc in snapshot.docs) { + sellers.add(Seller(doc["name"], doc["uid"], doc["location"], + TimeRange(doc["start-time"], doc["end-time"]), doc["price"])); + } + return sellers; +} diff --git a/macos/Flutter/Flutter-Debug.xcconfig b/macos/Flutter/Flutter-Debug.xcconfig index c2efd0b..4b81f9b 100644 --- a/macos/Flutter/Flutter-Debug.xcconfig +++ b/macos/Flutter/Flutter-Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig" diff --git a/macos/Flutter/Flutter-Release.xcconfig b/macos/Flutter/Flutter-Release.xcconfig index c2efd0b..5caa9d1 100644 --- a/macos/Flutter/Flutter-Release.xcconfig +++ b/macos/Flutter/Flutter-Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig" diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 4889eec..f534431 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -10,6 +10,7 @@ import desktop_webview_auth import firebase_auth import firebase_core import firebase_database +import geolocator_apple import sign_in_with_apple import twitter_login @@ -19,6 +20,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin")) FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin")) FLTFirebaseDatabasePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseDatabasePlugin")) + GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin")) SignInWithApplePlugin.register(with: registry.registrar(forPlugin: "SignInWithApplePlugin")) TwitterLoginPlugin.register(with: registry.registrar(forPlugin: "TwitterLoginPlugin")) } diff --git a/macos/Podfile b/macos/Podfile new file mode 100644 index 0000000..049abe2 --- /dev/null +++ b/macos/Podfile @@ -0,0 +1,40 @@ +platform :osx, '10.14' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\"" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_macos_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_macos_build_settings(target) + end +end diff --git a/pubspec.lock b/pubspec.lock index 4c9d6c4..a661366 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -277,6 +277,54 @@ packages: url: "https://pub.dev" source: hosted version: "0.4.3+20" + geolocator: + dependency: "direct main" + description: + name: geolocator + sha256: "5c23f3613f50586c0bbb2b8f970240ae66b3bd992088cf60dd5ee2e6f7dde3a8" + url: "https://pub.dev" + source: hosted + version: "9.0.2" + geolocator_android: + dependency: transitive + description: + name: geolocator_android + sha256: "2ba24690aee0a3e1b6b7bd47c2711a50c874e95e4c758346589d35194adf6d6a" + url: "https://pub.dev" + source: hosted + version: "4.1.7" + geolocator_apple: + dependency: transitive + description: + name: geolocator_apple + sha256: "22b60ca3b8c0f58e6a9688ff855ee39ab813ca3f0c0609a48d282f6631266f2e" + url: "https://pub.dev" + source: hosted + version: "2.2.5" + geolocator_platform_interface: + dependency: transitive + description: + name: geolocator_platform_interface + sha256: af4d69231452f9620718588f41acc4cb58312368716bfff2e92e770b46ce6386 + url: "https://pub.dev" + source: hosted + version: "4.0.7" + geolocator_web: + dependency: transitive + description: + name: geolocator_web + sha256: f68a122da48fcfff68bbc9846bb0b74ef651afe84a1b1f6ec20939de4d6860e1 + url: "https://pub.dev" + source: hosted + version: "2.1.6" + geolocator_windows: + dependency: transitive + description: + name: geolocator_windows + sha256: f5911c88e23f48b598dd506c7c19eff0e001645bdc03bb6fecb9f4549208354d + url: "https://pub.dev" + source: hosted + version: "0.1.1" google_sign_in: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index d8761c8..e12a74b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,6 +40,7 @@ dependencies: flutterfire_ui: ^0.4.3+20 flutter_dotenv: ^5.0.2 persistent_bottom_nav_bar: any + geolocator: ^9.0.2 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 45e2647..75e23e2 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -7,8 +7,11 @@ #include "generated_plugin_registrant.h" #include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { DesktopWebviewAuthPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("DesktopWebviewAuthPlugin")); + GeolocatorWindowsRegisterWithRegistrar( + registry->GetRegistrarForPlugin("GeolocatorWindows")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 6797231..3ff9bdc 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -4,6 +4,7 @@ list(APPEND FLUTTER_PLUGIN_LIST desktop_webview_auth + geolocator_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST