├── .vscode
└── settings.json
├── example
├── linux
│ ├── .gitignore
│ ├── main.cc
│ ├── flutter
│ │ ├── generated_plugin_registrant.cc
│ │ ├── generated_plugin_registrant.h
│ │ ├── generated_plugins.cmake
│ │ └── CMakeLists.txt
│ ├── my_application.h
│ ├── my_application.cc
│ └── CMakeLists.txt
├── ios
│ ├── Runner
│ │ ├── Runner-Bridging-Header.h
│ │ ├── Assets.xcassets
│ │ │ ├── LaunchImage.imageset
│ │ │ │ ├── LaunchImage.png
│ │ │ │ ├── LaunchImage@2x.png
│ │ │ │ ├── LaunchImage@3x.png
│ │ │ │ ├── README.md
│ │ │ │ └── Contents.json
│ │ │ └── AppIcon.appiconset
│ │ │ │ ├── Icon-App-20x20@1x.png
│ │ │ │ ├── Icon-App-20x20@2x.png
│ │ │ │ ├── Icon-App-20x20@3x.png
│ │ │ │ ├── Icon-App-29x29@1x.png
│ │ │ │ ├── Icon-App-29x29@2x.png
│ │ │ │ ├── Icon-App-29x29@3x.png
│ │ │ │ ├── Icon-App-40x40@1x.png
│ │ │ │ ├── Icon-App-40x40@2x.png
│ │ │ │ ├── Icon-App-40x40@3x.png
│ │ │ │ ├── Icon-App-60x60@2x.png
│ │ │ │ ├── Icon-App-60x60@3x.png
│ │ │ │ ├── Icon-App-76x76@1x.png
│ │ │ │ ├── Icon-App-76x76@2x.png
│ │ │ │ ├── Icon-App-1024x1024@1x.png
│ │ │ │ ├── Icon-App-83.5x83.5@2x.png
│ │ │ │ └── Contents.json
│ │ ├── AppDelegate.swift
│ │ ├── Base.lproj
│ │ │ ├── Main.storyboard
│ │ │ └── LaunchScreen.storyboard
│ │ └── Info.plist
│ ├── Flutter
│ │ ├── Debug.xcconfig
│ │ ├── Release.xcconfig
│ │ └── AppFrameworkInfo.plist
│ ├── Runner.xcodeproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcshareddata
│ │ │ │ ├── WorkspaceSettings.xcsettings
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ └── Runner.xcscheme
│ ├── Runner.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ ├── WorkspaceSettings.xcsettings
│ │ │ └── IDEWorkspaceChecks.plist
│ ├── RunnerTests
│ │ └── RunnerTests.swift
│ ├── .gitignore
│ └── Podfile
├── web
│ ├── favicon.png
│ ├── icons
│ │ ├── Icon-192.png
│ │ ├── Icon-512.png
│ │ ├── Icon-maskable-192.png
│ │ └── Icon-maskable-512.png
│ ├── manifest.json
│ └── index.html
├── android
│ ├── gradle.properties
│ ├── app
│ │ ├── src
│ │ │ ├── main
│ │ │ │ ├── res
│ │ │ │ │ ├── mipmap-hdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-mdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ │ │ └── ic_launcher.png
│ │ │ │ │ ├── drawable
│ │ │ │ │ │ └── launch_background.xml
│ │ │ │ │ ├── drawable-v21
│ │ │ │ │ │ └── launch_background.xml
│ │ │ │ │ ├── values
│ │ │ │ │ │ └── styles.xml
│ │ │ │ │ └── values-night
│ │ │ │ │ │ └── styles.xml
│ │ │ │ ├── kotlin
│ │ │ │ │ └── com
│ │ │ │ │ │ └── example
│ │ │ │ │ │ └── example
│ │ │ │ │ │ └── MainActivity.kt
│ │ │ │ └── AndroidManifest.xml
│ │ │ ├── debug
│ │ │ │ └── AndroidManifest.xml
│ │ │ └── profile
│ │ │ │ └── AndroidManifest.xml
│ │ └── build.gradle
│ ├── gradle
│ │ └── wrapper
│ │ │ └── gradle-wrapper.properties
│ ├── .gitignore
│ ├── build.gradle
│ └── settings.gradle
├── macos
│ ├── Runner
│ │ ├── Configs
│ │ │ ├── Debug.xcconfig
│ │ │ ├── Release.xcconfig
│ │ │ ├── Warnings.xcconfig
│ │ │ └── AppInfo.xcconfig
│ │ ├── Assets.xcassets
│ │ │ └── AppIcon.appiconset
│ │ │ │ ├── app_icon_16.png
│ │ │ │ ├── app_icon_32.png
│ │ │ │ ├── app_icon_64.png
│ │ │ │ ├── app_icon_1024.png
│ │ │ │ ├── app_icon_128.png
│ │ │ │ ├── app_icon_256.png
│ │ │ │ ├── app_icon_512.png
│ │ │ │ └── Contents.json
│ │ ├── AppDelegate.swift
│ │ ├── Release.entitlements
│ │ ├── DebugProfile.entitlements
│ │ ├── MainFlutterWindow.swift
│ │ └── Info.plist
│ ├── .gitignore
│ ├── Flutter
│ │ ├── Flutter-Debug.xcconfig
│ │ ├── Flutter-Release.xcconfig
│ │ └── GeneratedPluginRegistrant.swift
│ ├── Runner.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcshareddata
│ │ │ └── IDEWorkspaceChecks.plist
│ ├── Runner.xcodeproj
│ │ ├── project.xcworkspace
│ │ │ └── xcshareddata
│ │ │ │ └── IDEWorkspaceChecks.plist
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ └── Runner.xcscheme
│ ├── RunnerTests
│ │ └── RunnerTests.swift
│ └── Podfile
├── windows
│ ├── runner
│ │ ├── resources
│ │ │ └── app_icon.ico
│ │ ├── resource.h
│ │ ├── utils.h
│ │ ├── runner.exe.manifest
│ │ ├── flutter_window.h
│ │ ├── main.cpp
│ │ ├── CMakeLists.txt
│ │ ├── utils.cpp
│ │ ├── flutter_window.cpp
│ │ ├── Runner.rc
│ │ ├── win32_window.h
│ │ └── win32_window.cpp
│ ├── flutter
│ │ ├── generated_plugin_registrant.cc
│ │ ├── generated_plugin_registrant.h
│ │ ├── generated_plugins.cmake
│ │ └── CMakeLists.txt
│ ├── .gitignore
│ └── CMakeLists.txt
├── README.md
├── lib
│ ├── routes
│ │ └── routes.dart
│ ├── providers
│ │ ├── products
│ │ │ ├── products_provider.dart
│ │ │ └── products_provider.g.dart
│ │ └── cart
│ │ │ └── cart_provider.dart
│ ├── models
│ │ ├── products_model.dart
│ │ ├── products_model.g.dart
│ │ └── products_model.freezed.dart
│ ├── main.dart
│ └── views
│ │ ├── products_view.dart
│ │ └── cart_view.dart
├── .gitignore
├── test
│ └── widget_test.dart
├── analysis_options.yaml
├── .metadata
└── pubspec.yaml
├── logo.png
├── flutter_cart(sample).gif
├── lib
├── flutter_cart.dart
├── constants
│ └── shared_pref_constants.dart
├── model
│ ├── cart_model.dart
│ ├── cart_model.g.dart
│ └── cart_model.freezed.dart
└── cart.dart
├── .metadata
├── .github
└── ISSUE_TEMPLATE
│ ├── feature_request.md
│ └── bug_report.md
├── CHANGELOG.md
├── LICENSE
├── .gitignore
├── pubspec.yaml
├── README.md
└── test
└── flutter_cart_test.dart
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/example/linux/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/ephemeral
2 |
--------------------------------------------------------------------------------
/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/logo.png
--------------------------------------------------------------------------------
/example/ios/Runner/Runner-Bridging-Header.h:
--------------------------------------------------------------------------------
1 | #import "GeneratedPluginRegistrant.h"
2 |
--------------------------------------------------------------------------------
/example/web/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/web/favicon.png
--------------------------------------------------------------------------------
/flutter_cart(sample).gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/flutter_cart(sample).gif
--------------------------------------------------------------------------------
/lib/flutter_cart.dart:
--------------------------------------------------------------------------------
1 | library flutter_cart;
2 |
3 | export 'cart.dart';
4 | export 'model/cart_model.dart';
5 |
--------------------------------------------------------------------------------
/example/web/icons/Icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/web/icons/Icon-192.png
--------------------------------------------------------------------------------
/example/web/icons/Icon-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/web/icons/Icon-512.png
--------------------------------------------------------------------------------
/example/android/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx4G
2 | android.useAndroidX=true
3 | android.enableJetifier=true
4 |
--------------------------------------------------------------------------------
/example/macos/Runner/Configs/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "../../Flutter/Flutter-Debug.xcconfig"
2 | #include "Warnings.xcconfig"
3 |
--------------------------------------------------------------------------------
/example/macos/Runner/Configs/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "../../Flutter/Flutter-Release.xcconfig"
2 | #include "Warnings.xcconfig"
3 |
--------------------------------------------------------------------------------
/example/macos/.gitignore:
--------------------------------------------------------------------------------
1 | # Flutter-related
2 | **/Flutter/ephemeral/
3 | **/Pods/
4 |
5 | # Xcode-related
6 | **/dgph
7 | **/xcuserdata/
8 |
--------------------------------------------------------------------------------
/example/web/icons/Icon-maskable-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/web/icons/Icon-maskable-192.png
--------------------------------------------------------------------------------
/example/web/icons/Icon-maskable-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/web/icons/Icon-maskable-512.png
--------------------------------------------------------------------------------
/example/ios/Flutter/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
2 | #include "Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/example/ios/Flutter/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
2 | #include "Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/example/windows/runner/resources/app_icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/windows/runner/resources/app_icon.ico
--------------------------------------------------------------------------------
/example/macos/Flutter/Flutter-Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
2 | #include "ephemeral/Flutter-Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/macos/Flutter/Flutter-Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
2 | #include "ephemeral/Flutter-Generated.xcconfig"
3 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png
--------------------------------------------------------------------------------
/lib/constants/shared_pref_constants.dart:
--------------------------------------------------------------------------------
1 | class SharedPreferenceConstants {
2 | static final isPersistenceSupportEnabled = 'isOfflineSupportEnabled';
3 | static final persistCart = 'persistCart';
4 | }
5 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@2x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage@3x.png
--------------------------------------------------------------------------------
/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.example.example
2 |
3 | import io.flutter.embedding.android.FlutterActivity
4 |
5 | class MainActivity: FlutterActivity() {
6 | }
7 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/osamaasifoak/flutter_cart/HEAD/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png
--------------------------------------------------------------------------------
/example/linux/main.cc:
--------------------------------------------------------------------------------
1 | #include "my_application.h"
2 |
3 | int main(int argc, char** argv) {
4 | g_autoptr(MyApplication) app = my_application_new();
5 | return g_application_run(G_APPLICATION(app), argc, argv);
6 | }
7 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/macos/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/linux/flutter/generated_plugin_registrant.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #include "generated_plugin_registrant.h"
8 |
9 |
10 | void fl_register_plugins(FlPluginRegistry* registry) {
11 | }
12 |
--------------------------------------------------------------------------------
/example/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | zipStoreBase=GRADLE_USER_HOME
4 | zipStorePath=wrapper/dists
5 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
6 |
--------------------------------------------------------------------------------
/example/windows/flutter/generated_plugin_registrant.cc:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #include "generated_plugin_registrant.h"
8 |
9 |
10 | void RegisterPlugins(flutter::PluginRegistry* registry) {
11 | }
12 |
--------------------------------------------------------------------------------
/example/macos/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import Cocoa
2 | import FlutterMacOS
3 |
4 | @NSApplicationMain
5 | class AppDelegate: FlutterAppDelegate {
6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
7 | return true
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/example/macos/Runner/Release.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PreviewsEnabled
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/example/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: bbfbf1770cca2da7c82e887e4e4af910034800b6
8 | channel: stable
9 |
10 | project_type: package
11 |
--------------------------------------------------------------------------------
/example/android/.gitignore:
--------------------------------------------------------------------------------
1 | gradle-wrapper.jar
2 | /.gradle
3 | /captures/
4 | /gradlew
5 | /gradlew.bat
6 | /local.properties
7 | GeneratedPluginRegistrant.java
8 |
9 | # Remember to never publicly share your keystore.
10 | # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
11 | key.properties
12 | **/*.keystore
13 | **/*.jks
14 |
--------------------------------------------------------------------------------
/example/ios/RunnerTests/RunnerTests.swift:
--------------------------------------------------------------------------------
1 | import Flutter
2 | import UIKit
3 | import XCTest
4 |
5 | class RunnerTests: XCTestCase {
6 |
7 | func testExample() {
8 | // If you add code to the Runner application, consider adding tests here.
9 | // See https://developer.apple.com/documentation/xctest for more information about using XCTest.
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/example/macos/Flutter/GeneratedPluginRegistrant.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | import FlutterMacOS
6 | import Foundation
7 |
8 | import shared_preferences_foundation
9 |
10 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
11 | SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
12 | }
13 |
--------------------------------------------------------------------------------
/example/macos/RunnerTests/RunnerTests.swift:
--------------------------------------------------------------------------------
1 | import FlutterMacOS
2 | import Cocoa
3 | import XCTest
4 |
5 | class RunnerTests: XCTestCase {
6 |
7 | func testExample() {
8 | // If you add code to the Runner application, consider adding tests here.
9 | // See https://developer.apple.com/documentation/xctest for more information about using XCTest.
10 | }
11 |
12 | }
13 |
--------------------------------------------------------------------------------
/example/windows/.gitignore:
--------------------------------------------------------------------------------
1 | flutter/ephemeral/
2 |
3 | # Visual Studio user-specific files.
4 | *.suo
5 | *.user
6 | *.userosscache
7 | *.sln.docstates
8 |
9 | # Visual Studio build-related files.
10 | x64/
11 | x86/
12 |
13 | # Visual Studio cache files
14 | # files ending in .cache can be ignored
15 | *.[Cc]ache
16 | # but keep track of directories ending in .cache
17 | !*.[Cc]ache/
18 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md:
--------------------------------------------------------------------------------
1 | # Launch Screen Assets
2 |
3 | You can customize the launch screen with your own desired assets by replacing the image files in this directory.
4 |
5 | You can also do it by opening your Flutter project's Xcode project with `open ios/Runner.xcworkspace`, selecting `Runner/Assets.xcassets` in the Project Navigator and dropping in the desired images.
--------------------------------------------------------------------------------
/example/linux/flutter/generated_plugin_registrant.h:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #ifndef GENERATED_PLUGIN_REGISTRANT_
8 | #define GENERATED_PLUGIN_REGISTRANT_
9 |
10 | #include
11 |
12 | // Registers Flutter plugins.
13 | void fl_register_plugins(FlPluginRegistry* registry);
14 |
15 | #endif // GENERATED_PLUGIN_REGISTRANT_
16 |
--------------------------------------------------------------------------------
/example/windows/flutter/generated_plugin_registrant.h:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | // clang-format off
6 |
7 | #ifndef GENERATED_PLUGIN_REGISTRANT_
8 | #define GENERATED_PLUGIN_REGISTRANT_
9 |
10 | #include
11 |
12 | // Registers Flutter plugins.
13 | void RegisterPlugins(flutter::PluginRegistry* registry);
14 |
15 | #endif // GENERATED_PLUGIN_REGISTRANT_
16 |
--------------------------------------------------------------------------------
/example/android/app/src/debug/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/android/app/src/profile/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/example/macos/Runner/DebugProfile.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 | com.apple.security.cs.allow-jit
8 |
9 | com.apple.security.network.server
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/example/ios/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import UIKit
2 | import Flutter
3 |
4 | @UIApplicationMain
5 | @objc class AppDelegate: FlutterAppDelegate {
6 | override func application(
7 | _ application: UIApplication,
8 | didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
9 | ) -> Bool {
10 | GeneratedPluginRegistrant.register(with: self)
11 | return super.application(application, didFinishLaunchingWithOptions: launchOptions)
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/example/macos/Runner/MainFlutterWindow.swift:
--------------------------------------------------------------------------------
1 | import Cocoa
2 | import FlutterMacOS
3 |
4 | class MainFlutterWindow: NSWindow {
5 | override func awakeFromNib() {
6 | let flutterViewController = FlutterViewController()
7 | let windowFrame = self.frame
8 | self.contentViewController = flutterViewController
9 | self.setFrame(windowFrame, display: true)
10 |
11 | RegisterGeneratedPlugins(registry: flutterViewController)
12 |
13 | super.awakeFromNib()
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/example/linux/my_application.h:
--------------------------------------------------------------------------------
1 | #ifndef FLUTTER_MY_APPLICATION_H_
2 | #define FLUTTER_MY_APPLICATION_H_
3 |
4 | #include
5 |
6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION,
7 | GtkApplication)
8 |
9 | /**
10 | * my_application_new:
11 | *
12 | * Creates a new Flutter-based application.
13 | *
14 | * Returns: a new #MyApplication.
15 | */
16 | MyApplication* my_application_new();
17 |
18 | #endif // FLUTTER_MY_APPLICATION_H_
19 |
--------------------------------------------------------------------------------
/example/windows/runner/resource.h:
--------------------------------------------------------------------------------
1 | //{{NO_DEPENDENCIES}}
2 | // Microsoft Visual C++ generated include file.
3 | // Used by Runner.rc
4 | //
5 | #define IDI_APP_ICON 101
6 |
7 | // Next default values for new objects
8 | //
9 | #ifdef APSTUDIO_INVOKED
10 | #ifndef APSTUDIO_READONLY_SYMBOLS
11 | #define _APS_NEXT_RESOURCE_VALUE 102
12 | #define _APS_NEXT_COMMAND_VALUE 40001
13 | #define _APS_NEXT_CONTROL_VALUE 1001
14 | #define _APS_NEXT_SYMED_VALUE 101
15 | #endif
16 | #endif
17 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/drawable/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/drawable-v21/launch_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
12 |
13 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "LaunchImage.png",
6 | "scale" : "1x"
7 | },
8 | {
9 | "idiom" : "universal",
10 | "filename" : "LaunchImage@2x.png",
11 | "scale" : "2x"
12 | },
13 | {
14 | "idiom" : "universal",
15 | "filename" : "LaunchImage@3x.png",
16 | "scale" : "3x"
17 | }
18 | ],
19 | "info" : {
20 | "version" : 1,
21 | "author" : "xcode"
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/example/README.md:
--------------------------------------------------------------------------------
1 | # example
2 |
3 | A new Flutter project.
4 |
5 | ## Getting Started
6 |
7 | This project is a starting point for a Flutter application.
8 |
9 | A few resources to get you started if this is your first Flutter project:
10 |
11 | - [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
12 | - [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
13 |
14 | For help getting started with Flutter development, view the
15 | [online documentation](https://docs.flutter.dev/), which offers tutorials,
16 | samples, guidance on mobile development, and a full API reference.
17 |
--------------------------------------------------------------------------------
/example/macos/Runner/Configs/Warnings.xcconfig:
--------------------------------------------------------------------------------
1 | WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings
2 | GCC_WARN_UNDECLARED_SELECTOR = YES
3 | CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES
4 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE
5 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES
6 | CLANG_WARN_PRAGMA_PACK = YES
7 | CLANG_WARN_STRICT_PROTOTYPES = YES
8 | CLANG_WARN_COMMA = YES
9 | GCC_WARN_STRICT_SELECTOR_MATCH = YES
10 | CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES
11 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES
12 | GCC_WARN_SHADOW = YES
13 | CLANG_WARN_UNREACHABLE_CODE = YES
14 |
--------------------------------------------------------------------------------
/example/macos/Runner/Configs/AppInfo.xcconfig:
--------------------------------------------------------------------------------
1 | // Application-level settings for the Runner target.
2 | //
3 | // This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the
4 | // future. If not, the values below would default to using the project name when this becomes a
5 | // 'flutter create' template.
6 |
7 | // The application's name. By default this is also the title of the Flutter window.
8 | PRODUCT_NAME = example
9 |
10 | // The application's bundle identifier
11 | PRODUCT_BUNDLE_IDENTIFIER = com.example.example
12 |
13 | // The copyright displayed in application information
14 | PRODUCT_COPYRIGHT = Copyright © 2024 com.example. All rights reserved.
15 |
--------------------------------------------------------------------------------
/example/android/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | ext.kotlin_version = '1.7.10'
3 | repositories {
4 | google()
5 | mavenCentral()
6 | }
7 |
8 | dependencies {
9 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
10 | }
11 | }
12 |
13 | allprojects {
14 | repositories {
15 | google()
16 | mavenCentral()
17 | }
18 | }
19 |
20 | rootProject.buildDir = '../build'
21 | subprojects {
22 | project.buildDir = "${rootProject.buildDir}/${project.name}"
23 | }
24 | subprojects {
25 | project.evaluationDependsOn(':app')
26 | }
27 |
28 | tasks.register("clean", Delete) {
29 | delete rootProject.buildDir
30 | }
31 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/example/lib/routes/routes.dart:
--------------------------------------------------------------------------------
1 | import 'package:example/views/cart_view.dart';
2 | import 'package:example/views/products_view.dart';
3 | import 'package:flutter/material.dart';
4 | import 'package:go_router/go_router.dart';
5 |
6 | final GoRouter router = GoRouter(
7 | routes: [
8 | GoRoute(
9 | path: '/',
10 | builder: (BuildContext context, GoRouterState state) {
11 | return const ProductsView();
12 | },
13 | routes: [
14 | GoRoute(
15 | path: 'cart',
16 | builder: (BuildContext context, GoRouterState state) {
17 | return const CartView();
18 | },
19 | ),
20 | ]),
21 | ],
22 | );
23 |
--------------------------------------------------------------------------------
/example/lib/providers/products/products_provider.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 | import 'package:example/models/products_model.dart';
3 | import 'package:flutter/services.dart';
4 | import 'package:riverpod_annotation/riverpod_annotation.dart';
5 |
6 | // Necessary for code-generation to work
7 | part 'products_provider.g.dart';
8 |
9 | /// This will create a provider named `fetchProductsProvider`
10 | /// which will cache the result of this function.
11 | @riverpod
12 | Future fetchProducts(FetchProductsRef ref) async {
13 | final String response = await rootBundle.loadString('assets/products.json');
14 | final json = jsonDecode(response) as Map;
15 | return ProductModel.fromJson(json);
16 | }
17 |
--------------------------------------------------------------------------------
/example/ios/.gitignore:
--------------------------------------------------------------------------------
1 | **/dgph
2 | *.mode1v3
3 | *.mode2v3
4 | *.moved-aside
5 | *.pbxuser
6 | *.perspectivev3
7 | **/*sync/
8 | .sconsign.dblite
9 | .tags*
10 | **/.vagrant/
11 | **/DerivedData/
12 | Icon?
13 | **/Pods/
14 | **/.symlinks/
15 | profile
16 | xcuserdata
17 | **/.generated/
18 | Flutter/App.framework
19 | Flutter/Flutter.framework
20 | Flutter/Flutter.podspec
21 | Flutter/Generated.xcconfig
22 | Flutter/ephemeral/
23 | Flutter/app.flx
24 | Flutter/app.zip
25 | Flutter/flutter_assets/
26 | Flutter/flutter_export_environment.sh
27 | ServiceDefinitions.json
28 | Runner/GeneratedPluginRegistrant.*
29 |
30 | # Exceptions to above rules.
31 | !default.mode1v3
32 | !default.mode2v3
33 | !default.pbxuser
34 | !default.perspectivev3
35 |
--------------------------------------------------------------------------------
/example/windows/runner/utils.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_UTILS_H_
2 | #define RUNNER_UTILS_H_
3 |
4 | #include
5 | #include
6 |
7 | // Creates a console for the process, and redirects stdout and stderr to
8 | // it for both the runner and the Flutter library.
9 | void CreateAndAttachConsole();
10 |
11 | // Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string
12 | // encoded in UTF-8. Returns an empty std::string on failure.
13 | std::string Utf8FromUtf16(const wchar_t* utf16_string);
14 |
15 | // Gets the command line arguments passed in as a std::vector,
16 | // encoded in UTF-8. Returns an empty std::vector on failure.
17 | std::vector GetCommandLineArguments();
18 |
19 | #endif // RUNNER_UTILS_H_
20 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [0.0.1]
2 |
3 | - Initial release of flutter cart package.
4 |
5 | ## [0.0.4]
6 |
7 | - Example has been added.
8 |
9 | ## [0.0.5]
10 |
11 | - Product price floating issue fixed.
12 |
13 | ## [0.0.5+1]
14 |
15 | - Fixed minor changes.
16 |
17 | ## [0.0.6]
18 |
19 | - Flutter Cart updated to null safety.
20 | - ProductName variable has been added in Cart model.
21 | - Now you can get the specific product by using getSpecificItemFromCart(productId) named function.
22 | - Improved the package and fixed some minor issues.
23 | ## [0.0.7]
24 |
25 | - Flutter cart updated to latest version
26 |
27 | ## [0.0.8]
28 |
29 | - Flutter cart updated to latest version
30 |
31 | ## [0.0.9]
32 |
33 | - Flutter cart updated to latest version
34 | - Improved documentation
35 | - Persistence support added
36 |
37 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Smartphone (please complete the following information):**
27 | - Device: [e.g. iPhone6]
28 | - OS: [e.g. iOS8.1]
29 | - Version [e.g. 22]
30 |
31 | **Additional context**
32 | Add any other context about the problem here.
33 |
--------------------------------------------------------------------------------
/example/linux/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | )
7 |
8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST
9 | )
10 |
11 | set(PLUGIN_BUNDLED_LIBRARIES)
12 |
13 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin})
15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
18 | endforeach(plugin)
19 |
20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
23 | endforeach(ffi_plugin)
24 |
--------------------------------------------------------------------------------
/example/windows/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | )
7 |
8 | list(APPEND FLUTTER_FFI_PLUGIN_LIST
9 | )
10 |
11 | set(PLUGIN_BUNDLED_LIBRARIES)
12 |
13 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
14 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
15 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
16 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
17 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
18 | endforeach(plugin)
19 |
20 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
21 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
22 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
23 | endforeach(ffi_plugin)
24 |
--------------------------------------------------------------------------------
/example/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 | migrate_working_dir/
12 |
13 | # IntelliJ related
14 | *.iml
15 | *.ipr
16 | *.iws
17 | .idea/
18 |
19 | # The .vscode folder contains launch configuration and tasks you configure in
20 | # VS Code which you may wish to be included in version control, so this line
21 | # is commented out by default.
22 | #.vscode/
23 |
24 | # Flutter/Dart/Pub related
25 | **/doc/api/
26 | **/ios/Flutter/.last_build_id
27 | .dart_tool/
28 | .flutter-plugins
29 | .flutter-plugins-dependencies
30 | .pub-cache/
31 | .pub/
32 | /build/
33 |
34 | # Symbolication related
35 | app.*.symbols
36 |
37 | # Obfuscation related
38 | app.*.map.json
39 |
40 | # Android Studio will place build artifacts here
41 | /android/app/debug
42 | /android/app/profile
43 | /android/app/release
44 |
--------------------------------------------------------------------------------
/example/ios/Flutter/AppFrameworkInfo.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | App
9 | CFBundleIdentifier
10 | io.flutter.flutter.app
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | App
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleSignature
20 | ????
21 | CFBundleVersion
22 | 1.0
23 | MinimumOSVersion
24 | 12.0
25 |
26 |
27 |
--------------------------------------------------------------------------------
/example/android/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | def flutterSdkPath = {
3 | def properties = new Properties()
4 | file("local.properties").withInputStream { properties.load(it) }
5 | def flutterSdkPath = properties.getProperty("flutter.sdk")
6 | assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
7 | return flutterSdkPath
8 | }
9 | settings.ext.flutterSdkPath = flutterSdkPath()
10 |
11 | includeBuild("${settings.ext.flutterSdkPath}/packages/flutter_tools/gradle")
12 |
13 | repositories {
14 | google()
15 | mavenCentral()
16 | gradlePluginPortal()
17 | }
18 |
19 | plugins {
20 | id "dev.flutter.flutter-gradle-plugin" version "1.0.0" apply false
21 | }
22 | }
23 |
24 | plugins {
25 | id "dev.flutter.flutter-plugin-loader" version "1.0.0"
26 | id "com.android.application" version "7.3.0" apply false
27 | }
28 |
29 | include ":app"
30 |
--------------------------------------------------------------------------------
/example/windows/runner/runner.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PerMonitorV2
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/example/web/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "example",
3 | "short_name": "example",
4 | "start_url": ".",
5 | "display": "standalone",
6 | "background_color": "#0175C2",
7 | "theme_color": "#0175C2",
8 | "description": "A new Flutter project.",
9 | "orientation": "portrait-primary",
10 | "prefer_related_applications": false,
11 | "icons": [
12 | {
13 | "src": "icons/Icon-192.png",
14 | "sizes": "192x192",
15 | "type": "image/png"
16 | },
17 | {
18 | "src": "icons/Icon-512.png",
19 | "sizes": "512x512",
20 | "type": "image/png"
21 | },
22 | {
23 | "src": "icons/Icon-maskable-192.png",
24 | "sizes": "192x192",
25 | "type": "image/png",
26 | "purpose": "maskable"
27 | },
28 | {
29 | "src": "icons/Icon-maskable-512.png",
30 | "sizes": "512x512",
31 | "type": "image/png",
32 | "purpose": "maskable"
33 | }
34 | ]
35 | }
36 |
--------------------------------------------------------------------------------
/example/windows/runner/flutter_window.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_FLUTTER_WINDOW_H_
2 | #define RUNNER_FLUTTER_WINDOW_H_
3 |
4 | #include
5 | #include
6 |
7 | #include
8 |
9 | #include "win32_window.h"
10 |
11 | // A window that does nothing but host a Flutter view.
12 | class FlutterWindow : public Win32Window {
13 | public:
14 | // Creates a new FlutterWindow hosting a Flutter view running |project|.
15 | explicit FlutterWindow(const flutter::DartProject& project);
16 | virtual ~FlutterWindow();
17 |
18 | protected:
19 | // Win32Window:
20 | bool OnCreate() override;
21 | void OnDestroy() override;
22 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam,
23 | LPARAM const lparam) noexcept override;
24 |
25 | private:
26 | // The project to run.
27 | flutter::DartProject project_;
28 |
29 | // The Flutter instance hosted by this window.
30 | std::unique_ptr flutter_controller_;
31 | };
32 |
33 | #endif // RUNNER_FLUTTER_WINDOW_H_
34 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/example/android/app/src/main/res/values-night/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/lib/model/cart_model.dart:
--------------------------------------------------------------------------------
1 | import 'package:freezed_annotation/freezed_annotation.dart';
2 | import 'package:flutter/foundation.dart';
3 |
4 | part 'cart_model.freezed.dart';
5 | part 'cart_model.g.dart';
6 |
7 | /// [Cart Model] for managing cart data
8 |
9 | @freezed
10 | class CartModel with _$CartModel {
11 | const factory CartModel({
12 | required String productId,
13 | required String productName,
14 | List? productImages,
15 | required List variants,
16 | @Default(1) int quantity,
17 | @Default(0.0) double discount,
18 | required String productDetails,
19 | Map? productMeta,
20 | }) = _CartModel;
21 |
22 | factory CartModel.fromJson(Map json) =>
23 | _$CartModelFromJson(json);
24 | }
25 |
26 | @freezed
27 | class ProductVariant with _$ProductVariant {
28 | factory ProductVariant({
29 | String? size,
30 | String? color,
31 | required double price,
32 | }) = _ProductVariant;
33 |
34 | factory ProductVariant.fromJson(Map json) =>
35 | _$ProductVariantFromJson(json);
36 | }
37 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) [2020][Osama Asif]
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/example/lib/models/products_model.dart:
--------------------------------------------------------------------------------
1 | import 'package:freezed_annotation/freezed_annotation.dart';
2 |
3 | part 'products_model.freezed.dart';
4 | part 'products_model.g.dart';
5 |
6 | /// [Cart Model] for managing cart data
7 |
8 | @freezed
9 | class ProductModel with _$ProductModel {
10 | const factory ProductModel({
11 | required List products,
12 | }) = _ProductModel;
13 |
14 | factory ProductModel.fromJson(Map json) =>
15 | _$ProductModelFromJson(json);
16 | }
17 |
18 | @freezed
19 | class ProductItemsModel with _$ProductItemsModel {
20 | const factory ProductItemsModel({
21 | required int id,
22 | required String title,
23 | required String description,
24 | required String category,
25 | required double price,
26 | required double discountPercentage,
27 | required double rating,
28 | required int stock,
29 | required String brand,
30 | String? thumbnail,
31 | List? images,
32 | }) = _ProductItemsModel;
33 |
34 | factory ProductItemsModel.fromJson(Map json) =>
35 | _$ProductItemsModelFromJson(json);
36 | }
37 |
--------------------------------------------------------------------------------
/example/lib/main.dart:
--------------------------------------------------------------------------------
1 | import 'package:example/routes/routes.dart';
2 | import 'package:flutter/material.dart';
3 | import 'package:flutter_cart/flutter_cart.dart';
4 | import 'package:flutter_riverpod/flutter_riverpod.dart';
5 |
6 | void main() async {
7 | WidgetsFlutterBinding.ensureInitialized();
8 | var cart = FlutterCart();
9 | await cart.initializeCart(isPersistenceSupportEnabled: true);
10 | runApp(const ProviderScope(child: MyApp()));
11 | }
12 |
13 | class MyApp extends StatelessWidget {
14 | const MyApp({super.key});
15 |
16 | // This widget is the root of your application.
17 | @override
18 | Widget build(BuildContext context) {
19 | return MaterialApp.router(
20 | routerConfig: router,
21 | title: 'Example Cart',
22 | theme: ThemeData(
23 | colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
24 | useMaterial3: true,
25 | appBarTheme: const AppBarTheme(
26 | color: Colors.deepPurple,
27 | titleTextStyle: TextStyle(
28 | color: Colors.white, fontWeight: FontWeight.w500, fontSize: 20),
29 | ),
30 | ),
31 | debugShowCheckedModeBanner: false,
32 | );
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/example/lib/providers/products/products_provider.g.dart:
--------------------------------------------------------------------------------
1 | // GENERATED CODE - DO NOT MODIFY BY HAND
2 |
3 | part of 'products_provider.dart';
4 |
5 | // **************************************************************************
6 | // RiverpodGenerator
7 | // **************************************************************************
8 |
9 | String _$fetchProductsHash() => r'4d089f2f981dac7767caed6ac7e4243b6c0b6ee9';
10 |
11 | /// This will create a provider named `fetchProductsProvider`
12 | /// which will cache the result of this function.
13 | ///
14 | /// Copied from [fetchProducts].
15 | @ProviderFor(fetchProducts)
16 | final fetchProductsProvider = AutoDisposeFutureProvider.internal(
17 | fetchProducts,
18 | name: r'fetchProductsProvider',
19 | debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product')
20 | ? null
21 | : _$fetchProductsHash,
22 | dependencies: null,
23 | allTransitiveDependencies: null,
24 | );
25 |
26 | typedef FetchProductsRef = AutoDisposeFutureProviderRef;
27 | // ignore_for_file: type=lint
28 | // ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member
29 |
--------------------------------------------------------------------------------
/example/test/widget_test.dart:
--------------------------------------------------------------------------------
1 | // This is a basic Flutter widget test.
2 | //
3 | // To perform an interaction with a widget in your test, use the WidgetTester
4 | // utility in the flutter_test package. For example, you can send tap and scroll
5 | // gestures. You can also use WidgetTester to find child widgets in the widget
6 | // tree, read text, and verify that the values of widget properties are correct.
7 |
8 | import 'package:flutter/material.dart';
9 | import 'package:flutter_test/flutter_test.dart';
10 |
11 | import 'package:example/main.dart';
12 |
13 | void main() {
14 | testWidgets('Counter increments smoke test', (WidgetTester tester) async {
15 | // Build our app and trigger a frame.
16 | await tester.pumpWidget(const MyApp());
17 |
18 | // Verify that our counter starts at 0.
19 | expect(find.text('0'), findsOneWidget);
20 | expect(find.text('1'), findsNothing);
21 |
22 | // Tap the '+' icon and trigger a frame.
23 | await tester.tap(find.byIcon(Icons.add));
24 | await tester.pump();
25 |
26 | // Verify that our counter has incremented.
27 | expect(find.text('0'), findsNothing);
28 | expect(find.text('1'), findsOneWidget);
29 | });
30 | }
31 |
--------------------------------------------------------------------------------
/example/macos/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIconFile
10 |
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | $(FLUTTER_BUILD_NAME)
21 | CFBundleVersion
22 | $(FLUTTER_BUILD_NUMBER)
23 | LSMinimumSystemVersion
24 | $(MACOSX_DEPLOYMENT_TARGET)
25 | NSHumanReadableCopyright
26 | $(PRODUCT_COPYRIGHT)
27 | NSMainNibFile
28 | MainMenu
29 | NSPrincipalClass
30 | NSApplication
31 |
32 |
33 |
--------------------------------------------------------------------------------
/example/windows/runner/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "flutter_window.h"
6 | #include "utils.h"
7 |
8 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev,
9 | _In_ wchar_t *command_line, _In_ int show_command) {
10 | // Attach to console when present (e.g., 'flutter run') or create a
11 | // new console when running with a debugger.
12 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) {
13 | CreateAndAttachConsole();
14 | }
15 |
16 | // Initialize COM, so that it is available for use in the library and/or
17 | // plugins.
18 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
19 |
20 | flutter::DartProject project(L"data");
21 |
22 | std::vector command_line_arguments =
23 | GetCommandLineArguments();
24 |
25 | project.set_dart_entrypoint_arguments(std::move(command_line_arguments));
26 |
27 | FlutterWindow window(project);
28 | Win32Window::Point origin(10, 10);
29 | Win32Window::Size size(1280, 720);
30 | if (!window.Create(L"example", origin, size)) {
31 | return EXIT_FAILURE;
32 | }
33 | window.SetQuitOnClose(true);
34 |
35 | ::MSG msg;
36 | while (::GetMessage(&msg, nullptr, 0, 0)) {
37 | ::TranslateMessage(&msg);
38 | ::DispatchMessage(&msg);
39 | }
40 |
41 | ::CoUninitialize();
42 | return EXIT_SUCCESS;
43 | }
44 |
--------------------------------------------------------------------------------
/example/macos/Podfile:
--------------------------------------------------------------------------------
1 | platform :osx, '10.14'
2 |
3 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
4 | ENV['COCOAPODS_DISABLE_STATS'] = 'true'
5 |
6 | project 'Runner', {
7 | 'Debug' => :debug,
8 | 'Profile' => :release,
9 | 'Release' => :release,
10 | }
11 |
12 | def flutter_root
13 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'ephemeral', 'Flutter-Generated.xcconfig'), __FILE__)
14 | unless File.exist?(generated_xcode_build_settings_path)
15 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure \"flutter pub get\" is executed first"
16 | end
17 |
18 | File.foreach(generated_xcode_build_settings_path) do |line|
19 | matches = line.match(/FLUTTER_ROOT\=(.*)/)
20 | return matches[1].strip if matches
21 | end
22 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Flutter-Generated.xcconfig, then run \"flutter pub get\""
23 | end
24 |
25 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
26 |
27 | flutter_macos_podfile_setup
28 |
29 | target 'Runner' do
30 | use_frameworks!
31 | use_modular_headers!
32 |
33 | flutter_install_all_macos_pods File.dirname(File.realpath(__FILE__))
34 | target 'RunnerTests' do
35 | inherit! :search_paths
36 | end
37 | end
38 |
39 | post_install do |installer|
40 | installer.pods_project.targets.each do |target|
41 | flutter_additional_macos_build_settings(target)
42 | end
43 | end
44 |
--------------------------------------------------------------------------------
/example/analysis_options.yaml:
--------------------------------------------------------------------------------
1 | # This file configures the analyzer, which statically analyzes Dart code to
2 | # check for errors, warnings, and lints.
3 | #
4 | # The issues identified by the analyzer are surfaced in the UI of Dart-enabled
5 | # IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
6 | # invoked from the command line by running `flutter analyze`.
7 |
8 | # The following line activates a set of recommended lints for Flutter apps,
9 | # packages, and plugins designed to encourage good coding practices.
10 | include: package:flutter_lints/flutter.yaml
11 |
12 | linter:
13 | # The lint rules applied to this project can be customized in the
14 | # section below to disable rules from the `package:flutter_lints/flutter.yaml`
15 | # included above or to enable additional rules. A list of all available lints
16 | # and their documentation is published at https://dart.dev/lints.
17 | #
18 | # Instead of disabling a lint rule for the entire project in the
19 | # section below, it can also be suppressed for a single line of code
20 | # or a specific dart file by using the `// ignore: name_of_lint` and
21 | # `// ignore_for_file: name_of_lint` syntax on the line or in the file
22 | # producing the lint.
23 | rules:
24 | # avoid_print: false # Uncomment to disable the `avoid_print` rule
25 | # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
26 |
27 | # Additional information about this file can be found at
28 | # https://dart.dev/guides/language/analysis-options
29 | analyzer:
30 | plugins:
31 | - custom_lint
32 |
--------------------------------------------------------------------------------
/example/ios/Podfile:
--------------------------------------------------------------------------------
1 | # Uncomment this line to define a global platform for your project
2 | # platform :ios, '12.0'
3 |
4 | # CocoaPods analytics sends network stats synchronously affecting flutter build latency.
5 | ENV['COCOAPODS_DISABLE_STATS'] = 'true'
6 |
7 | project 'Runner', {
8 | 'Debug' => :debug,
9 | 'Profile' => :release,
10 | 'Release' => :release,
11 | }
12 |
13 | def flutter_root
14 | generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
15 | unless File.exist?(generated_xcode_build_settings_path)
16 | raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
17 | end
18 |
19 | File.foreach(generated_xcode_build_settings_path) do |line|
20 | matches = line.match(/FLUTTER_ROOT\=(.*)/)
21 | return matches[1].strip if matches
22 | end
23 | raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
24 | end
25 |
26 | require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
27 |
28 | flutter_ios_podfile_setup
29 |
30 | target 'Runner' do
31 | use_frameworks!
32 | use_modular_headers!
33 |
34 | flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
35 | target 'RunnerTests' do
36 | inherit! :search_paths
37 | end
38 | end
39 |
40 | post_install do |installer|
41 | installer.pods_project.targets.each do |target|
42 | flutter_additional_ios_build_settings(target)
43 | end
44 | end
45 |
--------------------------------------------------------------------------------
/example/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "16x16",
5 | "idiom" : "mac",
6 | "filename" : "app_icon_16.png",
7 | "scale" : "1x"
8 | },
9 | {
10 | "size" : "16x16",
11 | "idiom" : "mac",
12 | "filename" : "app_icon_32.png",
13 | "scale" : "2x"
14 | },
15 | {
16 | "size" : "32x32",
17 | "idiom" : "mac",
18 | "filename" : "app_icon_32.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "32x32",
23 | "idiom" : "mac",
24 | "filename" : "app_icon_64.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "128x128",
29 | "idiom" : "mac",
30 | "filename" : "app_icon_128.png",
31 | "scale" : "1x"
32 | },
33 | {
34 | "size" : "128x128",
35 | "idiom" : "mac",
36 | "filename" : "app_icon_256.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "256x256",
41 | "idiom" : "mac",
42 | "filename" : "app_icon_256.png",
43 | "scale" : "1x"
44 | },
45 | {
46 | "size" : "256x256",
47 | "idiom" : "mac",
48 | "filename" : "app_icon_512.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "512x512",
53 | "idiom" : "mac",
54 | "filename" : "app_icon_512.png",
55 | "scale" : "1x"
56 | },
57 | {
58 | "size" : "512x512",
59 | "idiom" : "mac",
60 | "filename" : "app_icon_1024.png",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/example/ios/Runner/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/example/lib/providers/cart/cart_provider.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter/material.dart';
2 | import 'package:flutter_cart/flutter_cart.dart';
3 | import 'package:example/models/products_model.dart';
4 | import 'package:flutter_riverpod/flutter_riverpod.dart';
5 |
6 | final cartNotifierProvider = ChangeNotifierProvider((ref) {
7 | return CartNotifier();
8 | });
9 |
10 | class CartNotifier extends ChangeNotifier {
11 | var flutterCart = FlutterCart();
12 |
13 | void addToCart(ProductItemsModel product) {
14 | var discount = (product.discountPercentage / 100) * product.price;
15 | flutterCart.addToCart(
16 | cartModel: CartModel(
17 | productId: product.id.toString(),
18 | productName: product.title,
19 | variants: [
20 | ProductVariant(price: product.price),
21 | ],
22 | productDetails: product.description,
23 | discount: discount,
24 | productMeta: product.toJson()),
25 | );
26 | notifyListeners();
27 | }
28 |
29 | void updateQuantity(CartModel item, int newQuantity) {
30 | flutterCart.updateQuantity(
31 | item.productId.toString(), item.variants, newQuantity);
32 | notifyListeners();
33 | }
34 |
35 | void removeItemFromCart(CartModel item) {
36 | flutterCart.removeItem(item.productId.toString(), item.variants);
37 | notifyListeners();
38 | }
39 |
40 | void clearCart() {
41 | flutterCart.clearCart();
42 | notifyListeners();
43 | }
44 |
45 | int get getCartCount => flutterCart.cartLength;
46 | List get getCartItems => flutterCart.cartItemsList;
47 | double get getTotalAmount => flutterCart.total;
48 | double get subtotal => flutterCart.subtotal;
49 | }
50 |
--------------------------------------------------------------------------------
/example/android/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
14 |
18 |
22 |
23 |
24 |
25 |
26 |
27 |
29 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/example/ios/Runner/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | $(DEVELOPMENT_LANGUAGE)
7 | CFBundleDisplayName
8 | Example
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | example
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | $(FLUTTER_BUILD_NAME)
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | $(FLUTTER_BUILD_NUMBER)
25 | LSRequiresIPhoneOS
26 |
27 | UILaunchStoryboardName
28 | LaunchScreen
29 | UIMainStoryboardFile
30 | Main
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 | CADisableMinimumFrameDurationOnPhone
45 |
46 | UIApplicationSupportsIndirectInputEvents
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Miscellaneous
2 | *.class
3 | *.log
4 | *.pyc
5 | *.swp
6 | .DS_Store
7 | .atom/
8 | .buildlog/
9 | .history
10 | .svn/
11 |
12 | # IntelliJ related
13 | *.iml
14 | *.ipr
15 | *.iws
16 | .idea/
17 |
18 | # The .vscode folder contains launch configuration and tasks you configure in
19 | # VS Code which you may wish to be included in version control, so this line
20 | # is commented out by default.
21 | #.vscode/
22 |
23 | # Flutter/Dart/Pub related
24 | **/doc/api/
25 | .dart_tool/
26 | .flutter-plugins
27 | .flutter-plugins-dependencies
28 | .packages
29 | .pub-cache/
30 | .pub/
31 | build/
32 |
33 | # Android related
34 | **/android/**/gradle-wrapper.jar
35 | **/android/.gradle
36 | **/android/captures/
37 | **/android/gradlew
38 | **/android/gradlew.bat
39 | **/android/local.properties
40 | **/android/**/GeneratedPluginRegistrant.java
41 |
42 | # iOS/XCode related
43 | **/ios/**/*.mode1v3
44 | **/ios/**/*.mode2v3
45 | **/ios/**/*.moved-aside
46 | **/ios/**/*.pbxuser
47 | **/ios/**/*.perspectivev3
48 | **/ios/**/*sync/
49 | **/ios/**/.sconsign.dblite
50 | **/ios/**/.tags*
51 | **/ios/**/.vagrant/
52 | **/ios/**/DerivedData/
53 | **/ios/**/Icon?
54 | **/ios/**/Pods/
55 | **/ios/**/.symlinks/
56 | **/ios/**/profile
57 | **/ios/**/xcuserdata
58 | **/ios/.generated/
59 | **/ios/Flutter/App.framework
60 | **/ios/Flutter/Flutter.framework
61 | **/ios/Flutter/Flutter.podspec
62 | **/ios/Flutter/Generated.xcconfig
63 | **/ios/Flutter/app.flx
64 | **/ios/Flutter/app.zip
65 | **/ios/Flutter/flutter_assets/
66 | **/ios/Flutter/flutter_export_environment.sh
67 | **/ios/ServiceDefinitions.json
68 | **/ios/Runner/GeneratedPluginRegistrant.*
69 |
70 | # Exceptions to above rules.
71 | !**/ios/**/default.mode1v3
72 | !**/ios/**/default.mode2v3
73 | !**/ios/**/default.pbxuser
74 | !**/ios/**/default.perspectivev3
75 | !/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
76 |
--------------------------------------------------------------------------------
/example/.metadata:
--------------------------------------------------------------------------------
1 | # This file tracks properties of this Flutter project.
2 | # Used by Flutter tool to assess capabilities and perform upgrades etc.
3 | #
4 | # This file should be version controlled and should not be manually edited.
5 |
6 | version:
7 | revision: "41456452f29d64e8deb623a3c927524bcf9f111b"
8 | channel: "stable"
9 |
10 | project_type: app
11 |
12 | # Tracks metadata for the flutter migrate command
13 | migration:
14 | platforms:
15 | - platform: root
16 | create_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
17 | base_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
18 | - platform: android
19 | create_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
20 | base_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
21 | - platform: ios
22 | create_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
23 | base_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
24 | - platform: linux
25 | create_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
26 | base_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
27 | - platform: macos
28 | create_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
29 | base_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
30 | - platform: web
31 | create_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
32 | base_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
33 | - platform: windows
34 | create_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
35 | base_revision: 41456452f29d64e8deb623a3c927524bcf9f111b
36 |
37 | # User provided section
38 |
39 | # List of Local paths (relative to this file) that should be
40 | # ignored by the migrate tool.
41 | #
42 | # Files that are not part of the templates will be ignored by default.
43 | unmanaged_files:
44 | - 'lib/main.dart'
45 | - 'ios/Runner.xcodeproj/project.pbxproj'
46 |
--------------------------------------------------------------------------------
/example/windows/runner/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.14)
2 | project(runner LANGUAGES CXX)
3 |
4 | # Define the application target. To change its name, change BINARY_NAME in the
5 | # top-level CMakeLists.txt, not the value here, or `flutter run` will no longer
6 | # work.
7 | #
8 | # Any new source files that you add to the application should be added here.
9 | add_executable(${BINARY_NAME} WIN32
10 | "flutter_window.cpp"
11 | "main.cpp"
12 | "utils.cpp"
13 | "win32_window.cpp"
14 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
15 | "Runner.rc"
16 | "runner.exe.manifest"
17 | )
18 |
19 | # Apply the standard set of build settings. This can be removed for applications
20 | # that need different build settings.
21 | apply_standard_settings(${BINARY_NAME})
22 |
23 | # Add preprocessor definitions for the build version.
24 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"")
25 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}")
26 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}")
27 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}")
28 | target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}")
29 |
30 | # Disable Windows macros that collide with C++ standard library functions.
31 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX")
32 |
33 | # Add dependency libraries and include directories. Add any application-specific
34 | # dependencies here.
35 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app)
36 | target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib")
37 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
38 |
39 | # Run the Flutter tool portions of the build. This must not be removed.
40 | add_dependencies(${BINARY_NAME} flutter_assemble)
41 |
--------------------------------------------------------------------------------
/lib/model/cart_model.g.dart:
--------------------------------------------------------------------------------
1 | // GENERATED CODE - DO NOT MODIFY BY HAND
2 |
3 | part of 'cart_model.dart';
4 |
5 | // **************************************************************************
6 | // JsonSerializableGenerator
7 | // **************************************************************************
8 |
9 | _$CartModelImpl _$$CartModelImplFromJson(Map json) =>
10 | _$CartModelImpl(
11 | productId: json['productId'] as String,
12 | productName: json['productName'] as String,
13 | productImages: (json['productImages'] as List?)
14 | ?.map((e) => e as String)
15 | .toList(),
16 | variants: (json['variants'] as List)
17 | .map((e) => ProductVariant.fromJson(e as Map))
18 | .toList(),
19 | quantity: json['quantity'] as int? ?? 1,
20 | discount: (json['discount'] as num?)?.toDouble() ?? 0.0,
21 | productDetails: json['productDetails'] as String,
22 | productMeta: json['productMeta'] as Map?,
23 | );
24 |
25 | Map _$$CartModelImplToJson(_$CartModelImpl instance) =>
26 | {
27 | 'productId': instance.productId,
28 | 'productName': instance.productName,
29 | 'productImages': instance.productImages,
30 | 'variants': instance.variants,
31 | 'quantity': instance.quantity,
32 | 'discount': instance.discount,
33 | 'productDetails': instance.productDetails,
34 | 'productMeta': instance.productMeta,
35 | };
36 |
37 | _$ProductVariantImpl _$$ProductVariantImplFromJson(Map json) =>
38 | _$ProductVariantImpl(
39 | size: json['size'] as String?,
40 | color: json['color'] as String?,
41 | price: (json['price'] as num).toDouble(),
42 | );
43 |
44 | Map _$$ProductVariantImplToJson(
45 | _$ProductVariantImpl instance) =>
46 | {
47 | 'size': instance.size,
48 | 'color': instance.color,
49 | 'price': instance.price,
50 | };
51 |
--------------------------------------------------------------------------------
/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: flutter_cart
2 | description: A flutter package for the cart management. This package helps you to perform basic cart operation like (Add to cart, Remove from cart, Get total count) etc.
3 | version: 0.0.9
4 | homepage: https://github.com/osamaasifoak/flutter_cart
5 |
6 | environment:
7 | sdk: ">=3.2.6 <4.0.0"
8 | flutter: ">=1.17.0"
9 |
10 | dependencies:
11 | flutter:
12 | sdk: flutter
13 | freezed: ^2.4.6
14 | freezed_annotation: ^2.4.1
15 | shared_preferences: ^2.2.2
16 |
17 | dev_dependencies:
18 | flutter_test:
19 | sdk: flutter
20 | build_runner: ^2.4.8
21 | json_serializable: ^6.7.1
22 |
23 | # For information on the generic Dart part of this file, see the
24 | # following page: https://dart.dev/tools/pub/pubspec
25 |
26 | # The following section is specific to Flutter.
27 | flutter:
28 |
29 | # To add assets to your package, add an assets section, like this:
30 | # assets:
31 | # - images/a_dot_burr.jpeg
32 | # - images/a_dot_ham.jpeg
33 | #
34 | # For details regarding assets in packages, see
35 | # https://flutter.dev/assets-and-images/#from-packages
36 | #
37 | # An image asset can refer to one or more resolution-specific "variants", see
38 | # https://flutter.dev/assets-and-images/#resolution-aware.
39 |
40 | # To add custom fonts to your package, add a fonts section here,
41 | # in this "flutter" section. Each entry in this list should have a
42 | # "family" key with the font family name, and a "fonts" key with a
43 | # list giving the asset and other descriptors for the font. For
44 | # example:
45 | # fonts:
46 | # - family: Schyler
47 | # fonts:
48 | # - asset: fonts/Schyler-Regular.ttf
49 | # - asset: fonts/Schyler-Italic.ttf
50 | # style: italic
51 | # - family: Trajan Pro
52 | # fonts:
53 | # - asset: fonts/TrajanPro.ttf
54 | # - asset: fonts/TrajanPro_Bold.ttf
55 | # weight: 700
56 | #
57 | # For details regarding fonts in packages, see
58 | # https://flutter.dev/custom-fonts/#from-packages
59 |
--------------------------------------------------------------------------------
/example/windows/runner/utils.cpp:
--------------------------------------------------------------------------------
1 | #include "utils.h"
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include
9 |
10 | void CreateAndAttachConsole() {
11 | if (::AllocConsole()) {
12 | FILE *unused;
13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) {
14 | _dup2(_fileno(stdout), 1);
15 | }
16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) {
17 | _dup2(_fileno(stdout), 2);
18 | }
19 | std::ios::sync_with_stdio();
20 | FlutterDesktopResyncOutputStreams();
21 | }
22 | }
23 |
24 | std::vector GetCommandLineArguments() {
25 | // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use.
26 | int argc;
27 | wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc);
28 | if (argv == nullptr) {
29 | return std::vector();
30 | }
31 |
32 | std::vector command_line_arguments;
33 |
34 | // Skip the first argument as it's the binary name.
35 | for (int i = 1; i < argc; i++) {
36 | command_line_arguments.push_back(Utf8FromUtf16(argv[i]));
37 | }
38 |
39 | ::LocalFree(argv);
40 |
41 | return command_line_arguments;
42 | }
43 |
44 | std::string Utf8FromUtf16(const wchar_t* utf16_string) {
45 | if (utf16_string == nullptr) {
46 | return std::string();
47 | }
48 | int target_length = ::WideCharToMultiByte(
49 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
50 | -1, nullptr, 0, nullptr, nullptr)
51 | -1; // remove the trailing null character
52 | int input_length = (int)wcslen(utf16_string);
53 | std::string utf8_string;
54 | if (target_length <= 0 || target_length > utf8_string.max_size()) {
55 | return utf8_string;
56 | }
57 | utf8_string.resize(target_length);
58 | int converted_length = ::WideCharToMultiByte(
59 | CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string,
60 | input_length, utf8_string.data(), target_length, nullptr, nullptr);
61 | if (converted_length == 0) {
62 | return std::string();
63 | }
64 | return utf8_string;
65 | }
66 |
--------------------------------------------------------------------------------
/example/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | example
33 |
34 |
35 |
39 |
40 |
41 |
42 |
43 |
58 |
59 |
60 |
--------------------------------------------------------------------------------
/example/lib/models/products_model.g.dart:
--------------------------------------------------------------------------------
1 | // GENERATED CODE - DO NOT MODIFY BY HAND
2 |
3 | part of 'products_model.dart';
4 |
5 | // **************************************************************************
6 | // JsonSerializableGenerator
7 | // **************************************************************************
8 |
9 | _$ProductModelImpl _$$ProductModelImplFromJson(Map json) =>
10 | _$ProductModelImpl(
11 | products: (json['products'] as List)
12 | .map((e) => ProductItemsModel.fromJson(e as Map))
13 | .toList(),
14 | );
15 |
16 | Map _$$ProductModelImplToJson(_$ProductModelImpl instance) =>
17 | {
18 | 'products': instance.products,
19 | };
20 |
21 | _$ProductItemsModelImpl _$$ProductItemsModelImplFromJson(
22 | Map json) =>
23 | _$ProductItemsModelImpl(
24 | id: json['id'] as int,
25 | title: json['title'] as String,
26 | description: json['description'] as String,
27 | category: json['category'] as String,
28 | price: (json['price'] as num).toDouble(),
29 | discountPercentage: (json['discountPercentage'] as num).toDouble(),
30 | rating: (json['rating'] as num).toDouble(),
31 | stock: json['stock'] as int,
32 | brand: json['brand'] as String,
33 | thumbnail: json['thumbnail'] as String?,
34 | images:
35 | (json['images'] as List?)?.map((e) => e as String).toList(),
36 | );
37 |
38 | Map _$$ProductItemsModelImplToJson(
39 | _$ProductItemsModelImpl instance) =>
40 | {
41 | 'id': instance.id,
42 | 'title': instance.title,
43 | 'description': instance.description,
44 | 'category': instance.category,
45 | 'price': instance.price,
46 | 'discountPercentage': instance.discountPercentage,
47 | 'rating': instance.rating,
48 | 'stock': instance.stock,
49 | 'brand': instance.brand,
50 | 'thumbnail': instance.thumbnail,
51 | 'images': instance.images,
52 | };
53 |
--------------------------------------------------------------------------------
/example/android/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id "com.android.application"
3 | id "kotlin-android"
4 | id "dev.flutter.flutter-gradle-plugin"
5 | }
6 |
7 | def localProperties = new Properties()
8 | def localPropertiesFile = rootProject.file('local.properties')
9 | if (localPropertiesFile.exists()) {
10 | localPropertiesFile.withReader('UTF-8') { reader ->
11 | localProperties.load(reader)
12 | }
13 | }
14 |
15 | def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
16 | if (flutterVersionCode == null) {
17 | flutterVersionCode = '1'
18 | }
19 |
20 | def flutterVersionName = localProperties.getProperty('flutter.versionName')
21 | if (flutterVersionName == null) {
22 | flutterVersionName = '1.0'
23 | }
24 |
25 | android {
26 | namespace "com.example.example"
27 | compileSdkVersion flutter.compileSdkVersion
28 | ndkVersion flutter.ndkVersion
29 |
30 | compileOptions {
31 | sourceCompatibility JavaVersion.VERSION_1_8
32 | targetCompatibility JavaVersion.VERSION_1_8
33 | }
34 |
35 | kotlinOptions {
36 | jvmTarget = '1.8'
37 | }
38 |
39 | sourceSets {
40 | main.java.srcDirs += 'src/main/kotlin'
41 | }
42 |
43 | defaultConfig {
44 | // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
45 | applicationId "com.example.example"
46 | // You can update the following values to match your application needs.
47 | // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
48 | minSdkVersion flutter.minSdkVersion
49 | targetSdkVersion flutter.targetSdkVersion
50 | versionCode flutterVersionCode.toInteger()
51 | versionName flutterVersionName
52 | }
53 |
54 | buildTypes {
55 | release {
56 | // TODO: Add your own signing config for the release build.
57 | // Signing with the debug keys for now, so `flutter run --release` works.
58 | signingConfig signingConfigs.debug
59 | }
60 | }
61 | }
62 |
63 | flutter {
64 | source '../..'
65 | }
66 |
67 | dependencies {}
68 |
--------------------------------------------------------------------------------
/example/windows/runner/flutter_window.cpp:
--------------------------------------------------------------------------------
1 | #include "flutter_window.h"
2 |
3 | #include
4 |
5 | #include "flutter/generated_plugin_registrant.h"
6 |
7 | FlutterWindow::FlutterWindow(const flutter::DartProject& project)
8 | : project_(project) {}
9 |
10 | FlutterWindow::~FlutterWindow() {}
11 |
12 | bool FlutterWindow::OnCreate() {
13 | if (!Win32Window::OnCreate()) {
14 | return false;
15 | }
16 |
17 | RECT frame = GetClientArea();
18 |
19 | // The size here must match the window dimensions to avoid unnecessary surface
20 | // creation / destruction in the startup path.
21 | flutter_controller_ = std::make_unique(
22 | frame.right - frame.left, frame.bottom - frame.top, project_);
23 | // Ensure that basic setup of the controller was successful.
24 | if (!flutter_controller_->engine() || !flutter_controller_->view()) {
25 | return false;
26 | }
27 | RegisterPlugins(flutter_controller_->engine());
28 | SetChildContent(flutter_controller_->view()->GetNativeWindow());
29 |
30 | flutter_controller_->engine()->SetNextFrameCallback([&]() {
31 | this->Show();
32 | });
33 |
34 | // Flutter can complete the first frame before the "show window" callback is
35 | // registered. The following call ensures a frame is pending to ensure the
36 | // window is shown. It is a no-op if the first frame hasn't completed yet.
37 | flutter_controller_->ForceRedraw();
38 |
39 | return true;
40 | }
41 |
42 | void FlutterWindow::OnDestroy() {
43 | if (flutter_controller_) {
44 | flutter_controller_ = nullptr;
45 | }
46 |
47 | Win32Window::OnDestroy();
48 | }
49 |
50 | LRESULT
51 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message,
52 | WPARAM const wparam,
53 | LPARAM const lparam) noexcept {
54 | // Give Flutter, including plugins, an opportunity to handle window messages.
55 | if (flutter_controller_) {
56 | std::optional result =
57 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam,
58 | lparam);
59 | if (result) {
60 | return *result;
61 | }
62 | }
63 |
64 | switch (message) {
65 | case WM_FONTCHANGE:
66 | flutter_controller_->engine()->ReloadSystemFonts();
67 | break;
68 | }
69 |
70 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam);
71 | }
72 |
--------------------------------------------------------------------------------
/example/ios/Runner/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/example/lib/views/products_view.dart:
--------------------------------------------------------------------------------
1 | import 'package:example/models/products_model.dart';
2 | import 'package:example/providers/cart/cart_provider.dart';
3 | import 'package:example/providers/products/products_provider.dart';
4 | import 'package:flutter/material.dart';
5 | import 'package:flutter_riverpod/flutter_riverpod.dart';
6 | import 'package:go_router/go_router.dart';
7 |
8 | class ProductsView extends ConsumerWidget {
9 | const ProductsView({super.key});
10 |
11 | @override
12 | Widget build(BuildContext context, WidgetRef ref) {
13 | final response = ref.watch(fetchProductsProvider);
14 |
15 | return Scaffold(
16 | appBar: AppBar(
17 | title: const Text('Products'),
18 | actions: const [
19 | Padding(
20 | padding: EdgeInsets.all(8.0),
21 | child: ShoppingCartIcon(),
22 | ),
23 | ],
24 | ),
25 | body: switch (response) {
26 | AsyncData(:final value) => _buildMain(ref, value),
27 | AsyncError() => Text(response.error.toString()),
28 | _ => const CircularProgressIndicator(),
29 | });
30 | }
31 |
32 | ListView _buildMain(WidgetRef ref, ProductModel value) {
33 | return ListView.builder(
34 | itemCount: value.products.length,
35 | itemBuilder: (context, index) {
36 | var product = value.products[index];
37 | return Padding(
38 | padding: const EdgeInsets.symmetric(vertical: 8),
39 | child: ListTile(
40 | leading: CircleAvatar(
41 | radius: 20,
42 | backgroundColor:
43 | Color((product.title.hashCode * 0xFFFFFF).toInt())
44 | .withOpacity(1.0),
45 | ),
46 | title: Text(product.title),
47 | subtitle: Text('\$${product.price.toString()}'),
48 | trailing: TextButton(
49 | onPressed: () => _handleAddToCart(ref, product),
50 | child: const Text('Add to cart'),
51 | ),
52 | ),
53 | );
54 | },
55 | );
56 | }
57 |
58 | void _handleAddToCart(WidgetRef ref, ProductItemsModel product) {
59 | ref.read(cartNotifierProvider).addToCart(product);
60 | }
61 | }
62 |
63 | class ShoppingCartIcon extends ConsumerWidget {
64 | const ShoppingCartIcon({
65 | super.key,
66 | });
67 |
68 | @override
69 | Widget build(BuildContext context, WidgetRef ref) {
70 | var cart = ref.watch(cartNotifierProvider);
71 | return InkWell(
72 | onTap: () => context.push('/cart'),
73 | child: Badge(
74 | backgroundColor: Colors.purpleAccent,
75 | label: Text(cart.getCartCount.toString()),
76 | child: const Icon(
77 | Icons.shopping_cart,
78 | color: Colors.white,
79 | ),
80 | ),
81 | );
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/example/linux/flutter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # This file controls Flutter-level build steps. It should not be edited.
2 | cmake_minimum_required(VERSION 3.10)
3 |
4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
5 |
6 | # Configuration provided via flutter tool.
7 | include(${EPHEMERAL_DIR}/generated_config.cmake)
8 |
9 | # TODO: Move the rest of this into files in ephemeral. See
10 | # https://github.com/flutter/flutter/issues/57146.
11 |
12 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...),
13 | # which isn't available in 3.10.
14 | function(list_prepend LIST_NAME PREFIX)
15 | set(NEW_LIST "")
16 | foreach(element ${${LIST_NAME}})
17 | list(APPEND NEW_LIST "${PREFIX}${element}")
18 | endforeach(element)
19 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
20 | endfunction()
21 |
22 | # === Flutter Library ===
23 | # System-level dependencies.
24 | find_package(PkgConfig REQUIRED)
25 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
26 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
27 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
28 |
29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
30 |
31 | # Published to parent scope for install step.
32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
36 |
37 | list(APPEND FLUTTER_LIBRARY_HEADERS
38 | "fl_basic_message_channel.h"
39 | "fl_binary_codec.h"
40 | "fl_binary_messenger.h"
41 | "fl_dart_project.h"
42 | "fl_engine.h"
43 | "fl_json_message_codec.h"
44 | "fl_json_method_codec.h"
45 | "fl_message_codec.h"
46 | "fl_method_call.h"
47 | "fl_method_channel.h"
48 | "fl_method_codec.h"
49 | "fl_method_response.h"
50 | "fl_plugin_registrar.h"
51 | "fl_plugin_registry.h"
52 | "fl_standard_message_codec.h"
53 | "fl_standard_method_codec.h"
54 | "fl_string_codec.h"
55 | "fl_value.h"
56 | "fl_view.h"
57 | "flutter_linux.h"
58 | )
59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
60 | add_library(flutter INTERFACE)
61 | target_include_directories(flutter INTERFACE
62 | "${EPHEMERAL_DIR}"
63 | )
64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
65 | target_link_libraries(flutter INTERFACE
66 | PkgConfig::GTK
67 | PkgConfig::GLIB
68 | PkgConfig::GIO
69 | )
70 | add_dependencies(flutter flutter_assemble)
71 |
72 | # === Flutter tool backend ===
73 | # _phony_ is a non-existent file to force this command to run every time,
74 | # since currently there's no way to get a full input/output list from the
75 | # flutter tool.
76 | add_custom_command(
77 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
78 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_
79 | COMMAND ${CMAKE_COMMAND} -E env
80 | ${FLUTTER_TOOL_ENVIRONMENT}
81 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
82 | ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
83 | VERBATIM
84 | )
85 | add_custom_target(flutter_assemble DEPENDS
86 | "${FLUTTER_LIBRARY}"
87 | ${FLUTTER_LIBRARY_HEADERS}
88 | )
89 |
--------------------------------------------------------------------------------
/example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-App-20x20@2x.png",
7 | "scale" : "2x"
8 | },
9 | {
10 | "size" : "20x20",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-App-20x20@3x.png",
13 | "scale" : "3x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-App-29x29@1x.png",
19 | "scale" : "1x"
20 | },
21 | {
22 | "size" : "29x29",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-App-29x29@2x.png",
25 | "scale" : "2x"
26 | },
27 | {
28 | "size" : "29x29",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-App-29x29@3x.png",
31 | "scale" : "3x"
32 | },
33 | {
34 | "size" : "40x40",
35 | "idiom" : "iphone",
36 | "filename" : "Icon-App-40x40@2x.png",
37 | "scale" : "2x"
38 | },
39 | {
40 | "size" : "40x40",
41 | "idiom" : "iphone",
42 | "filename" : "Icon-App-40x40@3x.png",
43 | "scale" : "3x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-App-60x60@2x.png",
49 | "scale" : "2x"
50 | },
51 | {
52 | "size" : "60x60",
53 | "idiom" : "iphone",
54 | "filename" : "Icon-App-60x60@3x.png",
55 | "scale" : "3x"
56 | },
57 | {
58 | "size" : "20x20",
59 | "idiom" : "ipad",
60 | "filename" : "Icon-App-20x20@1x.png",
61 | "scale" : "1x"
62 | },
63 | {
64 | "size" : "20x20",
65 | "idiom" : "ipad",
66 | "filename" : "Icon-App-20x20@2x.png",
67 | "scale" : "2x"
68 | },
69 | {
70 | "size" : "29x29",
71 | "idiom" : "ipad",
72 | "filename" : "Icon-App-29x29@1x.png",
73 | "scale" : "1x"
74 | },
75 | {
76 | "size" : "29x29",
77 | "idiom" : "ipad",
78 | "filename" : "Icon-App-29x29@2x.png",
79 | "scale" : "2x"
80 | },
81 | {
82 | "size" : "40x40",
83 | "idiom" : "ipad",
84 | "filename" : "Icon-App-40x40@1x.png",
85 | "scale" : "1x"
86 | },
87 | {
88 | "size" : "40x40",
89 | "idiom" : "ipad",
90 | "filename" : "Icon-App-40x40@2x.png",
91 | "scale" : "2x"
92 | },
93 | {
94 | "size" : "76x76",
95 | "idiom" : "ipad",
96 | "filename" : "Icon-App-76x76@1x.png",
97 | "scale" : "1x"
98 | },
99 | {
100 | "size" : "76x76",
101 | "idiom" : "ipad",
102 | "filename" : "Icon-App-76x76@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "size" : "83.5x83.5",
107 | "idiom" : "ipad",
108 | "filename" : "Icon-App-83.5x83.5@2x.png",
109 | "scale" : "2x"
110 | },
111 | {
112 | "size" : "1024x1024",
113 | "idiom" : "ios-marketing",
114 | "filename" : "Icon-App-1024x1024@1x.png",
115 | "scale" : "1x"
116 | }
117 | ],
118 | "info" : {
119 | "version" : 1,
120 | "author" : "xcode"
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/example/windows/runner/Runner.rc:
--------------------------------------------------------------------------------
1 | // Microsoft Visual C++ generated resource script.
2 | //
3 | #pragma code_page(65001)
4 | #include "resource.h"
5 |
6 | #define APSTUDIO_READONLY_SYMBOLS
7 | /////////////////////////////////////////////////////////////////////////////
8 | //
9 | // Generated from the TEXTINCLUDE 2 resource.
10 | //
11 | #include "winres.h"
12 |
13 | /////////////////////////////////////////////////////////////////////////////
14 | #undef APSTUDIO_READONLY_SYMBOLS
15 |
16 | /////////////////////////////////////////////////////////////////////////////
17 | // English (United States) resources
18 |
19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
21 |
22 | #ifdef APSTUDIO_INVOKED
23 | /////////////////////////////////////////////////////////////////////////////
24 | //
25 | // TEXTINCLUDE
26 | //
27 |
28 | 1 TEXTINCLUDE
29 | BEGIN
30 | "resource.h\0"
31 | END
32 |
33 | 2 TEXTINCLUDE
34 | BEGIN
35 | "#include ""winres.h""\r\n"
36 | "\0"
37 | END
38 |
39 | 3 TEXTINCLUDE
40 | BEGIN
41 | "\r\n"
42 | "\0"
43 | END
44 |
45 | #endif // APSTUDIO_INVOKED
46 |
47 |
48 | /////////////////////////////////////////////////////////////////////////////
49 | //
50 | // Icon
51 | //
52 |
53 | // Icon with lowest ID value placed first to ensure application icon
54 | // remains consistent on all systems.
55 | IDI_APP_ICON ICON "resources\\app_icon.ico"
56 |
57 |
58 | /////////////////////////////////////////////////////////////////////////////
59 | //
60 | // Version
61 | //
62 |
63 | #if defined(FLUTTER_VERSION_MAJOR) && defined(FLUTTER_VERSION_MINOR) && defined(FLUTTER_VERSION_PATCH) && defined(FLUTTER_VERSION_BUILD)
64 | #define VERSION_AS_NUMBER FLUTTER_VERSION_MAJOR,FLUTTER_VERSION_MINOR,FLUTTER_VERSION_PATCH,FLUTTER_VERSION_BUILD
65 | #else
66 | #define VERSION_AS_NUMBER 1,0,0,0
67 | #endif
68 |
69 | #if defined(FLUTTER_VERSION)
70 | #define VERSION_AS_STRING FLUTTER_VERSION
71 | #else
72 | #define VERSION_AS_STRING "1.0.0"
73 | #endif
74 |
75 | VS_VERSION_INFO VERSIONINFO
76 | FILEVERSION VERSION_AS_NUMBER
77 | PRODUCTVERSION VERSION_AS_NUMBER
78 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
79 | #ifdef _DEBUG
80 | FILEFLAGS VS_FF_DEBUG
81 | #else
82 | FILEFLAGS 0x0L
83 | #endif
84 | FILEOS VOS__WINDOWS32
85 | FILETYPE VFT_APP
86 | FILESUBTYPE 0x0L
87 | BEGIN
88 | BLOCK "StringFileInfo"
89 | BEGIN
90 | BLOCK "040904e4"
91 | BEGIN
92 | VALUE "CompanyName", "com.example" "\0"
93 | VALUE "FileDescription", "example" "\0"
94 | VALUE "FileVersion", VERSION_AS_STRING "\0"
95 | VALUE "InternalName", "example" "\0"
96 | VALUE "LegalCopyright", "Copyright (C) 2024 com.example. All rights reserved." "\0"
97 | VALUE "OriginalFilename", "example.exe" "\0"
98 | VALUE "ProductName", "example" "\0"
99 | VALUE "ProductVersion", VERSION_AS_STRING "\0"
100 | END
101 | END
102 | BLOCK "VarFileInfo"
103 | BEGIN
104 | VALUE "Translation", 0x409, 1252
105 | END
106 | END
107 |
108 | #endif // English (United States) resources
109 | /////////////////////////////////////////////////////////////////////////////
110 |
111 |
112 |
113 | #ifndef APSTUDIO_INVOKED
114 | /////////////////////////////////////////////////////////////////////////////
115 | //
116 | // Generated from the TEXTINCLUDE 3 resource.
117 | //
118 |
119 |
120 | /////////////////////////////////////////////////////////////////////////////
121 | #endif // not APSTUDIO_INVOKED
122 |
--------------------------------------------------------------------------------
/example/windows/runner/win32_window.h:
--------------------------------------------------------------------------------
1 | #ifndef RUNNER_WIN32_WINDOW_H_
2 | #define RUNNER_WIN32_WINDOW_H_
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 |
10 | // A class abstraction for a high DPI-aware Win32 Window. Intended to be
11 | // inherited from by classes that wish to specialize with custom
12 | // rendering and input handling
13 | class Win32Window {
14 | public:
15 | struct Point {
16 | unsigned int x;
17 | unsigned int y;
18 | Point(unsigned int x, unsigned int y) : x(x), y(y) {}
19 | };
20 |
21 | struct Size {
22 | unsigned int width;
23 | unsigned int height;
24 | Size(unsigned int width, unsigned int height)
25 | : width(width), height(height) {}
26 | };
27 |
28 | Win32Window();
29 | virtual ~Win32Window();
30 |
31 | // Creates a win32 window with |title| that is positioned and sized using
32 | // |origin| and |size|. New windows are created on the default monitor. Window
33 | // sizes are specified to the OS in physical pixels, hence to ensure a
34 | // consistent size this function will scale the inputted width and height as
35 | // as appropriate for the default monitor. The window is invisible until
36 | // |Show| is called. Returns true if the window was created successfully.
37 | bool Create(const std::wstring& title, const Point& origin, const Size& size);
38 |
39 | // Show the current window. Returns true if the window was successfully shown.
40 | bool Show();
41 |
42 | // Release OS resources associated with window.
43 | void Destroy();
44 |
45 | // Inserts |content| into the window tree.
46 | void SetChildContent(HWND content);
47 |
48 | // Returns the backing Window handle to enable clients to set icon and other
49 | // window properties. Returns nullptr if the window has been destroyed.
50 | HWND GetHandle();
51 |
52 | // If true, closing this window will quit the application.
53 | void SetQuitOnClose(bool quit_on_close);
54 |
55 | // Return a RECT representing the bounds of the current client area.
56 | RECT GetClientArea();
57 |
58 | protected:
59 | // Processes and route salient window messages for mouse handling,
60 | // size change and DPI. Delegates handling of these to member overloads that
61 | // inheriting classes can handle.
62 | virtual LRESULT MessageHandler(HWND window,
63 | UINT const message,
64 | WPARAM const wparam,
65 | LPARAM const lparam) noexcept;
66 |
67 | // Called when CreateAndShow is called, allowing subclass window-related
68 | // setup. Subclasses should return false if setup fails.
69 | virtual bool OnCreate();
70 |
71 | // Called when Destroy is called.
72 | virtual void OnDestroy();
73 |
74 | private:
75 | friend class WindowClassRegistrar;
76 |
77 | // OS callback called by message pump. Handles the WM_NCCREATE message which
78 | // is passed when the non-client area is being created and enables automatic
79 | // non-client DPI scaling so that the non-client area automatically
80 | // responds to changes in DPI. All other messages are handled by
81 | // MessageHandler.
82 | static LRESULT CALLBACK WndProc(HWND const window,
83 | UINT const message,
84 | WPARAM const wparam,
85 | LPARAM const lparam) noexcept;
86 |
87 | // Retrieves a class instance pointer for |window|
88 | static Win32Window* GetThisFromHandle(HWND const window) noexcept;
89 |
90 | // Update the window frame's theme to match the system theme.
91 | static void UpdateTheme(HWND const window);
92 |
93 | bool quit_on_close_ = false;
94 |
95 | // window handle for top level window.
96 | HWND window_handle_ = nullptr;
97 |
98 | // window handle for hosted content.
99 | HWND child_content_ = nullptr;
100 | };
101 |
102 | #endif // RUNNER_WIN32_WINDOW_H_
103 |
--------------------------------------------------------------------------------
/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
43 |
49 |
50 |
51 |
52 |
53 |
63 |
65 |
71 |
72 |
73 |
74 |
80 |
82 |
88 |
89 |
90 |
91 |
93 |
94 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/example/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
37 |
38 |
39 |
40 |
43 |
49 |
50 |
51 |
52 |
53 |
63 |
65 |
71 |
72 |
73 |
74 |
80 |
82 |
88 |
89 |
90 |
91 |
93 |
94 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/example/linux/my_application.cc:
--------------------------------------------------------------------------------
1 | #include "my_application.h"
2 |
3 | #include
4 | #ifdef GDK_WINDOWING_X11
5 | #include
6 | #endif
7 |
8 | #include "flutter/generated_plugin_registrant.h"
9 |
10 | struct _MyApplication {
11 | GtkApplication parent_instance;
12 | char** dart_entrypoint_arguments;
13 | };
14 |
15 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
16 |
17 | // Implements GApplication::activate.
18 | static void my_application_activate(GApplication* application) {
19 | MyApplication* self = MY_APPLICATION(application);
20 | GtkWindow* window =
21 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
22 |
23 | // Use a header bar when running in GNOME as this is the common style used
24 | // by applications and is the setup most users will be using (e.g. Ubuntu
25 | // desktop).
26 | // If running on X and not using GNOME then just use a traditional title bar
27 | // in case the window manager does more exotic layout, e.g. tiling.
28 | // If running on Wayland assume the header bar will work (may need changing
29 | // if future cases occur).
30 | gboolean use_header_bar = TRUE;
31 | #ifdef GDK_WINDOWING_X11
32 | GdkScreen* screen = gtk_window_get_screen(window);
33 | if (GDK_IS_X11_SCREEN(screen)) {
34 | const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
35 | if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
36 | use_header_bar = FALSE;
37 | }
38 | }
39 | #endif
40 | if (use_header_bar) {
41 | GtkHeaderBar* header_bar = GTK_HEADER_BAR(gtk_header_bar_new());
42 | gtk_widget_show(GTK_WIDGET(header_bar));
43 | gtk_header_bar_set_title(header_bar, "example");
44 | gtk_header_bar_set_show_close_button(header_bar, TRUE);
45 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar));
46 | } else {
47 | gtk_window_set_title(window, "example");
48 | }
49 |
50 | gtk_window_set_default_size(window, 1280, 720);
51 | gtk_widget_show(GTK_WIDGET(window));
52 |
53 | g_autoptr(FlDartProject) project = fl_dart_project_new();
54 | fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
55 |
56 | FlView* view = fl_view_new(project);
57 | gtk_widget_show(GTK_WIDGET(view));
58 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
59 |
60 | fl_register_plugins(FL_PLUGIN_REGISTRY(view));
61 |
62 | gtk_widget_grab_focus(GTK_WIDGET(view));
63 | }
64 |
65 | // Implements GApplication::local_command_line.
66 | static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) {
67 | MyApplication* self = MY_APPLICATION(application);
68 | // Strip out the first argument as it is the binary name.
69 | self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
70 |
71 | g_autoptr(GError) error = nullptr;
72 | if (!g_application_register(application, nullptr, &error)) {
73 | g_warning("Failed to register: %s", error->message);
74 | *exit_status = 1;
75 | return TRUE;
76 | }
77 |
78 | g_application_activate(application);
79 | *exit_status = 0;
80 |
81 | return TRUE;
82 | }
83 |
84 | // Implements GObject::dispose.
85 | static void my_application_dispose(GObject* object) {
86 | MyApplication* self = MY_APPLICATION(object);
87 | g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
88 | G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
89 | }
90 |
91 | static void my_application_class_init(MyApplicationClass* klass) {
92 | G_APPLICATION_CLASS(klass)->activate = my_application_activate;
93 | G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
94 | G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
95 | }
96 |
97 | static void my_application_init(MyApplication* self) {}
98 |
99 | MyApplication* my_application_new() {
100 | return MY_APPLICATION(g_object_new(my_application_get_type(),
101 | "application-id", APPLICATION_ID,
102 | "flags", G_APPLICATION_NON_UNIQUE,
103 | nullptr));
104 | }
105 |
--------------------------------------------------------------------------------
/example/windows/flutter/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # This file controls Flutter-level build steps. It should not be edited.
2 | cmake_minimum_required(VERSION 3.14)
3 |
4 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
5 |
6 | # Configuration provided via flutter tool.
7 | include(${EPHEMERAL_DIR}/generated_config.cmake)
8 |
9 | # TODO: Move the rest of this into files in ephemeral. See
10 | # https://github.com/flutter/flutter/issues/57146.
11 | set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")
12 |
13 | # Set fallback configurations for older versions of the flutter tool.
14 | if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
15 | set(FLUTTER_TARGET_PLATFORM "windows-x64")
16 | endif()
17 |
18 | # === Flutter Library ===
19 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")
20 |
21 | # Published to parent scope for install step.
22 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
23 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
24 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
25 | set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE)
26 |
27 | list(APPEND FLUTTER_LIBRARY_HEADERS
28 | "flutter_export.h"
29 | "flutter_windows.h"
30 | "flutter_messenger.h"
31 | "flutter_plugin_registrar.h"
32 | "flutter_texture_registrar.h"
33 | )
34 | list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/")
35 | add_library(flutter INTERFACE)
36 | target_include_directories(flutter INTERFACE
37 | "${EPHEMERAL_DIR}"
38 | )
39 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib")
40 | add_dependencies(flutter flutter_assemble)
41 |
42 | # === Wrapper ===
43 | list(APPEND CPP_WRAPPER_SOURCES_CORE
44 | "core_implementations.cc"
45 | "standard_codec.cc"
46 | )
47 | list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/")
48 | list(APPEND CPP_WRAPPER_SOURCES_PLUGIN
49 | "plugin_registrar.cc"
50 | )
51 | list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/")
52 | list(APPEND CPP_WRAPPER_SOURCES_APP
53 | "flutter_engine.cc"
54 | "flutter_view_controller.cc"
55 | )
56 | list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/")
57 |
58 | # Wrapper sources needed for a plugin.
59 | add_library(flutter_wrapper_plugin STATIC
60 | ${CPP_WRAPPER_SOURCES_CORE}
61 | ${CPP_WRAPPER_SOURCES_PLUGIN}
62 | )
63 | apply_standard_settings(flutter_wrapper_plugin)
64 | set_target_properties(flutter_wrapper_plugin PROPERTIES
65 | POSITION_INDEPENDENT_CODE ON)
66 | set_target_properties(flutter_wrapper_plugin PROPERTIES
67 | CXX_VISIBILITY_PRESET hidden)
68 | target_link_libraries(flutter_wrapper_plugin PUBLIC flutter)
69 | target_include_directories(flutter_wrapper_plugin PUBLIC
70 | "${WRAPPER_ROOT}/include"
71 | )
72 | add_dependencies(flutter_wrapper_plugin flutter_assemble)
73 |
74 | # Wrapper sources needed for the runner.
75 | add_library(flutter_wrapper_app STATIC
76 | ${CPP_WRAPPER_SOURCES_CORE}
77 | ${CPP_WRAPPER_SOURCES_APP}
78 | )
79 | apply_standard_settings(flutter_wrapper_app)
80 | target_link_libraries(flutter_wrapper_app PUBLIC flutter)
81 | target_include_directories(flutter_wrapper_app PUBLIC
82 | "${WRAPPER_ROOT}/include"
83 | )
84 | add_dependencies(flutter_wrapper_app flutter_assemble)
85 |
86 | # === Flutter tool backend ===
87 | # _phony_ is a non-existent file to force this command to run every time,
88 | # since currently there's no way to get a full input/output list from the
89 | # flutter tool.
90 | set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_")
91 | set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE)
92 | add_custom_command(
93 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
94 | ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN}
95 | ${CPP_WRAPPER_SOURCES_APP}
96 | ${PHONY_OUTPUT}
97 | COMMAND ${CMAKE_COMMAND} -E env
98 | ${FLUTTER_TOOL_ENVIRONMENT}
99 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
100 | ${FLUTTER_TARGET_PLATFORM} $
101 | VERBATIM
102 | )
103 | add_custom_target(flutter_assemble DEPENDS
104 | "${FLUTTER_LIBRARY}"
105 | ${FLUTTER_LIBRARY_HEADERS}
106 | ${CPP_WRAPPER_SOURCES_CORE}
107 | ${CPP_WRAPPER_SOURCES_PLUGIN}
108 | ${CPP_WRAPPER_SOURCES_APP}
109 | )
110 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | 
3 |
4 | 
5 |
6 | Empower your Flutter app with seamless cart management using this powerful package. This comprehensive Flutter package offers a wide range of cart management features that simplify the process of adding, removing, and updating items in your app's cart. With its easy-to-use functionality, managing your app's cart has never been easier.
7 |
8 | ![sample]()
9 |
10 | ## Features
11 |
12 | - Initialization: Initialize the flutter_cart using initializeCart() method. Pass isPersistenceSupportEnabled to true to enable persistence support.
13 | - Add to Cart: Add products to the cart with the addToCart method.
14 | - Update Quantity: Update the quantity of the items e.g. increment/decrement using the updateQuantity method.
15 | - Remove from Cart: Remove specific items from the cart using the removeItem method.
16 | - Clear Cart: Remove all items from the cart using the clearCart method.
17 | - Apply Discount: Apply discount on item using the applyDiscount method. Note: you can also apply a discount at the time of adding the item to the cart.
18 | - Total Amount: Get the total amount of items in the cart using the total variable e.g. flutterCart.total.
19 | - Subtotal: Get the subtotal amount of items in the cart using the subtotal variable e.g. flutterCart.subtotal.
20 | - Items Count: Retrieve the total number of items in the cart using the cartLength variable e.g. flutterCart.cartLength.
21 | - Get Item Index: Use getProductIndex method to get the item index in the cart.
22 | - Get Specific Item: Use getSpecificProduct method to get the specific item from the cart.
23 | - Check Persistence Support: Use getPersistenceSupportStatus method to check the persistence support status.
24 |
25 | ## Usage
26 |
27 | To use this plugin, add `flutter_cart` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).
28 |
29 | ```
30 | dependencies:
31 | flutter:
32 | sdk: flutter
33 | flutter_cart:
34 | ```
35 | #### Note:
36 | This package is using [`shared_preferences`](https://pub.dev/packages/shared_preferences) for persisting cart items.
37 |
38 | ## Getting Started
39 |
40 | - ### Initialization
41 |
42 | first, create an instance of flutter_cart package.
43 |
44 | ```
45 | // Set [isPersistenceSupportEnabled] to true to turn on the cart persistence
46 | void main() async {
47 | WidgetsFlutterBinding.ensureInitialized();
48 | var cart = FlutterCart();
49 | await cart.initializeCart(isPersistenceSupportEnabled: true);
50 | runApp(MyApp());
51 | }
52 | ```
53 |
54 | - ### Add to cart 🛒
55 | ```
56 | // This method is called when we have to add an item to the cart
57 | // Example:
58 | void addToCart(YourProductModel product) {
59 | flutterCart.addToCart(
60 | cartModel: CartModel(
61 | // ... other parameters
62 | if [discount] is applicable and in percentage so, you can
63 | calculate the discount like this
64 | var discount = (product.discountPercentage / 100) * product.price;
65 | discount: discount,
66 | [productMeta] takes Map so, you can store your complete product data in productMeta
67 | productMeta: product.toJson()),
68 | );
69 | }
70 | ```
71 | - ### Update quantity ➕/ ➖
72 | ```
73 | // [updateQuantity] is used to increment/decrement the item quantity
74 | // Example:
75 | void updateQuantity(CartModel item, int newQuantity) {
76 | flutterCart.updateQuantity(
77 | item.productId, item.variants, newQuantity);
78 | }
79 | ```
80 | - ### Remove item 🗑️
81 | ```
82 | // [removeItem] is used for removing the specific item from the cart
83 | // Example:
84 | void removeItemFromCart(CartModel item) {
85 | flutterCart.removeItem(item.productId, item.variants);
86 | }
87 | ```
88 | - ### Clear cart 🧹
89 | ```
90 | void clearCart() {
91 | flutterCart.clearCart();
92 | }
93 | ```
94 | - ### Get cart Items
95 | ```
96 | List get getCartItems => flutterCart.cartItemsList;
97 | ```
98 | - ### Total quantity
99 | ```
100 | int get getCartCount => flutterCart.cartLength;
101 | ```
102 | - ### Total amount
103 | ```
104 | double get getTotalAmount => flutterCart.total;
105 | ```
106 | - ### Subtotal
107 | ```
108 | double get subtotal => flutterCart.subtotal;
109 | ```
110 |
--------------------------------------------------------------------------------
/example/windows/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Project-level configuration.
2 | cmake_minimum_required(VERSION 3.14)
3 | project(example LANGUAGES CXX)
4 |
5 | # The name of the executable created for the application. Change this to change
6 | # the on-disk name of your application.
7 | set(BINARY_NAME "example")
8 |
9 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent
10 | # versions of CMake.
11 | cmake_policy(VERSION 3.14...3.25)
12 |
13 | # Define build configuration option.
14 | get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
15 | if(IS_MULTICONFIG)
16 | set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
17 | CACHE STRING "" FORCE)
18 | else()
19 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
20 | set(CMAKE_BUILD_TYPE "Debug" CACHE
21 | STRING "Flutter build mode" FORCE)
22 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
23 | "Debug" "Profile" "Release")
24 | endif()
25 | endif()
26 | # Define settings for the Profile build mode.
27 | set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
28 | set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
29 | set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
30 | set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")
31 |
32 | # Use Unicode for all projects.
33 | add_definitions(-DUNICODE -D_UNICODE)
34 |
35 | # Compilation settings that should be applied to most targets.
36 | #
37 | # Be cautious about adding new options here, as plugins use this function by
38 | # default. In most cases, you should add new options to specific targets instead
39 | # of modifying this function.
40 | function(APPLY_STANDARD_SETTINGS TARGET)
41 | target_compile_features(${TARGET} PUBLIC cxx_std_17)
42 | target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
43 | target_compile_options(${TARGET} PRIVATE /EHsc)
44 | target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
45 | target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>")
46 | endfunction()
47 |
48 | # Flutter library and tool build rules.
49 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
50 | add_subdirectory(${FLUTTER_MANAGED_DIR})
51 |
52 | # Application build; see runner/CMakeLists.txt.
53 | add_subdirectory("runner")
54 |
55 |
56 | # Generated plugin build rules, which manage building the plugins and adding
57 | # them to the application.
58 | include(flutter/generated_plugins.cmake)
59 |
60 |
61 | # === Installation ===
62 | # Support files are copied into place next to the executable, so that it can
63 | # run in place. This is done instead of making a separate bundle (as on Linux)
64 | # so that building and running from within Visual Studio will work.
65 | set(BUILD_BUNDLE_DIR "$")
66 | # Make the "install" step default, as it's required to run.
67 | set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
68 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
69 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
70 | endif()
71 |
72 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
73 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}")
74 |
75 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
76 | COMPONENT Runtime)
77 |
78 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
79 | COMPONENT Runtime)
80 |
81 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
82 | COMPONENT Runtime)
83 |
84 | if(PLUGIN_BUNDLED_LIBRARIES)
85 | install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
86 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
87 | COMPONENT Runtime)
88 | endif()
89 |
90 | # Copy the native assets provided by the build.dart from all packages.
91 | set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/")
92 | install(DIRECTORY "${NATIVE_ASSETS_DIR}"
93 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
94 | COMPONENT Runtime)
95 |
96 | # Fully re-copy the assets directory on each build to avoid having stale files
97 | # from a previous install.
98 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
99 | install(CODE "
100 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
101 | " COMPONENT Runtime)
102 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
103 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
104 |
105 | # Install the AOT library on non-Debug builds only.
106 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
107 | CONFIGURATIONS Profile;Release
108 | COMPONENT Runtime)
109 |
--------------------------------------------------------------------------------
/example/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: example
2 | description: "A new Flutter project."
3 | # The following line prevents the package from being accidentally published to
4 | # pub.dev using `flutter pub publish`. This is preferred for private packages.
5 | publish_to: "none" # Remove this line if you wish to publish to pub.dev
6 |
7 | # The following defines the version and build number for your application.
8 | # A version number is three numbers separated by dots, like 1.2.43
9 | # followed by an optional build number separated by a +.
10 | # Both the version and the builder number may be overridden in flutter
11 | # build by specifying --build-name and --build-number, respectively.
12 | # In Android, build-name is used as versionName while build-number used as versionCode.
13 | # Read more about Android versioning at https://developer.android.com/studio/publish/versioning
14 | # In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
15 | # Read more about iOS versioning at
16 | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
17 | # In Windows, build-name is used as the major, minor, and patch parts
18 | # of the product and file versions while build-number is used as the build suffix.
19 | version: 1.0.0+1
20 |
21 | environment:
22 | sdk: ">=3.2.6 <4.0.0"
23 |
24 | # Dependencies specify other packages that your package needs in order to work.
25 | # To automatically upgrade your package dependencies to the latest versions
26 | # consider running `flutter pub upgrade --major-versions`. Alternatively,
27 | # dependencies can be manually updated by changing the version numbers below to
28 | # the latest version available on pub.dev. To see which dependencies have newer
29 | # versions available, run `flutter pub outdated`.
30 | dependencies:
31 | flutter:
32 | sdk: flutter
33 | go_router: ^13.1.0
34 | freezed: ^2.4.6
35 | freezed_annotation: ^2.4.1
36 | flutter_riverpod: ^2.4.10
37 | riverpod_annotation: ^2.3.4
38 | flutter_cart:
39 | # When depending on this package from a real application you should use:
40 | # flutter_cart: ^x.y.z
41 | # See https://dart.dev/tools/pub/dependencies#version-constraints
42 | # The example app is bundled with the plugin so we use a path dependency on
43 | # the parent directory to use the current plugin's version.
44 | path: ../
45 |
46 | # The following adds the Cupertino Icons font to your application.
47 | # Use with the CupertinoIcons class for iOS style icons.
48 | cupertino_icons: ^1.0.2
49 |
50 | dev_dependencies:
51 | flutter_test:
52 | sdk: flutter
53 | build_runner: ^2.4.8
54 | json_serializable: ^6.7.1
55 | # The "flutter_lints" package below contains a set of recommended lints to
56 | # encourage good coding practices. The lint set provided by the package is
57 | # activated in the `analysis_options.yaml` file located at the root of your
58 | # package. See that file for information about deactivating specific lint
59 | # rules and activating additional ones.
60 | flutter_lints: ^2.0.0
61 | custom_lint:
62 | riverpod_generator: ^2.3.11
63 | riverpod_lint: ^2.3.9
64 |
65 | # For information on the generic Dart part of this file, see the
66 | # following page: https://dart.dev/tools/pub/pubspec
67 |
68 | # The following section is specific to Flutter packages.
69 | flutter:
70 | # The following line ensures that the Material Icons font is
71 | # included with your application, so that you can use the icons in
72 | # the material Icons class.
73 | uses-material-design: true
74 |
75 | # To add assets to your application, add an assets section, like this:
76 | assets:
77 | - assets/products.json
78 | # - images/a_dot_ham.jpeg
79 |
80 | # An image asset can refer to one or more resolution-specific "variants", see
81 | # https://flutter.dev/assets-and-images/#resolution-aware
82 |
83 | # For details regarding adding assets from package dependencies, see
84 | # https://flutter.dev/assets-and-images/#from-packages
85 |
86 | # To add custom fonts to your application, add a fonts section here,
87 | # in this "flutter" section. Each entry in this list should have a
88 | # "family" key with the font family name, and a "fonts" key with a
89 | # list giving the asset and other descriptors for the font. For
90 | # example:
91 | # fonts:
92 | # - family: Schyler
93 | # fonts:
94 | # - asset: fonts/Schyler-Regular.ttf
95 | # - asset: fonts/Schyler-Italic.ttf
96 | # style: italic
97 | # - family: Trajan Pro
98 | # fonts:
99 | # - asset: fonts/TrajanPro.ttf
100 | # - asset: fonts/TrajanPro_Bold.ttf
101 | # weight: 700
102 | #
103 | # For details regarding fonts from package dependencies,
104 | # see https://flutter.dev/custom-fonts/#from-packages
105 |
--------------------------------------------------------------------------------
/test/flutter_cart_test.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_cart/flutter_cart.dart';
2 | import 'package:flutter_test/flutter_test.dart';
3 | import 'package:shared_preferences/shared_preferences.dart';
4 |
5 | void main() {
6 | setUp(() async {
7 | TestWidgetsFlutterBinding.ensureInitialized();
8 | SharedPreferences.setMockInitialValues({});
9 | });
10 |
11 | test('addToCart should add items to the cart', () async {
12 | // Arrange
13 | final cart = FlutterCart();
14 | await cart.initializeCart();
15 |
16 | final cartModel1 = CartModel(
17 | productId: '1',
18 | variants: [ProductVariant(price: 1000)],
19 | quantity: 2,
20 | productName: 'Product 1',
21 | productDetails: 'This is a product 1');
22 | final cartModel2 = CartModel(
23 | productId: '2',
24 | variants: [ProductVariant(price: 2000)],
25 | quantity: 4,
26 | productName: 'Product 2',
27 | productDetails: 'This is a product 2');
28 |
29 | // Act
30 | cart.addToCart(cartModel: cartModel1);
31 | cart.addToCart(cartModel: cartModel2);
32 |
33 | // Assert
34 | expect(cart.cartItemsList.length, 2);
35 | expect(cart.cartItemsList[0].quantity, 2);
36 | expect(cart.cartItemsList[1].quantity, 4);
37 | var persistItem = cart.persistenceCartItemsList;
38 | expect(persistItem, null);
39 | });
40 |
41 | test('addToCart should add items to the cart with persistance', () async {
42 | // Arrange
43 | final cart = FlutterCart();
44 | await cart.initializeCart(isPersistenceSupportEnabled: true);
45 |
46 | final cartModel1 = CartModel(
47 | productId: '1',
48 | variants: [ProductVariant(price: 1000)],
49 | quantity: 2,
50 | productName: 'Product 1',
51 | productDetails: 'This is a product 1');
52 | final cartModel2 = CartModel(
53 | productId: '2',
54 | variants: [ProductVariant(price: 2000)],
55 | quantity: 4,
56 | productName: 'Product 2',
57 | productDetails: 'This is a product 2');
58 |
59 | // Act
60 | cart.addToCart(cartModel: cartModel1);
61 | cart.addToCart(cartModel: cartModel2);
62 |
63 | // Assert
64 | expect(cart.cartItemsList.length, 2);
65 | expect(cart.persistenceCartItemsList?.length, 2);
66 | });
67 |
68 | test('addToCart should update quantity for existing items', () async {
69 | // Arrange
70 | final cart = FlutterCart();
71 | await cart.initializeCart();
72 | final cartModel1 = CartModel(
73 | productId: '1',
74 | variants: [ProductVariant(price: 1000)],
75 | quantity: 2,
76 | productName: 'Product 1',
77 | productDetails: 'This is a product 1');
78 | final cartModel2 = CartModel(
79 | productId: '1',
80 | variants: [ProductVariant(price: 1000)],
81 | quantity: 3,
82 | productName: 'Product 1',
83 | productDetails: 'This is a product 1');
84 |
85 | // Act
86 | cart.addToCart(cartModel: cartModel1);
87 | cart.addToCart(cartModel: cartModel2);
88 |
89 | // Assert
90 | expect(cart.cartItemsList.length, 1);
91 | expect(cart.cartItemsList[0].quantity, 5);
92 | });
93 |
94 | test('updateQuantity should update the quantity for existing items',
95 | () async {
96 | // Arrange
97 | final cart = FlutterCart();
98 | await cart.initializeCart();
99 | final cartModel1 = CartModel(
100 | productId: '1',
101 | variants: [ProductVariant(price: 1000)],
102 | quantity: 2,
103 | productName: 'Product 1',
104 | productDetails: 'This is a product 1');
105 |
106 | // Act
107 | cart.addToCart(cartModel: cartModel1);
108 | cart.updateQuantity(cartModel1.productId, cartModel1.variants, 4);
109 |
110 | // Assert
111 | expect(cart.cartItemsList.length, 1);
112 | expect(cart.cartItemsList[0].quantity, 4);
113 | });
114 |
115 | test('removeItem should remove the item from cart', () async {
116 | // Arrange
117 | final cart = FlutterCart();
118 | await cart.initializeCart();
119 | final cartModel1 = CartModel(
120 | productId: '1',
121 | variants: [ProductVariant(price: 1000)],
122 | quantity: 2,
123 | productName: 'Product 1',
124 | productDetails: 'This is a product 1');
125 | final cartModel2 = CartModel(
126 | productId: '2',
127 | variants: [ProductVariant(price: 2000)],
128 | quantity: 4,
129 | productName: 'Product 2',
130 | productDetails: 'This is a product 2');
131 |
132 | // Act
133 | cart.addToCart(cartModel: cartModel1);
134 | cart.addToCart(cartModel: cartModel2);
135 |
136 | cart.removeItem(cartModel1.productId, cartModel1.variants);
137 |
138 | // Assert
139 | expect(cart.cartItemsList.length, 1);
140 | });
141 |
142 | test('getProductIndex should get the item index from cart', () async {
143 | // Arrange
144 | final cart = FlutterCart();
145 | await cart.initializeCart();
146 | final cartModel1 = CartModel(
147 | productId: '1',
148 | variants: [ProductVariant(price: 1000)],
149 | quantity: 2,
150 | productName: 'Product 1',
151 | productDetails: 'This is a product 1');
152 | final cartModel2 = CartModel(
153 | productId: '2',
154 | variants: [ProductVariant(price: 2000)],
155 | quantity: 4,
156 | productName: 'Product 2',
157 | productDetails: 'This is a product 2');
158 |
159 | // Act
160 | cart.addToCart(cartModel: cartModel1);
161 | cart.addToCart(cartModel: cartModel2);
162 |
163 | var index = cart.getProductIndex(cartModel2.productId, cartModel2.variants);
164 |
165 | // Assert
166 | expect(index, 1);
167 | });
168 | }
169 |
--------------------------------------------------------------------------------
/example/lib/views/cart_view.dart:
--------------------------------------------------------------------------------
1 | import 'package:example/providers/cart/cart_provider.dart';
2 | import 'package:flutter/material.dart';
3 | import 'package:flutter_cart/flutter_cart.dart';
4 | import 'package:flutter_riverpod/flutter_riverpod.dart';
5 |
6 | class CartView extends ConsumerWidget {
7 | const CartView({super.key});
8 |
9 | @override
10 | Widget build(BuildContext context, WidgetRef ref) {
11 | var cart = ref.watch(cartNotifierProvider);
12 | return Scaffold(
13 | appBar: AppBar(
14 | title: const Text('Cart'),
15 | actions: [
16 | IconButton(
17 | onPressed: () => clearCart(ref),
18 | icon: const Icon(
19 | Icons.delete,
20 | color: Colors.white,
21 | ),
22 | )
23 | ],
24 | ),
25 | body: Stack(
26 | alignment: Alignment.bottomCenter,
27 | children: [
28 | _buildCartItemList(cart, ref),
29 | _buildTotal(context, cart),
30 | ],
31 | ),
32 | );
33 | }
34 |
35 | Padding _buildTotal(BuildContext context, CartNotifier cart) {
36 | return Padding(
37 | padding: const EdgeInsets.all(16),
38 | child: SizedBox(
39 | width: MediaQuery.of(context).size.width,
40 | child: Card(
41 | child: Padding(
42 | padding: const EdgeInsets.all(8.0),
43 | child: Column(
44 | mainAxisSize: MainAxisSize.min,
45 | children: [
46 | Row(
47 | mainAxisAlignment: MainAxisAlignment.spaceBetween,
48 | children: [
49 | const Text(
50 | 'Subtotal',
51 | style: TextStyle(
52 | fontSize: 12,
53 | color: Colors.deepPurple,
54 | fontWeight: FontWeight.w700),
55 | ),
56 | Text(
57 | '\$${cart.subtotal}',
58 | style: const TextStyle(
59 | fontSize: 12, color: Colors.deepPurple),
60 | ),
61 | ],
62 | ),
63 | Row(
64 | mainAxisAlignment: MainAxisAlignment.spaceBetween,
65 | children: [
66 | const Text(
67 | 'Total',
68 | style: TextStyle(
69 | fontSize: 18,
70 | color: Colors.deepPurple,
71 | fontWeight: FontWeight.w700),
72 | ),
73 | Text(
74 | '\$${cart.getTotalAmount}',
75 | style: const TextStyle(
76 | fontSize: 16, color: Colors.deepPurple),
77 | ),
78 | ],
79 | ),
80 | ],
81 | ),
82 | ),
83 | ),
84 | ),
85 | );
86 | }
87 |
88 | ListView _buildCartItemList(CartNotifier cart, WidgetRef ref) {
89 | return ListView.builder(
90 | itemCount: cart.getCartItems.length,
91 | itemBuilder: (context, index) {
92 | var item = cart.getCartItems[index];
93 | const width4 = SizedBox(
94 | width: 4,
95 | );
96 | return Dismissible(
97 | key: Key(item.productId),
98 | background: Container(
99 | alignment: Alignment.centerRight,
100 | padding: const EdgeInsets.only(right: 20),
101 | color: Colors.red,
102 | child: const Text(
103 | 'swipe to delete',
104 | style: TextStyle(color: Colors.white),
105 | ),
106 | ),
107 | child: Padding(
108 | padding: const EdgeInsets.symmetric(vertical: 8),
109 | child: ListTile(
110 | leading: CircleAvatar(
111 | radius: 20,
112 | backgroundColor:
113 | Color((item.productId.hashCode * 0xFFFFFF).toInt())
114 | .withOpacity(1.0),
115 | ),
116 | title: Text(item.productName),
117 | subtitle: Text('\$${item.variants[0].price.toString()}'),
118 | trailing: Row(
119 | mainAxisSize: MainAxisSize.min,
120 | children: [
121 | IconButton(
122 | onPressed: () => decrementItemCount(ref, item),
123 | icon: const Icon(Icons.remove),
124 | ),
125 | width4,
126 | Text(
127 | item.quantity.toString(),
128 | style:
129 | const TextStyle(fontSize: 16, color: Colors.deepPurple),
130 | ),
131 | width4,
132 | IconButton(
133 | onPressed: () => incrementItemCount(ref, item),
134 | icon: const Icon(Icons.add),
135 | ),
136 | ],
137 | ),
138 | ),
139 | ),
140 | onDismissed: (direction) => deleteItem(ref, item),
141 | );
142 | },
143 | );
144 | }
145 |
146 | void clearCart(WidgetRef ref) {
147 | ref.read(cartNotifierProvider).clearCart();
148 | }
149 |
150 | void deleteItem(WidgetRef ref, CartModel item) {
151 | ref.read(cartNotifierProvider).removeItemFromCart(item);
152 | }
153 |
154 | void decrementItemCount(WidgetRef ref, CartModel item) {
155 | ref.read(cartNotifierProvider).updateQuantity(item, item.quantity - 1);
156 | }
157 |
158 | void incrementItemCount(WidgetRef ref, CartModel item) {
159 | ref.read(cartNotifierProvider).updateQuantity(item, item.quantity + 1);
160 | }
161 | }
162 |
--------------------------------------------------------------------------------
/example/linux/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | # Project-level configuration.
2 | cmake_minimum_required(VERSION 3.10)
3 | project(runner LANGUAGES CXX)
4 |
5 | # The name of the executable created for the application. Change this to change
6 | # the on-disk name of your application.
7 | set(BINARY_NAME "example")
8 | # The unique GTK application identifier for this application. See:
9 | # https://wiki.gnome.org/HowDoI/ChooseApplicationID
10 | set(APPLICATION_ID "com.example.example")
11 |
12 | # Explicitly opt in to modern CMake behaviors to avoid warnings with recent
13 | # versions of CMake.
14 | cmake_policy(SET CMP0063 NEW)
15 |
16 | # Load bundled libraries from the lib/ directory relative to the binary.
17 | set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")
18 |
19 | # Root filesystem for cross-building.
20 | if(FLUTTER_TARGET_PLATFORM_SYSROOT)
21 | set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
22 | set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
23 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
24 | set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
25 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
26 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
27 | endif()
28 |
29 | # Define build configuration options.
30 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
31 | set(CMAKE_BUILD_TYPE "Debug" CACHE
32 | STRING "Flutter build mode" FORCE)
33 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
34 | "Debug" "Profile" "Release")
35 | endif()
36 |
37 | # Compilation settings that should be applied to most targets.
38 | #
39 | # Be cautious about adding new options here, as plugins use this function by
40 | # default. In most cases, you should add new options to specific targets instead
41 | # of modifying this function.
42 | function(APPLY_STANDARD_SETTINGS TARGET)
43 | target_compile_features(${TARGET} PUBLIC cxx_std_14)
44 | target_compile_options(${TARGET} PRIVATE -Wall -Werror)
45 | target_compile_options(${TARGET} PRIVATE "$<$>:-O3>")
46 | target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>")
47 | endfunction()
48 |
49 | # Flutter library and tool build rules.
50 | set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
51 | add_subdirectory(${FLUTTER_MANAGED_DIR})
52 |
53 | # System-level dependencies.
54 | find_package(PkgConfig REQUIRED)
55 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
56 |
57 | add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
58 |
59 | # Define the application target. To change its name, change BINARY_NAME above,
60 | # not the value here, or `flutter run` will no longer work.
61 | #
62 | # Any new source files that you add to the application should be added here.
63 | add_executable(${BINARY_NAME}
64 | "main.cc"
65 | "my_application.cc"
66 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
67 | )
68 |
69 | # Apply the standard set of build settings. This can be removed for applications
70 | # that need different build settings.
71 | apply_standard_settings(${BINARY_NAME})
72 |
73 | # Add dependency libraries. Add any application-specific dependencies here.
74 | target_link_libraries(${BINARY_NAME} PRIVATE flutter)
75 | target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
76 |
77 | # Run the Flutter tool portions of the build. This must not be removed.
78 | add_dependencies(${BINARY_NAME} flutter_assemble)
79 |
80 | # Only the install-generated bundle's copy of the executable will launch
81 | # correctly, since the resources must in the right relative locations. To avoid
82 | # people trying to run the unbundled copy, put it in a subdirectory instead of
83 | # the default top-level location.
84 | set_target_properties(${BINARY_NAME}
85 | PROPERTIES
86 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
87 | )
88 |
89 |
90 | # Generated plugin build rules, which manage building the plugins and adding
91 | # them to the application.
92 | include(flutter/generated_plugins.cmake)
93 |
94 |
95 | # === Installation ===
96 | # By default, "installing" just makes a relocatable bundle in the build
97 | # directory.
98 | set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
99 | if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
100 | set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
101 | endif()
102 |
103 | # Start with a clean build bundle directory every time.
104 | install(CODE "
105 | file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
106 | " COMPONENT Runtime)
107 |
108 | set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
109 | set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
110 |
111 | install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
112 | COMPONENT Runtime)
113 |
114 | install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
115 | COMPONENT Runtime)
116 |
117 | install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
118 | COMPONENT Runtime)
119 |
120 | foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
121 | install(FILES "${bundled_library}"
122 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
123 | COMPONENT Runtime)
124 | endforeach(bundled_library)
125 |
126 | # Copy the native assets provided by the build.dart from all packages.
127 | set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/")
128 | install(DIRECTORY "${NATIVE_ASSETS_DIR}"
129 | DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
130 | COMPONENT Runtime)
131 |
132 | # Fully re-copy the assets directory on each build to avoid having stale files
133 | # from a previous install.
134 | set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
135 | install(CODE "
136 | file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
137 | " COMPONENT Runtime)
138 | install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
139 | DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)
140 |
141 | # Install the AOT library on non-Debug builds only.
142 | if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
143 | install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
144 | COMPONENT Runtime)
145 | endif()
146 |
--------------------------------------------------------------------------------
/lib/cart.dart:
--------------------------------------------------------------------------------
1 | import 'dart:async';
2 | import 'dart:convert';
3 | import 'package:flutter_cart/constants/shared_pref_constants.dart';
4 | import 'package:shared_preferences/shared_preferences.dart';
5 | import 'model/cart_model.dart';
6 |
7 | class FlutterCart {
8 | static final FlutterCart _instance = FlutterCart._internal();
9 | late List _cartItemsList;
10 | late final SharedPreferences _sharedPreference;
11 |
12 | factory FlutterCart() {
13 | return _instance;
14 | }
15 | FlutterCart._internal();
16 |
17 | /// Set [isPersistenceSupportEnabled] to true to turn on the cart persistence
18 | /// Example:
19 | /// void main() async {
20 | /// WidgetsFlutterBinding.ensureInitialized();
21 | /// var cart = FlutterCart();
22 | /// await cart.initializeCart(isPersistenceSupportEnabled: true);
23 | /// runApp(MyApp());
24 | /// }
25 | Future initializeCart(
26 | {bool isPersistenceSupportEnabled = false}) async {
27 | _cartItemsList = [];
28 | _sharedPreference = await SharedPreferences.getInstance();
29 | await _enableAndDisableCartPersistenceSupport(
30 | isPersistenceSupportEnabled: isPersistenceSupportEnabled);
31 | if (isPersistenceSupportEnabled) {
32 | _cartItemsList = _getPersistenceCartItems() ?? [];
33 | }
34 | }
35 |
36 | /// This method is called when we have to add an item to the cart
37 | /// Example:
38 | /// void addToCart(YourProductModel product) {
39 | /// flutterCart.addToCart(
40 | /// cartModel: CartModel(
41 | /// // ... other parameters
42 | /// if [discount] is applicable and in percentage so, you can
43 | /// calculate the discount like this
44 | /// var discount = (product.discountPercentage / 100) * product.price;
45 | /// discount: discount,
46 | /// [productMeta] takes Map so, you can store your complete product data in productMeta
47 | /// productMeta: product.toJson()),
48 | /// );
49 | /// }
50 | void addToCart({required CartModel cartModel}) {
51 | var existingItemIndex =
52 | getProductIndex(cartModel.productId, cartModel.variants);
53 |
54 | if (existingItemIndex != -1) {
55 | var quantity =
56 | _cartItemsList[existingItemIndex].quantity + cartModel.quantity;
57 | _cartItemsList[existingItemIndex] =
58 | _cartItemsList[existingItemIndex].copyWith(quantity: quantity);
59 | } else {
60 | _cartItemsList.add(cartModel);
61 | }
62 | if (getPersistenceSupportStatus()) {
63 | _updatePersistenceCart(_cartItemsList);
64 | }
65 | }
66 |
67 | /// [updateQuantity] is used to increment/decrement the item quantity
68 | /// Example:
69 | /// void updateQuantity(CartModel item, int newQuantity) {
70 | /// flutterCart.updateQuantity(
71 | /// item.productId, item.variants, newQuantity);
72 | /// }
73 |
74 | void updateQuantity(
75 | String productId, List variants, int newQuantity) {
76 | if (newQuantity == 0) {
77 | removeItem(productId, variants);
78 | } else {
79 | var itemIndex = _cartItemsList.indexWhere((item) =>
80 | item.productId == productId &&
81 | _areVariantsEqual(item.variants, variants));
82 |
83 | if (itemIndex != -1) {
84 | _cartItemsList[itemIndex] =
85 | _cartItemsList[itemIndex].copyWith(quantity: newQuantity);
86 | if (getPersistenceSupportStatus()) {
87 | _updatePersistenceCart(_cartItemsList);
88 | }
89 | }
90 | }
91 | }
92 |
93 | /// [removeItem] is used for removing the specific item from the cart
94 | /// Example:
95 | /// void removeItemFromCart(CartModel item) {
96 | // flutterCart.removeItem(item.productId, item.variants);
97 | // }
98 | void removeItem(String productId, List variants) {
99 | _cartItemsList.removeWhere((item) =>
100 | item.productId == productId &&
101 | _areVariantsEqual(item.variants, variants));
102 | if (getPersistenceSupportStatus()) {
103 | _updatePersistenceCart(_cartItemsList);
104 | }
105 | }
106 |
107 | /// [getSpecificProduct] will return the specific item from cart
108 | CartModel? getSpecificProduct(
109 | String productId,
110 | List variants,
111 | ) {
112 | var itemIndex = getProductIndex(productId, variants);
113 | if (itemIndex != -1) {
114 | return _cartItemsList[itemIndex];
115 | }
116 | return null;
117 | }
118 |
119 | /// [getProductIndex] will return the specific item index
120 | int getProductIndex(
121 | String productId,
122 | List variants,
123 | ) {
124 | var itemIndex = _cartItemsList.indexWhere((item) =>
125 | item.productId == productId &&
126 | _areVariantsEqual(item.variants, variants));
127 |
128 | return itemIndex;
129 | }
130 |
131 | /// [applyDiscount] use this method when you have case where you have to apply discount
132 | /// on specific product. Otherwise you can also apply discount the time of adding product into the cart.
133 | /// Check [addToCart] example for more info.
134 | void applyDiscount(
135 | String productId, List variants, double discount) {
136 | var itemIndex = getProductIndex(productId, variants);
137 |
138 | if (itemIndex != -1) {
139 | _cartItemsList[itemIndex] =
140 | _cartItemsList[itemIndex].copyWith(discount: discount);
141 | }
142 | }
143 |
144 | /// [clearCart] will clear the complete cart, including both in-memory and persistent cart data.
145 | void clearCart() {
146 | _cartItemsList.clear();
147 | unawaited(_clearPersistenceCart());
148 | }
149 |
150 | /// [getPersistenceSupportStatus] use this method to check the persistence storage enable/disable status
151 | bool getPersistenceSupportStatus() {
152 | var status = _sharedPreference
153 | .getBool(SharedPreferenceConstants.isPersistenceSupportEnabled);
154 | return status ?? false;
155 | }
156 |
157 | //By default the persistence support will be off
158 | Future _enableAndDisableCartPersistenceSupport(
159 | {required bool isPersistenceSupportEnabled}) async {
160 | try {
161 | await _sharedPreference.setBool(
162 | SharedPreferenceConstants.isPersistenceSupportEnabled,
163 | isPersistenceSupportEnabled,
164 | );
165 | if (!isPersistenceSupportEnabled) {
166 | await _clearPersistenceCart();
167 | }
168 | } catch (_) {
169 | rethrow;
170 | }
171 | }
172 |
173 | void _updatePersistenceCart(List cartItemsList) {
174 | var cartList = cartItemsList.map((e) => json.encode(e.toJson())).toList();
175 | unawaited(_sharedPreference.setStringList(
176 | SharedPreferenceConstants.persistCart, cartList));
177 | }
178 |
179 | List? _getPersistenceCartItems() {
180 | var items =
181 | _sharedPreference.getStringList(SharedPreferenceConstants.persistCart);
182 | if (items != null && items.isNotEmpty) {
183 | return items.map((e) => CartModel.fromJson(json.decode(e))).toList();
184 | }
185 | return null;
186 | }
187 |
188 | Future _clearPersistenceCart() async {
189 | var isRemoved =
190 | await _sharedPreference.remove(SharedPreferenceConstants.persistCart);
191 | return isRemoved;
192 | }
193 |
194 | /// Compares two lists of ProductVariant objects for equality.
195 | bool _areVariantsEqual(
196 | List variants1, List variants2) {
197 | if (variants1.length != variants2.length) {
198 | return false;
199 | }
200 |
201 | for (int i = 0; i < variants1.length; i++) {
202 | if (variants1[i].size != variants2[i].size ||
203 | variants1[i].price != variants2[i].price) {
204 | return false;
205 | }
206 | }
207 |
208 | return true;
209 | }
210 |
211 | /// This method is called when we have to get the [Total amount]
212 | double get subtotal {
213 | return _cartItemsList.fold(0, (sum, item) {
214 | return sum +
215 | item.variants.fold(
216 | 0,
217 | (variantSum, variant) =>
218 | variantSum + (variant.price * item.quantity),
219 | );
220 | });
221 | }
222 |
223 | double get total {
224 | return subtotal - discount;
225 | }
226 |
227 | double get discount {
228 | return _cartItemsList.fold(
229 | 0, (sum, item) => sum + (item.discount * item.quantity));
230 | }
231 |
232 | int get cartLength {
233 | return _cartItemsList.length;
234 | }
235 |
236 | List get cartItemsList {
237 | return _cartItemsList;
238 | }
239 |
240 | List? get persistenceCartItemsList {
241 | return _getPersistenceCartItems();
242 | }
243 | }
244 |
--------------------------------------------------------------------------------
/example/windows/runner/win32_window.cpp:
--------------------------------------------------------------------------------
1 | #include "win32_window.h"
2 |
3 | #include
4 | #include
5 |
6 | #include "resource.h"
7 |
8 | namespace {
9 |
10 | /// Window attribute that enables dark mode window decorations.
11 | ///
12 | /// Redefined in case the developer's machine has a Windows SDK older than
13 | /// version 10.0.22000.0.
14 | /// See: https://docs.microsoft.com/windows/win32/api/dwmapi/ne-dwmapi-dwmwindowattribute
15 | #ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
16 | #define DWMWA_USE_IMMERSIVE_DARK_MODE 20
17 | #endif
18 |
19 | constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW";
20 |
21 | /// Registry key for app theme preference.
22 | ///
23 | /// A value of 0 indicates apps should use dark mode. A non-zero or missing
24 | /// value indicates apps should use light mode.
25 | constexpr const wchar_t kGetPreferredBrightnessRegKey[] =
26 | L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
27 | constexpr const wchar_t kGetPreferredBrightnessRegValue[] = L"AppsUseLightTheme";
28 |
29 | // The number of Win32Window objects that currently exist.
30 | static int g_active_window_count = 0;
31 |
32 | using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd);
33 |
34 | // Scale helper to convert logical scaler values to physical using passed in
35 | // scale factor
36 | int Scale(int source, double scale_factor) {
37 | return static_cast(source * scale_factor);
38 | }
39 |
40 | // Dynamically loads the |EnableNonClientDpiScaling| from the User32 module.
41 | // This API is only needed for PerMonitor V1 awareness mode.
42 | void EnableFullDpiSupportIfAvailable(HWND hwnd) {
43 | HMODULE user32_module = LoadLibraryA("User32.dll");
44 | if (!user32_module) {
45 | return;
46 | }
47 | auto enable_non_client_dpi_scaling =
48 | reinterpret_cast(
49 | GetProcAddress(user32_module, "EnableNonClientDpiScaling"));
50 | if (enable_non_client_dpi_scaling != nullptr) {
51 | enable_non_client_dpi_scaling(hwnd);
52 | }
53 | FreeLibrary(user32_module);
54 | }
55 |
56 | } // namespace
57 |
58 | // Manages the Win32Window's window class registration.
59 | class WindowClassRegistrar {
60 | public:
61 | ~WindowClassRegistrar() = default;
62 |
63 | // Returns the singleton registrar instance.
64 | static WindowClassRegistrar* GetInstance() {
65 | if (!instance_) {
66 | instance_ = new WindowClassRegistrar();
67 | }
68 | return instance_;
69 | }
70 |
71 | // Returns the name of the window class, registering the class if it hasn't
72 | // previously been registered.
73 | const wchar_t* GetWindowClass();
74 |
75 | // Unregisters the window class. Should only be called if there are no
76 | // instances of the window.
77 | void UnregisterWindowClass();
78 |
79 | private:
80 | WindowClassRegistrar() = default;
81 |
82 | static WindowClassRegistrar* instance_;
83 |
84 | bool class_registered_ = false;
85 | };
86 |
87 | WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr;
88 |
89 | const wchar_t* WindowClassRegistrar::GetWindowClass() {
90 | if (!class_registered_) {
91 | WNDCLASS window_class{};
92 | window_class.hCursor = LoadCursor(nullptr, IDC_ARROW);
93 | window_class.lpszClassName = kWindowClassName;
94 | window_class.style = CS_HREDRAW | CS_VREDRAW;
95 | window_class.cbClsExtra = 0;
96 | window_class.cbWndExtra = 0;
97 | window_class.hInstance = GetModuleHandle(nullptr);
98 | window_class.hIcon =
99 | LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON));
100 | window_class.hbrBackground = 0;
101 | window_class.lpszMenuName = nullptr;
102 | window_class.lpfnWndProc = Win32Window::WndProc;
103 | RegisterClass(&window_class);
104 | class_registered_ = true;
105 | }
106 | return kWindowClassName;
107 | }
108 |
109 | void WindowClassRegistrar::UnregisterWindowClass() {
110 | UnregisterClass(kWindowClassName, nullptr);
111 | class_registered_ = false;
112 | }
113 |
114 | Win32Window::Win32Window() {
115 | ++g_active_window_count;
116 | }
117 |
118 | Win32Window::~Win32Window() {
119 | --g_active_window_count;
120 | Destroy();
121 | }
122 |
123 | bool Win32Window::Create(const std::wstring& title,
124 | const Point& origin,
125 | const Size& size) {
126 | Destroy();
127 |
128 | const wchar_t* window_class =
129 | WindowClassRegistrar::GetInstance()->GetWindowClass();
130 |
131 | const POINT target_point = {static_cast(origin.x),
132 | static_cast(origin.y)};
133 | HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST);
134 | UINT dpi = FlutterDesktopGetDpiForMonitor(monitor);
135 | double scale_factor = dpi / 96.0;
136 |
137 | HWND window = CreateWindow(
138 | window_class, title.c_str(), WS_OVERLAPPEDWINDOW,
139 | Scale(origin.x, scale_factor), Scale(origin.y, scale_factor),
140 | Scale(size.width, scale_factor), Scale(size.height, scale_factor),
141 | nullptr, nullptr, GetModuleHandle(nullptr), this);
142 |
143 | if (!window) {
144 | return false;
145 | }
146 |
147 | UpdateTheme(window);
148 |
149 | return OnCreate();
150 | }
151 |
152 | bool Win32Window::Show() {
153 | return ShowWindow(window_handle_, SW_SHOWNORMAL);
154 | }
155 |
156 | // static
157 | LRESULT CALLBACK Win32Window::WndProc(HWND const window,
158 | UINT const message,
159 | WPARAM const wparam,
160 | LPARAM const lparam) noexcept {
161 | if (message == WM_NCCREATE) {
162 | auto window_struct = reinterpret_cast(lparam);
163 | SetWindowLongPtr(window, GWLP_USERDATA,
164 | reinterpret_cast(window_struct->lpCreateParams));
165 |
166 | auto that = static_cast(window_struct->lpCreateParams);
167 | EnableFullDpiSupportIfAvailable(window);
168 | that->window_handle_ = window;
169 | } else if (Win32Window* that = GetThisFromHandle(window)) {
170 | return that->MessageHandler(window, message, wparam, lparam);
171 | }
172 |
173 | return DefWindowProc(window, message, wparam, lparam);
174 | }
175 |
176 | LRESULT
177 | Win32Window::MessageHandler(HWND hwnd,
178 | UINT const message,
179 | WPARAM const wparam,
180 | LPARAM const lparam) noexcept {
181 | switch (message) {
182 | case WM_DESTROY:
183 | window_handle_ = nullptr;
184 | Destroy();
185 | if (quit_on_close_) {
186 | PostQuitMessage(0);
187 | }
188 | return 0;
189 |
190 | case WM_DPICHANGED: {
191 | auto newRectSize = reinterpret_cast(lparam);
192 | LONG newWidth = newRectSize->right - newRectSize->left;
193 | LONG newHeight = newRectSize->bottom - newRectSize->top;
194 |
195 | SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth,
196 | newHeight, SWP_NOZORDER | SWP_NOACTIVATE);
197 |
198 | return 0;
199 | }
200 | case WM_SIZE: {
201 | RECT rect = GetClientArea();
202 | if (child_content_ != nullptr) {
203 | // Size and position the child window.
204 | MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left,
205 | rect.bottom - rect.top, TRUE);
206 | }
207 | return 0;
208 | }
209 |
210 | case WM_ACTIVATE:
211 | if (child_content_ != nullptr) {
212 | SetFocus(child_content_);
213 | }
214 | return 0;
215 |
216 | case WM_DWMCOLORIZATIONCOLORCHANGED:
217 | UpdateTheme(hwnd);
218 | return 0;
219 | }
220 |
221 | return DefWindowProc(window_handle_, message, wparam, lparam);
222 | }
223 |
224 | void Win32Window::Destroy() {
225 | OnDestroy();
226 |
227 | if (window_handle_) {
228 | DestroyWindow(window_handle_);
229 | window_handle_ = nullptr;
230 | }
231 | if (g_active_window_count == 0) {
232 | WindowClassRegistrar::GetInstance()->UnregisterWindowClass();
233 | }
234 | }
235 |
236 | Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept {
237 | return reinterpret_cast(
238 | GetWindowLongPtr(window, GWLP_USERDATA));
239 | }
240 |
241 | void Win32Window::SetChildContent(HWND content) {
242 | child_content_ = content;
243 | SetParent(content, window_handle_);
244 | RECT frame = GetClientArea();
245 |
246 | MoveWindow(content, frame.left, frame.top, frame.right - frame.left,
247 | frame.bottom - frame.top, true);
248 |
249 | SetFocus(child_content_);
250 | }
251 |
252 | RECT Win32Window::GetClientArea() {
253 | RECT frame;
254 | GetClientRect(window_handle_, &frame);
255 | return frame;
256 | }
257 |
258 | HWND Win32Window::GetHandle() {
259 | return window_handle_;
260 | }
261 |
262 | void Win32Window::SetQuitOnClose(bool quit_on_close) {
263 | quit_on_close_ = quit_on_close;
264 | }
265 |
266 | bool Win32Window::OnCreate() {
267 | // No-op; provided for subclasses.
268 | return true;
269 | }
270 |
271 | void Win32Window::OnDestroy() {
272 | // No-op; provided for subclasses.
273 | }
274 |
275 | void Win32Window::UpdateTheme(HWND const window) {
276 | DWORD light_mode;
277 | DWORD light_mode_size = sizeof(light_mode);
278 | LSTATUS result = RegGetValue(HKEY_CURRENT_USER, kGetPreferredBrightnessRegKey,
279 | kGetPreferredBrightnessRegValue,
280 | RRF_RT_REG_DWORD, nullptr, &light_mode,
281 | &light_mode_size);
282 |
283 | if (result == ERROR_SUCCESS) {
284 | BOOL enable_dark_mode = light_mode == 0;
285 | DwmSetWindowAttribute(window, DWMWA_USE_IMMERSIVE_DARK_MODE,
286 | &enable_dark_mode, sizeof(enable_dark_mode));
287 | }
288 | }
289 |
--------------------------------------------------------------------------------
/example/lib/models/products_model.freezed.dart:
--------------------------------------------------------------------------------
1 | // coverage:ignore-file
2 | // GENERATED CODE - DO NOT MODIFY BY HAND
3 | // ignore_for_file: type=lint
4 | // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
5 |
6 | part of 'products_model.dart';
7 |
8 | // **************************************************************************
9 | // FreezedGenerator
10 | // **************************************************************************
11 |
12 | T _$identity(T value) => value;
13 |
14 | final _privateConstructorUsedError = UnsupportedError(
15 | 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
16 |
17 | ProductModel _$ProductModelFromJson(Map json) {
18 | return _ProductModel.fromJson(json);
19 | }
20 |
21 | /// @nodoc
22 | mixin _$ProductModel {
23 | List get products => throw _privateConstructorUsedError;
24 |
25 | Map toJson() => throw _privateConstructorUsedError;
26 | @JsonKey(ignore: true)
27 | $ProductModelCopyWith get copyWith =>
28 | throw _privateConstructorUsedError;
29 | }
30 |
31 | /// @nodoc
32 | abstract class $ProductModelCopyWith<$Res> {
33 | factory $ProductModelCopyWith(
34 | ProductModel value, $Res Function(ProductModel) then) =
35 | _$ProductModelCopyWithImpl<$Res, ProductModel>;
36 | @useResult
37 | $Res call({List products});
38 | }
39 |
40 | /// @nodoc
41 | class _$ProductModelCopyWithImpl<$Res, $Val extends ProductModel>
42 | implements $ProductModelCopyWith<$Res> {
43 | _$ProductModelCopyWithImpl(this._value, this._then);
44 |
45 | // ignore: unused_field
46 | final $Val _value;
47 | // ignore: unused_field
48 | final $Res Function($Val) _then;
49 |
50 | @pragma('vm:prefer-inline')
51 | @override
52 | $Res call({
53 | Object? products = null,
54 | }) {
55 | return _then(_value.copyWith(
56 | products: null == products
57 | ? _value.products
58 | : products // ignore: cast_nullable_to_non_nullable
59 | as List,
60 | ) as $Val);
61 | }
62 | }
63 |
64 | /// @nodoc
65 | abstract class _$$ProductModelImplCopyWith<$Res>
66 | implements $ProductModelCopyWith<$Res> {
67 | factory _$$ProductModelImplCopyWith(
68 | _$ProductModelImpl value, $Res Function(_$ProductModelImpl) then) =
69 | __$$ProductModelImplCopyWithImpl<$Res>;
70 | @override
71 | @useResult
72 | $Res call({List products});
73 | }
74 |
75 | /// @nodoc
76 | class __$$ProductModelImplCopyWithImpl<$Res>
77 | extends _$ProductModelCopyWithImpl<$Res, _$ProductModelImpl>
78 | implements _$$ProductModelImplCopyWith<$Res> {
79 | __$$ProductModelImplCopyWithImpl(
80 | _$ProductModelImpl _value, $Res Function(_$ProductModelImpl) _then)
81 | : super(_value, _then);
82 |
83 | @pragma('vm:prefer-inline')
84 | @override
85 | $Res call({
86 | Object? products = null,
87 | }) {
88 | return _then(_$ProductModelImpl(
89 | products: null == products
90 | ? _value._products
91 | : products // ignore: cast_nullable_to_non_nullable
92 | as List,
93 | ));
94 | }
95 | }
96 |
97 | /// @nodoc
98 | @JsonSerializable()
99 | class _$ProductModelImpl implements _ProductModel {
100 | const _$ProductModelImpl({required final List products})
101 | : _products = products;
102 |
103 | factory _$ProductModelImpl.fromJson(Map json) =>
104 | _$$ProductModelImplFromJson(json);
105 |
106 | final List _products;
107 | @override
108 | List get products {
109 | if (_products is EqualUnmodifiableListView) return _products;
110 | // ignore: implicit_dynamic_type
111 | return EqualUnmodifiableListView(_products);
112 | }
113 |
114 | @override
115 | String toString() {
116 | return 'ProductModel(products: $products)';
117 | }
118 |
119 | @override
120 | bool operator ==(Object other) {
121 | return identical(this, other) ||
122 | (other.runtimeType == runtimeType &&
123 | other is _$ProductModelImpl &&
124 | const DeepCollectionEquality().equals(other._products, _products));
125 | }
126 |
127 | @JsonKey(ignore: true)
128 | @override
129 | int get hashCode =>
130 | Object.hash(runtimeType, const DeepCollectionEquality().hash(_products));
131 |
132 | @JsonKey(ignore: true)
133 | @override
134 | @pragma('vm:prefer-inline')
135 | _$$ProductModelImplCopyWith<_$ProductModelImpl> get copyWith =>
136 | __$$ProductModelImplCopyWithImpl<_$ProductModelImpl>(this, _$identity);
137 |
138 | @override
139 | Map toJson() {
140 | return _$$ProductModelImplToJson(
141 | this,
142 | );
143 | }
144 | }
145 |
146 | abstract class _ProductModel implements ProductModel {
147 | const factory _ProductModel(
148 | {required final List products}) = _$ProductModelImpl;
149 |
150 | factory _ProductModel.fromJson(Map json) =
151 | _$ProductModelImpl.fromJson;
152 |
153 | @override
154 | List get products;
155 | @override
156 | @JsonKey(ignore: true)
157 | _$$ProductModelImplCopyWith<_$ProductModelImpl> get copyWith =>
158 | throw _privateConstructorUsedError;
159 | }
160 |
161 | ProductItemsModel _$ProductItemsModelFromJson(Map json) {
162 | return _ProductItemsModel.fromJson(json);
163 | }
164 |
165 | /// @nodoc
166 | mixin _$ProductItemsModel {
167 | int get id => throw _privateConstructorUsedError;
168 | String get title => throw _privateConstructorUsedError;
169 | String get description => throw _privateConstructorUsedError;
170 | String get category => throw _privateConstructorUsedError;
171 | double get price => throw _privateConstructorUsedError;
172 | double get discountPercentage => throw _privateConstructorUsedError;
173 | double get rating => throw _privateConstructorUsedError;
174 | int get stock => throw _privateConstructorUsedError;
175 | String get brand => throw _privateConstructorUsedError;
176 | String? get thumbnail => throw _privateConstructorUsedError;
177 | List? get images => throw _privateConstructorUsedError;
178 |
179 | Map toJson() => throw _privateConstructorUsedError;
180 | @JsonKey(ignore: true)
181 | $ProductItemsModelCopyWith get copyWith =>
182 | throw _privateConstructorUsedError;
183 | }
184 |
185 | /// @nodoc
186 | abstract class $ProductItemsModelCopyWith<$Res> {
187 | factory $ProductItemsModelCopyWith(
188 | ProductItemsModel value, $Res Function(ProductItemsModel) then) =
189 | _$ProductItemsModelCopyWithImpl<$Res, ProductItemsModel>;
190 | @useResult
191 | $Res call(
192 | {int id,
193 | String title,
194 | String description,
195 | String category,
196 | double price,
197 | double discountPercentage,
198 | double rating,
199 | int stock,
200 | String brand,
201 | String? thumbnail,
202 | List? images});
203 | }
204 |
205 | /// @nodoc
206 | class _$ProductItemsModelCopyWithImpl<$Res, $Val extends ProductItemsModel>
207 | implements $ProductItemsModelCopyWith<$Res> {
208 | _$ProductItemsModelCopyWithImpl(this._value, this._then);
209 |
210 | // ignore: unused_field
211 | final $Val _value;
212 | // ignore: unused_field
213 | final $Res Function($Val) _then;
214 |
215 | @pragma('vm:prefer-inline')
216 | @override
217 | $Res call({
218 | Object? id = null,
219 | Object? title = null,
220 | Object? description = null,
221 | Object? category = null,
222 | Object? price = null,
223 | Object? discountPercentage = null,
224 | Object? rating = null,
225 | Object? stock = null,
226 | Object? brand = null,
227 | Object? thumbnail = freezed,
228 | Object? images = freezed,
229 | }) {
230 | return _then(_value.copyWith(
231 | id: null == id
232 | ? _value.id
233 | : id // ignore: cast_nullable_to_non_nullable
234 | as int,
235 | title: null == title
236 | ? _value.title
237 | : title // ignore: cast_nullable_to_non_nullable
238 | as String,
239 | description: null == description
240 | ? _value.description
241 | : description // ignore: cast_nullable_to_non_nullable
242 | as String,
243 | category: null == category
244 | ? _value.category
245 | : category // ignore: cast_nullable_to_non_nullable
246 | as String,
247 | price: null == price
248 | ? _value.price
249 | : price // ignore: cast_nullable_to_non_nullable
250 | as double,
251 | discountPercentage: null == discountPercentage
252 | ? _value.discountPercentage
253 | : discountPercentage // ignore: cast_nullable_to_non_nullable
254 | as double,
255 | rating: null == rating
256 | ? _value.rating
257 | : rating // ignore: cast_nullable_to_non_nullable
258 | as double,
259 | stock: null == stock
260 | ? _value.stock
261 | : stock // ignore: cast_nullable_to_non_nullable
262 | as int,
263 | brand: null == brand
264 | ? _value.brand
265 | : brand // ignore: cast_nullable_to_non_nullable
266 | as String,
267 | thumbnail: freezed == thumbnail
268 | ? _value.thumbnail
269 | : thumbnail // ignore: cast_nullable_to_non_nullable
270 | as String?,
271 | images: freezed == images
272 | ? _value.images
273 | : images // ignore: cast_nullable_to_non_nullable
274 | as List?,
275 | ) as $Val);
276 | }
277 | }
278 |
279 | /// @nodoc
280 | abstract class _$$ProductItemsModelImplCopyWith<$Res>
281 | implements $ProductItemsModelCopyWith<$Res> {
282 | factory _$$ProductItemsModelImplCopyWith(_$ProductItemsModelImpl value,
283 | $Res Function(_$ProductItemsModelImpl) then) =
284 | __$$ProductItemsModelImplCopyWithImpl<$Res>;
285 | @override
286 | @useResult
287 | $Res call(
288 | {int id,
289 | String title,
290 | String description,
291 | String category,
292 | double price,
293 | double discountPercentage,
294 | double rating,
295 | int stock,
296 | String brand,
297 | String? thumbnail,
298 | List? images});
299 | }
300 |
301 | /// @nodoc
302 | class __$$ProductItemsModelImplCopyWithImpl<$Res>
303 | extends _$ProductItemsModelCopyWithImpl<$Res, _$ProductItemsModelImpl>
304 | implements _$$ProductItemsModelImplCopyWith<$Res> {
305 | __$$ProductItemsModelImplCopyWithImpl(_$ProductItemsModelImpl _value,
306 | $Res Function(_$ProductItemsModelImpl) _then)
307 | : super(_value, _then);
308 |
309 | @pragma('vm:prefer-inline')
310 | @override
311 | $Res call({
312 | Object? id = null,
313 | Object? title = null,
314 | Object? description = null,
315 | Object? category = null,
316 | Object? price = null,
317 | Object? discountPercentage = null,
318 | Object? rating = null,
319 | Object? stock = null,
320 | Object? brand = null,
321 | Object? thumbnail = freezed,
322 | Object? images = freezed,
323 | }) {
324 | return _then(_$ProductItemsModelImpl(
325 | id: null == id
326 | ? _value.id
327 | : id // ignore: cast_nullable_to_non_nullable
328 | as int,
329 | title: null == title
330 | ? _value.title
331 | : title // ignore: cast_nullable_to_non_nullable
332 | as String,
333 | description: null == description
334 | ? _value.description
335 | : description // ignore: cast_nullable_to_non_nullable
336 | as String,
337 | category: null == category
338 | ? _value.category
339 | : category // ignore: cast_nullable_to_non_nullable
340 | as String,
341 | price: null == price
342 | ? _value.price
343 | : price // ignore: cast_nullable_to_non_nullable
344 | as double,
345 | discountPercentage: null == discountPercentage
346 | ? _value.discountPercentage
347 | : discountPercentage // ignore: cast_nullable_to_non_nullable
348 | as double,
349 | rating: null == rating
350 | ? _value.rating
351 | : rating // ignore: cast_nullable_to_non_nullable
352 | as double,
353 | stock: null == stock
354 | ? _value.stock
355 | : stock // ignore: cast_nullable_to_non_nullable
356 | as int,
357 | brand: null == brand
358 | ? _value.brand
359 | : brand // ignore: cast_nullable_to_non_nullable
360 | as String,
361 | thumbnail: freezed == thumbnail
362 | ? _value.thumbnail
363 | : thumbnail // ignore: cast_nullable_to_non_nullable
364 | as String?,
365 | images: freezed == images
366 | ? _value._images
367 | : images // ignore: cast_nullable_to_non_nullable
368 | as List?,
369 | ));
370 | }
371 | }
372 |
373 | /// @nodoc
374 | @JsonSerializable()
375 | class _$ProductItemsModelImpl implements _ProductItemsModel {
376 | const _$ProductItemsModelImpl(
377 | {required this.id,
378 | required this.title,
379 | required this.description,
380 | required this.category,
381 | required this.price,
382 | required this.discountPercentage,
383 | required this.rating,
384 | required this.stock,
385 | required this.brand,
386 | this.thumbnail,
387 | final List? images})
388 | : _images = images;
389 |
390 | factory _$ProductItemsModelImpl.fromJson(Map json) =>
391 | _$$ProductItemsModelImplFromJson(json);
392 |
393 | @override
394 | final int id;
395 | @override
396 | final String title;
397 | @override
398 | final String description;
399 | @override
400 | final String category;
401 | @override
402 | final double price;
403 | @override
404 | final double discountPercentage;
405 | @override
406 | final double rating;
407 | @override
408 | final int stock;
409 | @override
410 | final String brand;
411 | @override
412 | final String? thumbnail;
413 | final List? _images;
414 | @override
415 | List? get images {
416 | final value = _images;
417 | if (value == null) return null;
418 | if (_images is EqualUnmodifiableListView) return _images;
419 | // ignore: implicit_dynamic_type
420 | return EqualUnmodifiableListView(value);
421 | }
422 |
423 | @override
424 | String toString() {
425 | return 'ProductItemsModel(id: $id, title: $title, description: $description, category: $category, price: $price, discountPercentage: $discountPercentage, rating: $rating, stock: $stock, brand: $brand, thumbnail: $thumbnail, images: $images)';
426 | }
427 |
428 | @override
429 | bool operator ==(Object other) {
430 | return identical(this, other) ||
431 | (other.runtimeType == runtimeType &&
432 | other is _$ProductItemsModelImpl &&
433 | (identical(other.id, id) || other.id == id) &&
434 | (identical(other.title, title) || other.title == title) &&
435 | (identical(other.description, description) ||
436 | other.description == description) &&
437 | (identical(other.category, category) ||
438 | other.category == category) &&
439 | (identical(other.price, price) || other.price == price) &&
440 | (identical(other.discountPercentage, discountPercentage) ||
441 | other.discountPercentage == discountPercentage) &&
442 | (identical(other.rating, rating) || other.rating == rating) &&
443 | (identical(other.stock, stock) || other.stock == stock) &&
444 | (identical(other.brand, brand) || other.brand == brand) &&
445 | (identical(other.thumbnail, thumbnail) ||
446 | other.thumbnail == thumbnail) &&
447 | const DeepCollectionEquality().equals(other._images, _images));
448 | }
449 |
450 | @JsonKey(ignore: true)
451 | @override
452 | int get hashCode => Object.hash(
453 | runtimeType,
454 | id,
455 | title,
456 | description,
457 | category,
458 | price,
459 | discountPercentage,
460 | rating,
461 | stock,
462 | brand,
463 | thumbnail,
464 | const DeepCollectionEquality().hash(_images));
465 |
466 | @JsonKey(ignore: true)
467 | @override
468 | @pragma('vm:prefer-inline')
469 | _$$ProductItemsModelImplCopyWith<_$ProductItemsModelImpl> get copyWith =>
470 | __$$ProductItemsModelImplCopyWithImpl<_$ProductItemsModelImpl>(
471 | this, _$identity);
472 |
473 | @override
474 | Map toJson() {
475 | return _$$ProductItemsModelImplToJson(
476 | this,
477 | );
478 | }
479 | }
480 |
481 | abstract class _ProductItemsModel implements ProductItemsModel {
482 | const factory _ProductItemsModel(
483 | {required final int id,
484 | required final String title,
485 | required final String description,
486 | required final String category,
487 | required final double price,
488 | required final double discountPercentage,
489 | required final double rating,
490 | required final int stock,
491 | required final String brand,
492 | final String? thumbnail,
493 | final List? images}) = _$ProductItemsModelImpl;
494 |
495 | factory _ProductItemsModel.fromJson(Map json) =
496 | _$ProductItemsModelImpl.fromJson;
497 |
498 | @override
499 | int get id;
500 | @override
501 | String get title;
502 | @override
503 | String get description;
504 | @override
505 | String get category;
506 | @override
507 | double get price;
508 | @override
509 | double get discountPercentage;
510 | @override
511 | double get rating;
512 | @override
513 | int get stock;
514 | @override
515 | String get brand;
516 | @override
517 | String? get thumbnail;
518 | @override
519 | List? get images;
520 | @override
521 | @JsonKey(ignore: true)
522 | _$$ProductItemsModelImplCopyWith<_$ProductItemsModelImpl> get copyWith =>
523 | throw _privateConstructorUsedError;
524 | }
525 |
--------------------------------------------------------------------------------
/lib/model/cart_model.freezed.dart:
--------------------------------------------------------------------------------
1 | // coverage:ignore-file
2 | // GENERATED CODE - DO NOT MODIFY BY HAND
3 | // ignore_for_file: type=lint
4 | // ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
5 |
6 | part of 'cart_model.dart';
7 |
8 | // **************************************************************************
9 | // FreezedGenerator
10 | // **************************************************************************
11 |
12 | T _$identity(T value) => value;
13 |
14 | final _privateConstructorUsedError = UnsupportedError(
15 | 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
16 |
17 | CartModel _$CartModelFromJson(Map json) {
18 | return _CartModel.fromJson(json);
19 | }
20 |
21 | /// @nodoc
22 | mixin _$CartModel {
23 | String get productId => throw _privateConstructorUsedError;
24 | String get productName => throw _privateConstructorUsedError;
25 | List? get productImages => throw _privateConstructorUsedError;
26 | List get variants => throw _privateConstructorUsedError;
27 | int get quantity => throw _privateConstructorUsedError;
28 | double get discount => throw _privateConstructorUsedError;
29 | String get productDetails => throw _privateConstructorUsedError;
30 | Map? get productMeta => throw _privateConstructorUsedError;
31 |
32 | Map toJson() => throw _privateConstructorUsedError;
33 | @JsonKey(ignore: true)
34 | $CartModelCopyWith get copyWith =>
35 | throw _privateConstructorUsedError;
36 | }
37 |
38 | /// @nodoc
39 | abstract class $CartModelCopyWith<$Res> {
40 | factory $CartModelCopyWith(CartModel value, $Res Function(CartModel) then) =
41 | _$CartModelCopyWithImpl<$Res, CartModel>;
42 | @useResult
43 | $Res call(
44 | {String productId,
45 | String productName,
46 | List? productImages,
47 | List variants,
48 | int quantity,
49 | double discount,
50 | String productDetails,
51 | Map? productMeta});
52 | }
53 |
54 | /// @nodoc
55 | class _$CartModelCopyWithImpl<$Res, $Val extends CartModel>
56 | implements $CartModelCopyWith<$Res> {
57 | _$CartModelCopyWithImpl(this._value, this._then);
58 |
59 | // ignore: unused_field
60 | final $Val _value;
61 | // ignore: unused_field
62 | final $Res Function($Val) _then;
63 |
64 | @pragma('vm:prefer-inline')
65 | @override
66 | $Res call({
67 | Object? productId = null,
68 | Object? productName = null,
69 | Object? productImages = freezed,
70 | Object? variants = null,
71 | Object? quantity = null,
72 | Object? discount = null,
73 | Object? productDetails = null,
74 | Object? productMeta = freezed,
75 | }) {
76 | return _then(_value.copyWith(
77 | productId: null == productId
78 | ? _value.productId
79 | : productId // ignore: cast_nullable_to_non_nullable
80 | as String,
81 | productName: null == productName
82 | ? _value.productName
83 | : productName // ignore: cast_nullable_to_non_nullable
84 | as String,
85 | productImages: freezed == productImages
86 | ? _value.productImages
87 | : productImages // ignore: cast_nullable_to_non_nullable
88 | as List?,
89 | variants: null == variants
90 | ? _value.variants
91 | : variants // ignore: cast_nullable_to_non_nullable
92 | as List,
93 | quantity: null == quantity
94 | ? _value.quantity
95 | : quantity // ignore: cast_nullable_to_non_nullable
96 | as int,
97 | discount: null == discount
98 | ? _value.discount
99 | : discount // ignore: cast_nullable_to_non_nullable
100 | as double,
101 | productDetails: null == productDetails
102 | ? _value.productDetails
103 | : productDetails // ignore: cast_nullable_to_non_nullable
104 | as String,
105 | productMeta: freezed == productMeta
106 | ? _value.productMeta
107 | : productMeta // ignore: cast_nullable_to_non_nullable
108 | as Map?,
109 | ) as $Val);
110 | }
111 | }
112 |
113 | /// @nodoc
114 | abstract class _$$CartModelImplCopyWith<$Res>
115 | implements $CartModelCopyWith<$Res> {
116 | factory _$$CartModelImplCopyWith(
117 | _$CartModelImpl value, $Res Function(_$CartModelImpl) then) =
118 | __$$CartModelImplCopyWithImpl<$Res>;
119 | @override
120 | @useResult
121 | $Res call(
122 | {String productId,
123 | String productName,
124 | List? productImages,
125 | List variants,
126 | int quantity,
127 | double discount,
128 | String productDetails,
129 | Map? productMeta});
130 | }
131 |
132 | /// @nodoc
133 | class __$$CartModelImplCopyWithImpl<$Res>
134 | extends _$CartModelCopyWithImpl<$Res, _$CartModelImpl>
135 | implements _$$CartModelImplCopyWith<$Res> {
136 | __$$CartModelImplCopyWithImpl(
137 | _$CartModelImpl _value, $Res Function(_$CartModelImpl) _then)
138 | : super(_value, _then);
139 |
140 | @pragma('vm:prefer-inline')
141 | @override
142 | $Res call({
143 | Object? productId = null,
144 | Object? productName = null,
145 | Object? productImages = freezed,
146 | Object? variants = null,
147 | Object? quantity = null,
148 | Object? discount = null,
149 | Object? productDetails = null,
150 | Object? productMeta = freezed,
151 | }) {
152 | return _then(_$CartModelImpl(
153 | productId: null == productId
154 | ? _value.productId
155 | : productId // ignore: cast_nullable_to_non_nullable
156 | as String,
157 | productName: null == productName
158 | ? _value.productName
159 | : productName // ignore: cast_nullable_to_non_nullable
160 | as String,
161 | productImages: freezed == productImages
162 | ? _value._productImages
163 | : productImages // ignore: cast_nullable_to_non_nullable
164 | as List?,
165 | variants: null == variants
166 | ? _value._variants
167 | : variants // ignore: cast_nullable_to_non_nullable
168 | as List,
169 | quantity: null == quantity
170 | ? _value.quantity
171 | : quantity // ignore: cast_nullable_to_non_nullable
172 | as int,
173 | discount: null == discount
174 | ? _value.discount
175 | : discount // ignore: cast_nullable_to_non_nullable
176 | as double,
177 | productDetails: null == productDetails
178 | ? _value.productDetails
179 | : productDetails // ignore: cast_nullable_to_non_nullable
180 | as String,
181 | productMeta: freezed == productMeta
182 | ? _value._productMeta
183 | : productMeta // ignore: cast_nullable_to_non_nullable
184 | as Map?,
185 | ));
186 | }
187 | }
188 |
189 | /// @nodoc
190 | @JsonSerializable()
191 | class _$CartModelImpl with DiagnosticableTreeMixin implements _CartModel {
192 | const _$CartModelImpl(
193 | {required this.productId,
194 | required this.productName,
195 | final List? productImages,
196 | required final List variants,
197 | this.quantity = 1,
198 | this.discount = 0.0,
199 | required this.productDetails,
200 | final Map? productMeta})
201 | : _productImages = productImages,
202 | _variants = variants,
203 | _productMeta = productMeta;
204 |
205 | factory _$CartModelImpl.fromJson(Map json) =>
206 | _$$CartModelImplFromJson(json);
207 |
208 | @override
209 | final String productId;
210 | @override
211 | final String productName;
212 | final List? _productImages;
213 | @override
214 | List? get productImages {
215 | final value = _productImages;
216 | if (value == null) return null;
217 | if (_productImages is EqualUnmodifiableListView) return _productImages;
218 | // ignore: implicit_dynamic_type
219 | return EqualUnmodifiableListView(value);
220 | }
221 |
222 | final List _variants;
223 | @override
224 | List get variants {
225 | if (_variants is EqualUnmodifiableListView) return _variants;
226 | // ignore: implicit_dynamic_type
227 | return EqualUnmodifiableListView(_variants);
228 | }
229 |
230 | @override
231 | @JsonKey()
232 | final int quantity;
233 | @override
234 | @JsonKey()
235 | final double discount;
236 | @override
237 | final String productDetails;
238 | final Map? _productMeta;
239 | @override
240 | Map? get productMeta {
241 | final value = _productMeta;
242 | if (value == null) return null;
243 | if (_productMeta is EqualUnmodifiableMapView) return _productMeta;
244 | // ignore: implicit_dynamic_type
245 | return EqualUnmodifiableMapView(value);
246 | }
247 |
248 | @override
249 | String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
250 | return 'CartModel(productId: $productId, productName: $productName, productImages: $productImages, variants: $variants, quantity: $quantity, discount: $discount, productDetails: $productDetails, productMeta: $productMeta)';
251 | }
252 |
253 | @override
254 | void debugFillProperties(DiagnosticPropertiesBuilder properties) {
255 | super.debugFillProperties(properties);
256 | properties
257 | ..add(DiagnosticsProperty('type', 'CartModel'))
258 | ..add(DiagnosticsProperty('productId', productId))
259 | ..add(DiagnosticsProperty('productName', productName))
260 | ..add(DiagnosticsProperty('productImages', productImages))
261 | ..add(DiagnosticsProperty('variants', variants))
262 | ..add(DiagnosticsProperty('quantity', quantity))
263 | ..add(DiagnosticsProperty('discount', discount))
264 | ..add(DiagnosticsProperty('productDetails', productDetails))
265 | ..add(DiagnosticsProperty('productMeta', productMeta));
266 | }
267 |
268 | @override
269 | bool operator ==(Object other) {
270 | return identical(this, other) ||
271 | (other.runtimeType == runtimeType &&
272 | other is _$CartModelImpl &&
273 | (identical(other.productId, productId) ||
274 | other.productId == productId) &&
275 | (identical(other.productName, productName) ||
276 | other.productName == productName) &&
277 | const DeepCollectionEquality()
278 | .equals(other._productImages, _productImages) &&
279 | const DeepCollectionEquality().equals(other._variants, _variants) &&
280 | (identical(other.quantity, quantity) ||
281 | other.quantity == quantity) &&
282 | (identical(other.discount, discount) ||
283 | other.discount == discount) &&
284 | (identical(other.productDetails, productDetails) ||
285 | other.productDetails == productDetails) &&
286 | const DeepCollectionEquality()
287 | .equals(other._productMeta, _productMeta));
288 | }
289 |
290 | @JsonKey(ignore: true)
291 | @override
292 | int get hashCode => Object.hash(
293 | runtimeType,
294 | productId,
295 | productName,
296 | const DeepCollectionEquality().hash(_productImages),
297 | const DeepCollectionEquality().hash(_variants),
298 | quantity,
299 | discount,
300 | productDetails,
301 | const DeepCollectionEquality().hash(_productMeta));
302 |
303 | @JsonKey(ignore: true)
304 | @override
305 | @pragma('vm:prefer-inline')
306 | _$$CartModelImplCopyWith<_$CartModelImpl> get copyWith =>
307 | __$$CartModelImplCopyWithImpl<_$CartModelImpl>(this, _$identity);
308 |
309 | @override
310 | Map toJson() {
311 | return _$$CartModelImplToJson(
312 | this,
313 | );
314 | }
315 | }
316 |
317 | abstract class _CartModel implements CartModel {
318 | const factory _CartModel(
319 | {required final String productId,
320 | required final String productName,
321 | final List? productImages,
322 | required final List variants,
323 | final int quantity,
324 | final double discount,
325 | required final String productDetails,
326 | final Map? productMeta}) = _$CartModelImpl;
327 |
328 | factory _CartModel.fromJson(Map json) =
329 | _$CartModelImpl.fromJson;
330 |
331 | @override
332 | String get productId;
333 | @override
334 | String get productName;
335 | @override
336 | List? get productImages;
337 | @override
338 | List get variants;
339 | @override
340 | int get quantity;
341 | @override
342 | double get discount;
343 | @override
344 | String get productDetails;
345 | @override
346 | Map? get productMeta;
347 | @override
348 | @JsonKey(ignore: true)
349 | _$$CartModelImplCopyWith<_$CartModelImpl> get copyWith =>
350 | throw _privateConstructorUsedError;
351 | }
352 |
353 | ProductVariant _$ProductVariantFromJson(Map json) {
354 | return _ProductVariant.fromJson(json);
355 | }
356 |
357 | /// @nodoc
358 | mixin _$ProductVariant {
359 | String? get size => throw _privateConstructorUsedError;
360 | String? get color => throw _privateConstructorUsedError;
361 | double get price => throw _privateConstructorUsedError;
362 |
363 | Map toJson() => throw _privateConstructorUsedError;
364 | @JsonKey(ignore: true)
365 | $ProductVariantCopyWith get copyWith =>
366 | throw _privateConstructorUsedError;
367 | }
368 |
369 | /// @nodoc
370 | abstract class $ProductVariantCopyWith<$Res> {
371 | factory $ProductVariantCopyWith(
372 | ProductVariant value, $Res Function(ProductVariant) then) =
373 | _$ProductVariantCopyWithImpl<$Res, ProductVariant>;
374 | @useResult
375 | $Res call({String? size, String? color, double price});
376 | }
377 |
378 | /// @nodoc
379 | class _$ProductVariantCopyWithImpl<$Res, $Val extends ProductVariant>
380 | implements $ProductVariantCopyWith<$Res> {
381 | _$ProductVariantCopyWithImpl(this._value, this._then);
382 |
383 | // ignore: unused_field
384 | final $Val _value;
385 | // ignore: unused_field
386 | final $Res Function($Val) _then;
387 |
388 | @pragma('vm:prefer-inline')
389 | @override
390 | $Res call({
391 | Object? size = freezed,
392 | Object? color = freezed,
393 | Object? price = null,
394 | }) {
395 | return _then(_value.copyWith(
396 | size: freezed == size
397 | ? _value.size
398 | : size // ignore: cast_nullable_to_non_nullable
399 | as String?,
400 | color: freezed == color
401 | ? _value.color
402 | : color // ignore: cast_nullable_to_non_nullable
403 | as String?,
404 | price: null == price
405 | ? _value.price
406 | : price // ignore: cast_nullable_to_non_nullable
407 | as double,
408 | ) as $Val);
409 | }
410 | }
411 |
412 | /// @nodoc
413 | abstract class _$$ProductVariantImplCopyWith<$Res>
414 | implements $ProductVariantCopyWith<$Res> {
415 | factory _$$ProductVariantImplCopyWith(_$ProductVariantImpl value,
416 | $Res Function(_$ProductVariantImpl) then) =
417 | __$$ProductVariantImplCopyWithImpl<$Res>;
418 | @override
419 | @useResult
420 | $Res call({String? size, String? color, double price});
421 | }
422 |
423 | /// @nodoc
424 | class __$$ProductVariantImplCopyWithImpl<$Res>
425 | extends _$ProductVariantCopyWithImpl<$Res, _$ProductVariantImpl>
426 | implements _$$ProductVariantImplCopyWith<$Res> {
427 | __$$ProductVariantImplCopyWithImpl(
428 | _$ProductVariantImpl _value, $Res Function(_$ProductVariantImpl) _then)
429 | : super(_value, _then);
430 |
431 | @pragma('vm:prefer-inline')
432 | @override
433 | $Res call({
434 | Object? size = freezed,
435 | Object? color = freezed,
436 | Object? price = null,
437 | }) {
438 | return _then(_$ProductVariantImpl(
439 | size: freezed == size
440 | ? _value.size
441 | : size // ignore: cast_nullable_to_non_nullable
442 | as String?,
443 | color: freezed == color
444 | ? _value.color
445 | : color // ignore: cast_nullable_to_non_nullable
446 | as String?,
447 | price: null == price
448 | ? _value.price
449 | : price // ignore: cast_nullable_to_non_nullable
450 | as double,
451 | ));
452 | }
453 | }
454 |
455 | /// @nodoc
456 | @JsonSerializable()
457 | class _$ProductVariantImpl
458 | with DiagnosticableTreeMixin
459 | implements _ProductVariant {
460 | _$ProductVariantImpl({this.size, this.color, required this.price});
461 |
462 | factory _$ProductVariantImpl.fromJson(Map json) =>
463 | _$$ProductVariantImplFromJson(json);
464 |
465 | @override
466 | final String? size;
467 | @override
468 | final String? color;
469 | @override
470 | final double price;
471 |
472 | @override
473 | String toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) {
474 | return 'ProductVariant(size: $size, color: $color, price: $price)';
475 | }
476 |
477 | @override
478 | void debugFillProperties(DiagnosticPropertiesBuilder properties) {
479 | super.debugFillProperties(properties);
480 | properties
481 | ..add(DiagnosticsProperty('type', 'ProductVariant'))
482 | ..add(DiagnosticsProperty('size', size))
483 | ..add(DiagnosticsProperty('color', color))
484 | ..add(DiagnosticsProperty('price', price));
485 | }
486 |
487 | @override
488 | bool operator ==(Object other) {
489 | return identical(this, other) ||
490 | (other.runtimeType == runtimeType &&
491 | other is _$ProductVariantImpl &&
492 | (identical(other.size, size) || other.size == size) &&
493 | (identical(other.color, color) || other.color == color) &&
494 | (identical(other.price, price) || other.price == price));
495 | }
496 |
497 | @JsonKey(ignore: true)
498 | @override
499 | int get hashCode => Object.hash(runtimeType, size, color, price);
500 |
501 | @JsonKey(ignore: true)
502 | @override
503 | @pragma('vm:prefer-inline')
504 | _$$ProductVariantImplCopyWith<_$ProductVariantImpl> get copyWith =>
505 | __$$ProductVariantImplCopyWithImpl<_$ProductVariantImpl>(
506 | this, _$identity);
507 |
508 | @override
509 | Map toJson() {
510 | return _$$ProductVariantImplToJson(
511 | this,
512 | );
513 | }
514 | }
515 |
516 | abstract class _ProductVariant implements ProductVariant {
517 | factory _ProductVariant(
518 | {final String? size,
519 | final String? color,
520 | required final double price}) = _$ProductVariantImpl;
521 |
522 | factory _ProductVariant.fromJson(Map json) =
523 | _$ProductVariantImpl.fromJson;
524 |
525 | @override
526 | String? get size;
527 | @override
528 | String? get color;
529 | @override
530 | double get price;
531 | @override
532 | @JsonKey(ignore: true)
533 | _$$ProductVariantImplCopyWith<_$ProductVariantImpl> get copyWith =>
534 | throw _privateConstructorUsedError;
535 | }
536 |
--------------------------------------------------------------------------------