From 9125041f18cb4bf3ffbc7c3329cb18459f750b35 Mon Sep 17 00:00:00 2001 From: Phani Pavan K Date: Sun, 20 Oct 2024 12:12:32 +0530 Subject: [PATCH 1/4] add about page --- lib/main.dart | 10 ++++++++-- lib/views/about.dart | 21 +++++++++++++++++++++ lib/views/homePage.dart | 33 ++++++++++++++++++++++++++++++--- pubspec.yaml | 10 ++++------ 4 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 lib/views/about.dart diff --git a/lib/main.dart b/lib/main.dart index f6ac6cf..7a4eb2b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:iiitb_menu/models/globalModel.dart'; import 'package:iiitb_menu/views/homePage.dart'; import 'package:provider/provider.dart'; +import "package:iiitb_menu/views/about.dart"; void main() { WidgetsFlutterBinding.ensureInitialized(); @@ -20,8 +21,13 @@ class MainApp extends StatelessWidget { builder: (BuildContext context, child) { return MaterialApp( title: "IIITB Menu", - home: const HomePage(), - theme: ThemeData(useMaterial3: false), + routes: { + "/": (context) => HomePage(), + "/info": (context) => AboutPage(), + }, + initialRoute: "/", + // home: const HomePage(), + theme: ThemeData(useMaterial3: true), ); }, ); diff --git a/lib/views/about.dart b/lib/views/about.dart new file mode 100644 index 0000000..4249f08 --- /dev/null +++ b/lib/views/about.dart @@ -0,0 +1,21 @@ +import 'package:flutter/material.dart'; + +class AboutPage extends StatelessWidget { + const AboutPage({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: const Text("About Page")), + body: const Column( + children: [ + Image(image: AssetImage("assets/plate.png")), + Text( + "IIIT Bangalore Unofficial Mess Menu", + style: TextStyle(fontSize: 50), + ) + ], + ), + ); + } +} diff --git a/lib/views/homePage.dart b/lib/views/homePage.dart index 035a0eb..be2981d 100644 --- a/lib/views/homePage.dart +++ b/lib/views/homePage.dart @@ -25,13 +25,40 @@ class HomePage extends StatelessWidget { return Consumer( builder: (BuildContext context, GlobalModel data, Widget? child) { return Scaffold( + drawer: Drawer( + child: ListView( + children: [ + ListTile( + leading: Icon(Icons.menu), + title: Text("Menu"), + onTap: () { + Navigator.pop(context); + }), + ListTile( + leading: Icon(Icons.star), + title: Text("Specials"), + ), + Divider(), + ListTile( + leading: Icon(Icons.settings), + title: Text("Settings"), + ), + ListTile( + leading: Icon(Icons.info), + title: Text("About App"), + onTap: () { + Navigator.pushNamed(context, "/info"); + }), + ], + ), + ), appBar: AppBar( title: Text("Daily ${data.menuTime} Menu"), bottom: TabBar( controller: cont, - splashFactory: NoSplash.splashFactory, - indicator: const UnderlineTabIndicator( - insets: EdgeInsets.fromLTRB(10, 3, 10, 3)), + // splashFactory: InkSplash.splashFactory, + // indicator: const UnderlineTabIndicator( + // insets: EdgeInsets.fromLTRB(10, 3, 10, 3)), onTap: (int index) { data.setMenuTime(index); }, diff --git a/pubspec.yaml b/pubspec.yaml index 58cc3ab..a3a7687 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: iiitb_menu description: IIITB Bi-Weekly Menu # The following line prevents the package from being accidentally published to # pub.dev using `flutter pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: "none" # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 @@ -19,7 +19,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: '>=3.1.0 <4.0.0' + sdk: ">=3.1.0 <4.0.0" # Dependencies specify other packages that your package needs in order to work. # To automatically upgrade your package dependencies to the latest versions @@ -31,10 +31,9 @@ dependencies: flutter: sdk: flutter - # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. - cupertino_icons: ^1.0.2 + # cupertino_icons: ^1.0.2 provider: ^6.0.5 crypto: ^3.0.3 intl: ^0.18.1 @@ -43,7 +42,7 @@ dependencies: path_provider: # localstorage: ^4.0.1+4 shared_preferences: ^2.2.0 - # sembast: + # sembast: dev_dependencies: flutter_test: @@ -61,7 +60,6 @@ dev_dependencies: # The following section is specific to Flutter packages. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. From ca13f575a23bad0d2927366bfa56671457d834a3 Mon Sep 17 00:00:00 2001 From: Phani Pavan K Date: Fri, 25 Oct 2024 15:20:36 +0530 Subject: [PATCH 2/4] add new data loading algo --- lib/models/globalModel.dart | 63 ++++++++++++++++++++++++++++++++++++- lib/views/homePage.dart | 7 +++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/lib/models/globalModel.dart b/lib/models/globalModel.dart index c41d96b..b0a7a5d 100644 --- a/lib/models/globalModel.dart +++ b/lib/models/globalModel.dart @@ -17,15 +17,27 @@ class GlobalModel extends ChangeNotifier { GlobalModel() { // print("In constructor"); - GlobalModel.loadData().then((value) { + GlobalModel.loadData2().then((value) { mainData = value; if (this.mainData["dates"].keys.contains(this.date)) { this.menuAvailable = DataStatus.Loaded; + } else { + this.menuAvailable = DataStatus.NotFound; } notifyListeners(); }); } + updateCall() async { + this.mainData = await GlobalModel.updateLocal(); + if (this.mainData["dates"].keys.contains(this.date)) { + this.menuAvailable = DataStatus.Loaded; + } else { + this.menuAvailable = DataStatus.NotFound; + } + notifyListeners(); + } + static Future getLatestHash() async { try { Response hashRequest = await get(Uri.parse(hashLink)); @@ -52,6 +64,55 @@ class GlobalModel extends ChangeNotifier { } } + static Future updateLocal() async { + // Set main data and return the data to be used in constructor + String remoteHash = await GlobalModel.getLatestHash(); + final SharedPreferences prefs = await SharedPreferences.getInstance(); + String? rawData = prefs.getString(storageKey); + rawData ??= ""; + String rawHash = md5.convert(utf8.encode(rawData)).toString(); + if (remoteHash != rawHash) { + print("Local data is out of date, updating local"); + // Donwload new data and save it. + rawData = await getLatestData(); + Map returnData = jsonDecode(rawData); + prefs.setString(storageKey, rawData); + return returnData; + } else { + // return the same data + print("Local data is up to date"); + return jsonDecode(rawData); + } + } + + static Future loadData2() async { + /* New flow for fetching data: + Get cached data into a var + if theres nothing: + get data + generate hash and store both the data and hash + else: + return the current data + + Move the download and get hash part to new method - done + + create a new method for updating the current data. + This checks for update and saves new data to sharedprefs if necessary, + */ + late Map returnData; + final SharedPreferences prefs = await SharedPreferences.getInstance(); + String? rawData; + rawData = prefs.getString(storageKey); + if (rawData != null) { + print("Some data found"); + returnData = jsonDecode(rawData); + return returnData; + } else { + print("Data Not Found"); + return GlobalModel.updateLocal(); + } + } + static Future loadData() async { late Map returnData; final SharedPreferences prefs = await SharedPreferences.getInstance(); diff --git a/lib/views/homePage.dart b/lib/views/homePage.dart index be2981d..342d9df 100644 --- a/lib/views/homePage.dart +++ b/lib/views/homePage.dart @@ -69,6 +69,13 @@ class HomePage extends StatelessWidget { Tab(icon: Icon(Icons.dinner_dining_outlined)) ]), actions: [ + InkWell( + splashFactory: NoSplash.splashFactory, + onTap: () { + data.updateCall(); + }, + child: const Icon(Icons.refresh), + ), InkWell( splashFactory: NoSplash.splashFactory, onTap: () { From fdff2bcfeeb2e2370d5885649df7b7956e3b8b7d Mon Sep 17 00:00:00 2001 From: Phani Pavan K Date: Fri, 25 Oct 2024 16:37:20 +0530 Subject: [PATCH 3/4] update about page, add share button but not working --- lib/models/globalModel.dart | 2 + lib/views/about.dart | 25 +++- lib/views/homePage.dart | 39 ++++-- linux/flutter/generated_plugin_registrant.cc | 4 + linux/flutter/generated_plugins.cmake | 1 + macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.yaml | 1 + web/index.html | 120 ++++++++++-------- .../flutter/generated_plugin_registrant.cc | 6 + windows/flutter/generated_plugins.cmake | 2 + 10 files changed, 135 insertions(+), 67 deletions(-) diff --git a/lib/models/globalModel.dart b/lib/models/globalModel.dart index b0a7a5d..89756b9 100644 --- a/lib/models/globalModel.dart +++ b/lib/models/globalModel.dart @@ -73,6 +73,8 @@ class GlobalModel extends ChangeNotifier { String rawHash = md5.convert(utf8.encode(rawData)).toString(); if (remoteHash != rawHash) { print("Local data is out of date, updating local"); + print("Old Hash: $rawHash"); + print("New Hash: $remoteHash"); // Donwload new data and save it. rawData = await getLatestData(); Map returnData = jsonDecode(rawData); diff --git a/lib/views/about.dart b/lib/views/about.dart index 4249f08..bc3b183 100644 --- a/lib/views/about.dart +++ b/lib/views/about.dart @@ -6,13 +6,28 @@ class AboutPage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( - appBar: AppBar(title: const Text("About Page")), + appBar: AppBar(title: const Text("About")), body: const Column( children: [ - Image(image: AssetImage("assets/plate.png")), - Text( - "IIIT Bangalore Unofficial Mess Menu", - style: TextStyle(fontSize: 50), + Padding( + padding: EdgeInsets.only(left: 100, right: 100, top: 50), + child: Image(image: AssetImage("assets/plate.png")), + ), + Center( + child: Text( + "IIIT Bangalore's Unofficial Menu App", + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 50, + ), + ), + ), + Center( + child: Text("Proud Ass Web 1.0 App built with Flutter"), + ), + Center( + child: Text( + "Menu updates every other Tuesday or when FoodComm does it."), ) ], ), diff --git a/lib/views/homePage.dart b/lib/views/homePage.dart index 342d9df..183d900 100644 --- a/lib/views/homePage.dart +++ b/lib/views/homePage.dart @@ -6,6 +6,7 @@ import "package:iiitb_menu/models/globalModel.dart"; import "package:iiitb_menu/models/initialPageIndexFunction.dart"; import "package:iiitb_menu/views/menuListView.dart"; import "package:provider/provider.dart"; +import "package:share_plus/share_plus.dart"; class HomePage extends StatelessWidget { const HomePage({Key? key}) : super(key: key); @@ -29,23 +30,35 @@ class HomePage extends StatelessWidget { child: ListView( children: [ ListTile( - leading: Icon(Icons.menu), + leading: Icon(Icons.arrow_back), title: Text("Menu"), onTap: () { Navigator.pop(context); }), + // ListTile( + // leading: Icon(Icons.star), + // title: Text("Specials"), + // ), + const Divider(), + // ListTile( + // leading: Icon(Icons.settings), + // title: Text("Settings"), + // ), ListTile( - leading: Icon(Icons.star), - title: Text("Specials"), - ), - Divider(), - ListTile( - leading: Icon(Icons.settings), - title: Text("Settings"), - ), + leading: const Icon(Icons.share_rounded), + title: const Text("Share"), + onTap: () { + var ret = Share.share( + "Hey, use this to track IIITB's Mess Menu. https://kphanipavan.github.io/IIITB_Menu/", + // subject: "IIITB Menu App", + ); + ret.then((value) { + print(value.status); + }); + }), ListTile( leading: Icon(Icons.info), - title: Text("About App"), + title: Text("About"), onTap: () { Navigator.pushNamed(context, "/info"); }), @@ -53,7 +66,7 @@ class HomePage extends StatelessWidget { ), ), appBar: AppBar( - title: Text("Daily ${data.menuTime} Menu"), + title: Text(data.menuTime), bottom: TabBar( controller: cont, // splashFactory: InkSplash.splashFactory, @@ -74,7 +87,9 @@ class HomePage extends StatelessWidget { onTap: () { data.updateCall(); }, - child: const Icon(Icons.refresh), + child: Icon(data.menuAvailable == DataStatus.Loading + ? Icons.downloading_rounded + : Icons.update_rounded), ), InkWell( splashFactory: NoSplash.splashFactory, diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index e71a16d..f6f23bf 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,6 +6,10 @@ #include "generated_plugin_registrant.h" +#include void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin"); + url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 2e1de87..f16b4c3 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + url_launcher_linux ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index b8e2b22..c3f782e 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -6,9 +6,11 @@ import FlutterMacOS import Foundation import path_provider_foundation +import share_plus import shared_preferences_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) + SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) } diff --git a/pubspec.yaml b/pubspec.yaml index a3a7687..807e9b2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: path_provider: # localstorage: ^4.0.1+4 shared_preferences: ^2.2.0 + share_plus: ^10.1.1 # sembast: dev_dependencies: diff --git a/web/index.html b/web/index.html index 6ee2f01..0fd9fc6 100644 --- a/web/index.html +++ b/web/index.html @@ -1,8 +1,7 @@ - + - - - - + - - - + + + - - - - - + + + + + - - - - - - - iiitb_menu - + + + + + + + iiitb_menu + - - - - + + + + - - - - - \ No newline at end of file + + + + diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 8b6d468..c3384ec 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,6 +6,12 @@ #include "generated_plugin_registrant.h" +#include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + SharePlusWindowsPluginCApiRegisterWithRegistrar( + registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi")); + UrlLauncherWindowsRegisterWithRegistrar( + registry->GetRegistrarForPlugin("UrlLauncherWindows")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index b93c4c3..01d3836 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,8 @@ # list(APPEND FLUTTER_PLUGIN_LIST + share_plus + url_launcher_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST From 3db2f94373ad1aff2fc202a3c16195c0ba89638d Mon Sep 17 00:00:00 2001 From: Phani Pavan Kambhampati <60005847+kphanipavan@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:16:02 +0530 Subject: [PATCH 4/4] temp disable apk build --- .github/workflows/gh-pages.yml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 43fce4c..41b9315 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -73,8 +73,8 @@ jobs: - name: Build Web Release run: flutter build web --base-href "/$HREFREPLACE/" --web-renderer canvaskit --no-web-resources-cdn - - name: Build Android Release - run: flutter build apk --split-per-abi --release --no-track-widget-creation --analyze-size --target-platform "android-arm64" + # - name: Build Android Release + # run: flutter build apk --split-per-abi --release --no-track-widget-creation --analyze-size --target-platform "android-arm64" - name: Fix PWA Offline Support run: | @@ -83,15 +83,15 @@ jobs: ./fixOfflinePWA.sh cat ./build/web/flutter_service_worker.js - - name: Create Release - uses: marvinpinto/action-automatic-releases@v1.2.1 - with: - repo_token: "${{ secrets.GITHUB_TOKEN }}" - automatic_release_tag: "latest" - prerelease: true - draft: false - title: "Git Build" - files: build/app/outputs/flutter-apk/app-arm64-v8a-release.apk + # - name: Create Release + # uses: marvinpinto/action-automatic-releases@v1.2.1 + # with: + # repo_token: "${{ secrets.GITHUB_TOKEN }}" + # automatic_release_tag: "latest" + # prerelease: true + # draft: false + # title: "Git Build" + # files: build/app/outputs/flutter-apk/app-arm64-v8a-release.apk - name: Upload production-ready build files uses: actions/upload-artifact@v3.1.2