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 |
--------------------------------------------------------------------------------
/macos/.gitignore:
--------------------------------------------------------------------------------
1 | # Flutter-related
2 | **/Flutter/ephemeral/
3 | **/Pods/
4 |
5 | # Xcode-related
6 | **/dgph
7 | **/xcuserdata/
8 |
--------------------------------------------------------------------------------
/macos/Flutter/Flutter-Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "ephemeral/Flutter-Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/macos/Flutter/Flutter-Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "ephemeral/Flutter-Generated.xcconfig"
2 |
--------------------------------------------------------------------------------
/macos/Flutter/GeneratedPluginRegistrant.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Generated file. Do not edit.
3 | //
4 |
5 | import FlutterMacOS
6 | import Foundation
7 |
8 | import flutter_inappwebview_macos
9 | import path_provider_foundation
10 | import printing
11 | import shared_preferences_foundation
12 |
13 | func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
14 | InAppWebViewFlutterPlugin.register(with: registry.registrar(forPlugin: "InAppWebViewFlutterPlugin"))
15 | PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
16 | PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin"))
17 | SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
18 | }
19 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/macos/Runner.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/macos/Runner/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | import Cocoa
2 | import FlutterMacOS
3 |
4 | @main
5 | class AppDelegate: FlutterAppDelegate {
6 | override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
7 | return true
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png
--------------------------------------------------------------------------------
/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png
--------------------------------------------------------------------------------
/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 = flutter_bloc_advance
9 |
10 | // The application's bundle identifier
11 | PRODUCT_BUNDLE_IDENTIFIER = com.cevheri.flutter.flutterBlocAdvance
12 |
13 | // The copyright displayed in application information
14 | PRODUCT_COPYRIGHT = Copyright © 2024 com.cevheri.flutter. All rights reserved.
15 |
--------------------------------------------------------------------------------
/macos/Runner/Configs/Debug.xcconfig:
--------------------------------------------------------------------------------
1 | #include "../../Flutter/Flutter-Debug.xcconfig"
2 | #include "Warnings.xcconfig"
3 |
--------------------------------------------------------------------------------
/macos/Runner/Configs/Release.xcconfig:
--------------------------------------------------------------------------------
1 | #include "../../Flutter/Flutter-Release.xcconfig"
2 | #include "Warnings.xcconfig"
3 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/macos/Runner/Release.entitlements:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | com.apple.security.app-sandbox
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/macos/RunnerTests/RunnerTests.swift:
--------------------------------------------------------------------------------
1 | import Cocoa
2 | import FlutterMacOS
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 |
--------------------------------------------------------------------------------
/pubspec.yaml:
--------------------------------------------------------------------------------
1 | name: flutter_bloc_advance
2 | description: "Flutter Bloc Advance Template"
3 | publish_to: 'none'
4 | version: 0.13.1+1
5 |
6 | environment:
7 | sdk: ^3.6.0
8 | flutter: '3.27.1'
9 |
10 | dependencies:
11 | flutter:
12 | sdk: flutter
13 | cupertino_icons: ^1.0.8
14 | flutter_localizations:
15 | sdk: flutter
16 | flutter_bloc:
17 | http:
18 | go_router:
19 | adaptive_theme:
20 | equatable:
21 | auto_route:
22 | get:
23 | intl:
24 | pdf:
25 | printing:
26 | dart_json_mapper:
27 | expansion_tile_card:
28 | device_preview:
29 | getwidget:
30 | flutter_form_builder: ^9.5.0
31 | form_builder_validators: ^11.0.0
32 | string_2_icon:
33 | intl_utils:
34 | pattern_formatter:
35 | http_certificate_pinning:
36 | bloc_concurrency:
37 | modbus_client_tcp:
38 | custom_navigation_bar:
39 | flutter_inappwebview:
40 | animated_toggle_switch:
41 | reflectable:
42 | glob:
43 | shared_preferences:
44 | logger: ^2.5.0
45 | get_storage:
46 |
47 | dev_dependencies:
48 | flutter_test:
49 | sdk: flutter
50 | flutter_lints: ^4.0.0
51 | integration_test:
52 | sdk: flutter
53 | build_runner:
54 | test: ^1.25.7
55 | bloc_test: ^9.1.7
56 | mockito: ^5.4.4
57 |
58 | flutter_secure_storage:
59 | enabled: true
60 | class_name: SecureStorage
61 | main_locale: en
62 |
63 | flutter_intl:
64 | enabled: true
65 |
66 | flutter:
67 | uses-material-design: true
68 | generate: true
69 | assets:
70 | - assets/mock/
71 | - assets/images/
--------------------------------------------------------------------------------
/scripts/run_build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo "Running flutter clean"
4 | flutter clean
5 |
6 | echo "Running pub get"
7 | flutter pub get
8 |
9 | echo "Running build_runner"
10 | dart run build_runner build --delete-conflicting-outputs
11 | dart run intl_utils:generate
12 |
13 | echo "Running flutter analyze"
14 | flutter analyze
15 | if [ $? -ne 0 ]; then
16 | echo "Flutter analyze found issues. Exiting."
17 | exit 1
18 | fi
19 |
20 | echo "Running flutter test"
21 | flutter test --coverage
22 | if [ $? -ne 0 ]; then
23 | echo "Flutter test found issues. Exiting."
24 | exit 1
25 | fi
26 |
27 | echo "Running flutter build apk"
28 | flutter build apk --release --target lib/main/main_prod.dart
29 |
30 | echo "Running flutter build appbundle"
31 | flutter build appbundle --release --target lib/main/main_prod.dart
32 |
--------------------------------------------------------------------------------
/scripts/run_fvm_build.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | fvm use 3.27.1
4 |
5 | echo "Running flutter clean"
6 | fvm flutter clean
7 |
8 | echo "Running pub get"
9 | fvm flutter pub get
10 |
11 | echo "Running build_runner"
12 | fvm dart run build_runner build --delete-conflicting-outputs
13 | fvm dart run intl_utils:generate
14 |
15 | echo "Running flutter analyze"
16 | fvm flutter analyze
17 | if [ $? -ne 0 ]; then
18 | echo "Flutter analyze found issues. Exiting."
19 | exit 1
20 | fi
21 |
22 | echo "Running flutter test"
23 | fvm flutter test --coverage
24 | if [ $? -ne 0 ]; then
25 | echo "Flutter test found issues. Exiting."
26 | exit 1
27 | fi
28 |
29 | echo "Running flutter build apk"
30 | fvm flutter build apk --release --target lib/main/main_prod.dart
31 |
32 | echo "Running flutter build appbundle"
33 | fvm flutter build appbundle --release --target lib/main/main_prod.dart
34 |
--------------------------------------------------------------------------------
/scripts/run_sonar_scanner.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #dart pub global activate fvm
4 | #export PATH="$PATH":"$HOME/.pub-cache/bin"
5 | fvm use 3.27.1
6 |
7 | fvm flutter clean
8 | fvm flutter pub get
9 |
10 | fvm dart run build_runner build --delete-conflicting-outputs
11 | fvm dart run intl_utils:generate
12 |
13 | # when flutter analyze issue found then exit
14 | fvm flutter analyze
15 | if [ $? -ne 0 ]; then
16 | echo "Flutter analyze found issues. Exiting."
17 | exit 1
18 | fi
19 |
20 | fvm flutter test --coverage
21 | if [ $? -ne 0 ]; then
22 | echo "Flutter test found issues. Exiting."
23 | exit 1
24 | fi
25 |
26 | # Download SonarQube scanner
27 | SONAR_SCANNER_VERSION=6.2.1.4610
28 | SONAR_SCANNER_DIR=$HOME/.sonar/sonar-scanner-$SONAR_SCANNER_VERSION-linux-x64
29 | SONAR_SCANNER_ZIP=$SONAR_SCANNER_DIR.zip
30 |
31 | if [ ! -d "$SONAR_SCANNER_DIR" ]; then
32 | echo "Downloading SonarQube scanner..."
33 | curl --create-dirs -sSLo $SONAR_SCANNER_ZIP https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_SCANNER_VERSION-linux-x64.zip
34 | unzip -o $SONAR_SCANNER_ZIP -d $HOME/.sonar/
35 | fi
36 |
37 | # Set up environment variables
38 | export PATH=$SONAR_SCANNER_DIR/bin:$PATH
39 |
40 | # Run SonarQube scanner
41 | $SONAR_SCANNER_DIR/bin/sonar-scanner \
42 | -Dsonar.projectKey=cevheri_flutter-bloc-advanced \
43 | -Dsonar.organization=cevheri-open-source \
44 | -Dsonar.sources=. \
45 | -Dsonar.host.url=https://sonarcloud.io \
46 | -Dsonar.login=$SONAR_TOKEN
--------------------------------------------------------------------------------
/scripts/run_unittests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | #dart pub global activate fvm
4 | #export PATH="$PATH":"$HOME/.pub-cache/bin"
5 | fvm use 3.27.1
6 |
7 | fvm flutter clean
8 | fvm flutter pub get
9 |
10 | fvm dart run build_runner build --delete-conflicting-outputs
11 | fvm dart run intl_utils:generate
12 |
13 | # when flutter analyze issue found then exit
14 | fvm flutter analyze
15 | if [ $? -ne 0 ]; then
16 | echo "Flutter analyze found issues. Exiting."
17 | exit 1
18 | fi
19 |
20 | fvm flutter test --coverage
21 | if [ $? -ne 0 ]; then
22 | echo "Flutter test found issues. Exiting."
23 | exit 1
24 | fi
--------------------------------------------------------------------------------
/sonar-project.properties:
--------------------------------------------------------------------------------
1 | # This is the name and version displayed in the SonarCloud UI.
2 | sonar.projectKey=cevheri_flutter-bloc-advanced
3 | sonar.organization=cevheri-open-source
4 | sonar.host.url=https://sonarcloud.io
5 |
6 |
7 | sonar.projectName=flutter-template
8 | sonar.projectVersion=1.0
9 |
10 |
11 | # Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
12 | sonar.sources=lib/
13 | #sonar.exclusions=**/test/**
14 | #sonar.test.exclusions=test/**
15 | sonar.tests=test/
16 | #sonar.verbose=true
17 | # exclude: lib/generated and lib/main dart files
18 | sonar.exclusions=assets/**,lib/main/**,test/**,linux/**,macos/**,windows/**,build/**,ios/**,android/**,web/**,example/**,packages/**,pubspec.lock,functions/**,lib/generated/**,lib/i18n/**,lib/routes/app_router.dart
19 |
20 | sonar.cpd.exclusions=lib/main/**
21 |
22 | # Encoding of the source code. Default is default system encoding
23 | sonar.sourceEncoding=UTF-8
24 |
25 | sonar.c.file.suffixes=-
26 | sonar.cpp.file.suffixes=-
27 | sonar.objc.file.suffixes=-
28 |
29 |
30 |
31 | sonar.dart.lcov.reportPaths=coverage/lcov.info
--------------------------------------------------------------------------------
/test/conf/environment_test.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_bloc_advance/configuration/allowed_paths.dart';
2 | import 'package:flutter_bloc_advance/configuration/environment.dart';
3 | import 'package:flutter_test/flutter_test.dart';
4 |
5 | void main() {
6 | group('ProfileConstants', () {
7 | test('setEnvironment sets dev environment', () {
8 | ProfileConstants.setEnvironment(Environment.dev);
9 | expect(ProfileConstants.isDevelopment, true);
10 | expect(ProfileConstants.api, "mock");
11 | });
12 |
13 | test('setEnvironment sets test environment', () {
14 | ProfileConstants.setEnvironment(Environment.test);
15 | expect(ProfileConstants.isDevelopment, false);
16 | expect(ProfileConstants.isProduction, false);
17 | expect(ProfileConstants.api, "mock");
18 | });
19 |
20 | test('setEnvironment sets prod environment', () {
21 | ProfileConstants.setEnvironment(Environment.prod);
22 | expect(ProfileConstants.isProduction, true);
23 | expect(ProfileConstants.api, "https://dhw-api.onrender.com/api");
24 | });
25 | });
26 | test("allowed paths", () {
27 | expect(allowedPaths, [
28 | '/authenticate',
29 | '/register',
30 | '/logout',
31 | '/account/reset-password/init',
32 | '/forgot-password',
33 | '/login-otp',
34 | '/login-otp-verify',
35 | '/authenticate/send-otp',
36 | '/authenticate/verify-otp'
37 | ]);
38 | });
39 | }
40 |
--------------------------------------------------------------------------------
/test/conf/logger_test.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_bloc_advance/configuration/app_logger.dart';
2 | import 'package:flutter_test/flutter_test.dart';
3 |
4 | void main() {
5 | // AppLogger Test
6 | group("AppLogger Test", () {
7 | test("Logger Test", () {
8 | // production
9 | AppLogger.configure(isProduction: true, logFormat: LogFormat.simple);
10 | final log = AppLogger();
11 | log.trace("trace");
12 | log.debug("debug");
13 | log.info("info");
14 | log.warn("warn");
15 | log.error("error");
16 | expect(log.toString(), "AppLogger(Logger, info, simple)");
17 | });
18 |
19 | test("Logger test with name", () {
20 | // production
21 | AppLogger.configure(isProduction: true, logFormat: LogFormat.simple);
22 | final log = AppLogger.getLogger("logger_test.dart");
23 | log.trace("trace");
24 | log.debug("debug");
25 | log.info("info");
26 | log.warn("warn");
27 | log.error("error");
28 | expect(log.toString(), "AppLogger(logger_test.dart, info, simple)");
29 | });
30 |
31 | test("Logger Test with parameters", () {
32 | // production
33 | AppLogger.configure(isProduction: true, logFormat: LogFormat.simple);
34 | final log = AppLogger.getLogger("logger_test.dart");
35 | log.trace("trace p1:{}", ["param1"]);
36 | log.debug("debug");
37 | log.info("info");
38 | log.warn("warn");
39 | log.error("error");
40 | expect(log.toString(), "AppLogger(logger_test.dart, info, simple)");
41 | });
42 |
43 | test("Logger Test with parameters dev env", () {
44 | // production
45 | AppLogger.configure(isProduction: false, logFormat: LogFormat.extended);
46 | final log = AppLogger.getLogger("logger_test.dart");
47 | log.trace("trace p1:{}", ["param1"]);
48 | log.debug("debug");
49 | log.info("info");
50 | log.warn("warn");
51 | log.error("error");
52 | expect(log.toString(), "AppLogger(logger_test.dart, debug, extended)");
53 | });
54 | });
55 | }
56 |
--------------------------------------------------------------------------------
/test/data/model/authority_test.dart:
--------------------------------------------------------------------------------
1 | import 'dart:convert';
2 |
3 | import 'package:flutter_bloc_advance/data/models/authority.dart';
4 | import 'package:flutter_bloc_advance/main/main_local.mapper.g.dart';
5 | import 'package:flutter_test/flutter_test.dart';
6 |
7 | import '../../fake/user_data.dart';
8 |
9 | /// Test the Authority model
10 | void main() {
11 | setUp(() {
12 | initializeJsonMapper();
13 | });
14 |
15 | group("Authority Model", () {
16 | test('should create a Authority instance (Constructor)', () {
17 | expect(mockAuthorityPayload.name, 'ROLE_USER');
18 | });
19 |
20 | test('should copy a Authority instance with new values (copyWith)', () {
21 | final entityUpd = mockAuthorityPayload.copyWith();
22 |
23 | expect(entityUpd == mockAuthorityPayload, true);
24 | });
25 |
26 | test('should copy a Authority instance with new values (copyWith)', () {
27 | final entityUpd = mockAuthorityPayload.copyWith(name: 'ROLE_ADMIN');
28 |
29 | expect(entityUpd.name, 'ROLE_ADMIN');
30 | });
31 |
32 | test('should compare two Authorities instances', () {
33 | const entity = mockAuthorityPayload;
34 | final entityUpd = entity.copyWith(name: 'ROLE_ADMIN');
35 |
36 | expect(entity == entityUpd, false);
37 | });
38 | });
39 |
40 | group("Authority Model Json Test", () {
41 | test('should convert Authorities from Json', () {
42 | final json = mockAuthorityPayload.toJson();
43 | final entity = Authority.fromJson(json!);
44 |
45 | expect(entity?.name, 'ROLE_USER');
46 | });
47 |
48 | test('should convert Authorities from JsonString', () {
49 | final jsonString = jsonEncode(mockAuthorityPayload.toJson());
50 | final entity = Authority.fromJsonString(jsonString);
51 |
52 | expect(entity?.name, 'ROLE_USER');
53 | });
54 |
55 | test('should convert Authorities to Json', () {
56 | final json = mockAuthorityPayload.toJson()!;
57 |
58 | expect(json['name'], 'ROLE_USER');
59 | });
60 |
61 | test("to string method", () {
62 | const entity = mockAuthorityPayload;
63 |
64 | expect(entity.toString(), 'Authority(ROLE_USER)');
65 | });
66 | });
67 | }
68 |
--------------------------------------------------------------------------------
/test/data/model/otp_send_model_test.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_bloc_advance/data/models/send_otp_request.dart';
2 | import 'package:flutter_bloc_advance/main/main_local.mapper.g.dart';
3 | import 'package:flutter_test/flutter_test.dart';
4 |
5 | void main() {
6 | group('SendOtpRequest', () {
7 | test('should create SendOtpRequest instance with email', () {
8 | // given
9 | const testEmail = 'test@example.com';
10 |
11 | // when
12 | final request = SendOtpRequest(email: testEmail);
13 |
14 | // then
15 | expect(request.email, equals(testEmail));
16 | });
17 |
18 | test('should convert SendOtpRequest to JSON correctly', () {
19 | // given
20 | const testEmail = 'test@example.com';
21 | final request = SendOtpRequest(email: testEmail);
22 |
23 | // when
24 | final json = request.toJson();
25 |
26 | // then
27 | expect(json, {
28 | 'email': 'test@example.com',
29 | });
30 | });
31 |
32 | test('should create SendOtpRequest from JSON correctly', () {
33 | initializeJsonMapper();
34 | // given
35 | final json = {
36 | 'email': 'test@example.com',
37 | };
38 |
39 | // when
40 | final request = SendOtpRequest.fromJson(json);
41 |
42 | // then
43 | expect(request, isNotNull);
44 | expect(request?.email, equals('test@example.com'));
45 | });
46 |
47 | test('should return null when fromJson is called with invalid JSON', () {
48 | initializeJsonMapper();
49 | // given
50 | final invalidJson = {
51 | 'invalid_key': 'test@example.com',
52 | };
53 |
54 | // when
55 | final request = SendOtpRequest.fromJson(invalidJson);
56 |
57 | // then
58 | expect(request, isNull);
59 | });
60 | });
61 | }
62 |
--------------------------------------------------------------------------------
/test/data/repository/package_info.dart:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/test/data/repository/package_info.dart
--------------------------------------------------------------------------------
/test/fake/city_data.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_bloc_advance/data/models/city.dart';
2 | import 'package:flutter_bloc_advance/data/models/district.dart';
3 |
4 | /// City Fake data with full payload
5 | const mockCityPayload = City(id: '1', name: 'istanbul', plateCode: '34');
6 |
7 | /// District Fake data with full payload
8 | const mockDistrictPayload = District(id: 'id', name: 'kadikoy', code: '34');
9 |
--------------------------------------------------------------------------------
/test/fake/customer_data.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_bloc_advance/data/models/customer.dart';
2 |
3 | /// Customer fake data with full payload
4 | const mockCustomerFullPayload = Customer(
5 | id: '1',
6 | name: 'Acme',
7 | phone: '5055055050',
8 | cityName: 'Konya',
9 | email: 'john.doe@example.com',
10 | districtName: 'selçuklu',
11 | address: 'yazır mh.',
12 | active: true,
13 | );
14 |
--------------------------------------------------------------------------------
/test/fake/user_data.dart:
--------------------------------------------------------------------------------
1 | import 'package:flutter_bloc_advance/data/models/authority.dart';
2 | import 'package:flutter_bloc_advance/data/models/change_password.dart';
3 | import 'package:flutter_bloc_advance/data/models/jwt_token.dart';
4 | import 'package:flutter_bloc_advance/data/models/menu.dart';
5 | import 'package:flutter_bloc_advance/data/models/user.dart';
6 | import 'package:flutter_bloc_advance/data/models/user_jwt.dart';
7 |
8 | final DateTime createdDate = DateTime(2024, 1, 1);
9 |
10 | /// User fake data with full payload
11 | final mockUserFullPayload = User(
12 | id: '1',
13 | login: 'test_login',
14 | firstName: 'John',
15 | lastName: 'Doe',
16 | email: 'john.doe@example.com',
17 | activated: true,
18 | langKey: 'en',
19 | createdBy: 'admin',
20 | createdDate: createdDate,
21 | lastModifiedBy: 'admin',
22 | lastModifiedDate: createdDate,
23 | authorities: const ['ROLE_USER'],
24 | );
25 |
26 | /// Authority(Role) fake data
27 | const mockAuthorityPayload = Authority(name: 'ROLE_USER');
28 |
29 | /// PasswordChange fake data with full payload
30 | const mockPasswordChangePayload = PasswordChangeDTO(currentPassword: 'password', newPassword: 'new_password');
31 |
32 | /// JWTToken fake data
33 | const mockJWTTokenPayload = JWTToken(idToken: 'MOCK_TOKEN');
34 |
35 | /// Menu fake data with full payload
36 | const mockMenuPayload = Menu(
37 | id: "0",
38 | name: 'test name',
39 | description: '',
40 | url: 'https://dhw-api.onrender.com/',
41 | icon: '',
42 | orderPriority: 01,
43 | active: false,
44 | parent: null,
45 | level: 01,
46 | );
47 |
48 | /// UserJWT fake data with full payload
49 | const mockUserJWTPayload = UserJWT("username", "password");
50 |
--------------------------------------------------------------------------------
/test/main/app_test.dart:
--------------------------------------------------------------------------------
1 | import 'package:adaptive_theme/adaptive_theme.dart';
2 | import 'package:flutter/material.dart';
3 | import 'package:flutter_bloc/flutter_bloc.dart';
4 | import 'package:flutter_bloc_advance/main/app.dart';
5 | import 'package:flutter_test/flutter_test.dart';
6 |
7 | import '../test_utils.dart';
8 |
9 | void main() {
10 | setUpAll(() async {
11 | await TestUtils().setupUnitTest();
12 | });
13 |
14 | group('App Widget Tests', () {
15 | late App app;
16 |
17 | setUp(() {
18 | app = const App(language: 'tr', initialTheme: AdaptiveThemeMode.light);
19 | });
20 |
21 | testWidgets('App should build without errors', (WidgetTester tester) async {
22 | await tester.pumpWidget(app);
23 | await tester.pumpAndSettle();
24 | expect(find.byType(AdaptiveTheme), findsOneWidget);
25 | });
26 |
27 | testWidgets('App should handle theme changes', (WidgetTester tester) async {
28 | await tester.pumpWidget(app);
29 | await tester.pumpAndSettle();
30 |
31 | final AdaptiveTheme adaptiveTheme = tester.widget(find.byType(AdaptiveTheme));
32 | expect(adaptiveTheme.initial, equals(AdaptiveThemeMode.light));
33 |
34 | // Test dark theme
35 | app = const App(language: 'tr', initialTheme: AdaptiveThemeMode.dark);
36 | await tester.pumpWidget(app);
37 | await tester.pumpAndSettle();
38 |
39 | final AdaptiveTheme darkTheme = tester.widget(find.byType(AdaptiveTheme));
40 | expect(darkTheme.initial, equals(AdaptiveThemeMode.dark));
41 | });
42 |
43 | testWidgets('App should handle different languages', (WidgetTester tester) async {
44 | TestUtils().setupAuthentication();
45 | app = const App(language: 'en', initialTheme: AdaptiveThemeMode.light);
46 | await tester.pumpWidget(app);
47 | await tester.pumpAndSettle();
48 |
49 | const expectedLocale = Locale('en');
50 | final materialApp = tester.widget(find.byType(MaterialApp)) as MaterialApp;
51 | expect(materialApp.locale, equals(expectedLocale));
52 | });
53 |
54 | testWidgets('MultiBlocProvider should contain all required providers', (WidgetTester tester) async {
55 | await tester.pumpWidget(app);
56 | await tester.pumpAndSettle();
57 | expect(find.byType(MultiBlocProvider), findsOneWidget);
58 | });
59 | });
60 | }
61 |
--------------------------------------------------------------------------------
/test/presentation/screen/user/package_info.dart:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/test/presentation/screen/user/package_info.dart
--------------------------------------------------------------------------------
/test/presentation/widgets/package_info.dart:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/test/presentation/widgets/package_info.dart
--------------------------------------------------------------------------------
/test/test_utils.dart:
--------------------------------------------------------------------------------
1 | import 'package:equatable/equatable.dart';
2 | import 'package:flutter_bloc_advance/configuration/app_logger.dart';
3 | import 'package:flutter_bloc_advance/configuration/environment.dart';
4 | import 'package:flutter_bloc_advance/configuration/local_storage.dart';
5 | import 'package:flutter_bloc_advance/main/main_local.mapper.g.dart';
6 | import 'package:flutter_bloc_advance/routes/app_router.dart';
7 | import 'package:flutter_test/flutter_test.dart';
8 | import 'package:shared_preferences/shared_preferences.dart';
9 |
10 | /// Utility class for the tests
11 | ///
12 | /// This class contains utility methods that are used in the tests
13 | class TestUtils {
14 | /// Initialize the dependencies for the BLoC tests
15 | ///
16 | /// This method initializes the following dependencies:
17 | /// 1. JsonMapper
18 | /// 2. Flutter Test Binding
19 | /// 3. Shared Preferences
20 | /// 4. Equatable Configuration
21 | /// 5. Mock Method Call Handler for Path Provider
22 |
23 |
24 | Future setupUnitTest() async {
25 | AppLogger.configure(isProduction: false, logFormat: LogFormat.simple);
26 | ProfileConstants.setEnvironment(Environment.test);
27 | initializeJsonMapper();
28 | TestWidgetsFlutterBinding.ensureInitialized();
29 | EquatableConfig.stringify = true;
30 | await _clearStorage();
31 | await AppLocalStorage().save(StorageKeys.language.name, "en");
32 | AppRouter().setRouter(RouterType.goRouter);
33 | }
34 | Future setupRepositoryUnitTest() async {
35 | AppLogger.configure(isProduction: false, logFormat: LogFormat.simple);
36 | ProfileConstants.setEnvironment(Environment.test);
37 | initializeJsonMapper();
38 | await _clearStorage();
39 | await AppLocalStorage().save(StorageKeys.language.name, "en");
40 | AppRouter().setRouter(RouterType.goRouter);
41 | }
42 |
43 | Future tearDownUnitTest() async {
44 | return await _clearStorage();
45 | }
46 |
47 | // add mock token to storage
48 | Future setupAuthentication() async {
49 | await AppLocalStorage().save(StorageKeys.jwtToken.name, "MOCK_TOKEN");
50 | }
51 |
52 | Future _clearStorage() async {
53 | SharedPreferences.setMockInitialValues({});
54 | await AppLocalStorage().clear();
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/test/widget_test.dart:
--------------------------------------------------------------------------------
1 | // import 'package:adaptive_theme/adaptive_theme.dart';
2 | // import 'package:flutter/material.dart';
3 | // import 'package:flutter_bloc_advance/configuration/app_logger.dart';
4 | // import 'package:flutter_bloc_advance/configuration/environment.dart';
5 | // import 'package:flutter_bloc_advance/configuration/local_storage.dart';
6 | // import 'package:flutter_bloc_advance/main/app.dart';
7 | // import 'package:flutter_bloc_advance/main/main_local.mapper.g.dart';
8 | // import 'package:flutter_bloc_advance/routes/app_router.dart';
9 | import 'package:flutter_test/flutter_test.dart';
10 |
11 | void main() {
12 | testWidgets('Counter increments smoke test', (WidgetTester tester) async {
13 | // AppLogger.configure(isProduction: false);
14 | // final log = AppLogger.getLogger("main_local.dart");
15 | // ProfileConstants.setEnvironment(Environment.dev);
16 | // log.info("Starting App with env: {}", [Environment.dev.name]);
17 | // initializeJsonMapper();
18 | // //WidgetsFlutterBinding.ensureInitialized();
19 | // const defaultLanguage = "en";
20 | // AppLocalStorage().setStorage(StorageType.sharedPreferences);
21 | // await AppLocalStorage().save(StorageKeys.language.name, defaultLanguage);
22 | // AppRouter().setRouter(RouterType.goRouter);
23 | // const initialTheme = AdaptiveThemeMode.dark;
24 | // //await tester.pumpWidget(const App(language: defaultLanguage, initialTheme: initialTheme));
25 |
26 | // Verify that our counter starts at 0.
27 | // expect(find.text('0'), findsOneWidget);
28 | // expect(find.text('1'), findsNothing);
29 |
30 | // Tap the '+' icon and trigger a frame.
31 | // await tester.tap(find.byIcon(Icons.add));
32 | // await tester.pump();
33 |
34 | // Verify that our counter has incremented.
35 | // expect(find.text('0'), findsNothing);
36 | // expect(find.text('1'), findsOneWidget);
37 | });
38 | }
39 |
--------------------------------------------------------------------------------
/web/favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/web/favicon.png
--------------------------------------------------------------------------------
/web/icons/Icon-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/web/icons/Icon-192.png
--------------------------------------------------------------------------------
/web/icons/Icon-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/web/icons/Icon-512.png
--------------------------------------------------------------------------------
/web/icons/Icon-maskable-192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/web/icons/Icon-maskable-192.png
--------------------------------------------------------------------------------
/web/icons/Icon-maskable-512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/web/icons/Icon-maskable-512.png
--------------------------------------------------------------------------------
/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 | flutter_bloc_advance
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/web/manifest.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "flutter_bloc_advance",
3 | "short_name": "flutter_bloc_advance",
4 | "start_url": ".",
5 | "display": "standalone",
6 | "background_color": "#0175C2",
7 | "theme_color": "#0175C2",
8 | "description": "flutter_bloc_advance",
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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | #include
10 | #include
11 |
12 | void RegisterPlugins(flutter::PluginRegistry* registry) {
13 | FlutterInappwebviewWindowsPluginCApiRegisterWithRegistrar(
14 | registry->GetRegistrarForPlugin("FlutterInappwebviewWindowsPluginCApi"));
15 | PrintingPluginRegisterWithRegistrar(
16 | registry->GetRegistrarForPlugin("PrintingPlugin"));
17 | }
18 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/windows/flutter/generated_plugins.cmake:
--------------------------------------------------------------------------------
1 | #
2 | # Generated file, do not edit.
3 | #
4 |
5 | list(APPEND FLUTTER_PLUGIN_LIST
6 | flutter_inappwebview_windows
7 | printing
8 | )
9 |
10 | list(APPEND FLUTTER_FFI_PLUGIN_LIST
11 | )
12 |
13 | set(PLUGIN_BUNDLED_LIBRARIES)
14 |
15 | foreach(plugin ${FLUTTER_PLUGIN_LIST})
16 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin})
17 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
18 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $)
19 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
20 | endforeach(plugin)
21 |
22 | foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
23 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/windows plugins/${ffi_plugin})
24 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
25 | endforeach(ffi_plugin)
26 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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"flutter_bloc_advance", 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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/windows/runner/resources/app_icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cevheri/flutter-bloc-advanced/4b9dcdbad897a0f78ccb09b6062e94b008c4d35d/windows/runner/resources/app_icon.ico
--------------------------------------------------------------------------------
/windows/runner/runner.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | PerMonitorV2
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/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 | unsigned 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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------