From 593fda09751997a217f449296a0bd27311466a9c Mon Sep 17 00:00:00 2001 From: Tony Bark <35226681+tonytins@users.noreply.github.com> Date: Sat, 29 May 2021 12:01:35 -0400 Subject: [PATCH] Adpative layout - The desktop version has the score, ect, in the title bar area now while the mobile version remains the same - Capitalized "bullseye" - Used "late" keyword for certain variables - Updated application Id --- android/app/build.gradle | 2 +- android/app/src/main/AndroidManifest.xml | 2 +- ios/Runner.xcodeproj/project.pbxproj | 6 +- ios/Runner/Info.plist | 2 +- lib/desktop.dart | 20 ++++ lib/game_model.dart | 8 +- lib/main.dart | 108 +++++++++++++----- lib/score.dart | 4 +- linux/CMakeLists.txt | 4 +- linux/flutter/generated_plugin_registrant.cc | 4 + linux/flutter/generated_plugins.cmake | 1 + linux/my_application.cc | 4 +- macos/Flutter/GeneratedPluginRegistrant.swift | 2 + macos/Podfile.lock | 6 + macos/Runner.xcodeproj/project.pbxproj | 7 +- .../xcshareddata/xcschemes/Runner.xcscheme | 14 +-- macos/Runner/Configs/AppInfo.xcconfig | 4 +- macos/Runner/MainFlutterWindow.swift | 8 +- pubspec.yaml | 9 +- .../flutter/generated_plugin_registrant.cc | 3 + windows/flutter/generated_plugins.cmake | 1 + windows/runner/main.cpp | 3 + 22 files changed, 154 insertions(+), 68 deletions(-) create mode 100644 lib/desktop.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index 9d8a641..b2d0ce4 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -34,7 +34,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.example.bullseye" + applicationId "com.tonybark.bullseye" minSdkVersion 16 targetSdkVersion 30 versionCode flutterVersionCode.toInteger() diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 7e94f05..b5eace4 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ CFBundleInfoDictionaryVersion 6.0 CFBundleName - bullseye + Bullseye CFBundlePackageType APPL CFBundleShortVersionString diff --git a/lib/desktop.dart b/lib/desktop.dart new file mode 100644 index 0000000..61cf252 --- /dev/null +++ b/lib/desktop.dart @@ -0,0 +1,20 @@ +import 'dart:io'; + +import 'package:bitsdojo_window/bitsdojo_window.dart'; +import 'package:flutter/material.dart'; + +bool get isDesktop => + (Platform.isLinux || Platform.isMacOS || Platform.isWindows); + +class WindowButtons extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Row( + children: [ + MinimizeWindowButton(), + MaximizeWindowButton(), + CloseWindowButton() + ], + ); + } +} diff --git a/lib/game_model.dart b/lib/game_model.dart index 446d398..1144ddd 100644 --- a/lib/game_model.dart +++ b/lib/game_model.dart @@ -8,8 +8,8 @@ class GameModel { this.totalScore = SCORE_START, this.round = ROUND_START]); - int? target; - int? current; - int? totalScore; - int? round; + late int target; + late int current; + late int totalScore; + late int round; } diff --git a/lib/main.dart b/lib/main.dart index d28f788..16abd48 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,29 +1,46 @@ -import 'package:flutter/cupertino.dart'; +import 'dart:math'; +import 'package:bitsdojo_window/bitsdojo_window.dart'; +import 'package:bullseye/desktop.dart'; + import 'package:flutter/material.dart'; -import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; import 'package:flutter/services.dart'; import 'package:bullseye/prompt.dart'; import 'package:bullseye/control.dart'; import 'package:bullseye/score.dart'; import 'package:bullseye/game_model.dart'; +import 'package:flutter_platform_widgets/flutter_platform_widgets.dart'; -void main() => runApp(BullsEyeApp()); +const gameTitle = "Bullseye"; + +void main() { + runApp(BullsEyeApp()); + + if (isDesktop) { + doWhenWindowReady(() { + final win = appWindow; + final minSize = Size(600, 450); + + win.minSize = minSize; + win.size = minSize; + win.alignment = Alignment.center; + win.title = gameTitle; + + win.show(); + }); + } +} class BullsEyeApp extends StatelessWidget { - Brightness currentBrightness = Brightness.light; - // This widget is the root of your application. @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations( [DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]); return PlatformApp( - title: 'BullsEye', - // For some reason text is black in dark mode on iOS - cupertino: (_, __) => CupertinoAppData( - theme: CupertinoThemeData(brightness: Brightness.light)), - home: GamePage(title: 'BullsEye')); + title: gameTitle, + debugShowCheckedModeBanner: false, + home: GamePage(title: gameTitle)); } } @@ -37,38 +54,69 @@ class GamePage extends StatefulWidget { class _GamePageState extends State { bool _alertIsVisable = false; - GameModel _model = GameModel(50); + late GameModel _model; @override void initState() { super.initState(); - _model = GameModel(50); + var rng = Random(); + _model = GameModel(rng.nextInt(100) + 1); + } + + Widget gameContainer() { + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Prompt(targetValue: _model.target), + Control(model: _model), + PlatformTextButton( + child: PlatformText('Hit me!'), + onPressed: () { + this._alertIsVisable = true; + _showAlert(context); + }) + ], + ); + } + + Widget mobileContainer() { + return Column(mainAxisAlignment: MainAxisAlignment.center, children: [ + gameContainer(), + Score(totalScore: _model.totalScore, round: _model.round) + ]); + } + + Widget desktopContainer() { + return Column(children: [ + Container( + height: 50, + child: WindowTitleBarBox( + child: Row( + children: [ + Expanded( + child: MoveWindow( + child: Score( + totalScore: _model.totalScore, round: _model.round))) + ], + ))), + Expanded(child: gameContainer()), + ]); } @override Widget build(BuildContext context) { - return PlatformScaffold( - body: Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Prompt(targetValue: _model.target), - Control(model: _model), - PlatformTextButton( - child: PlatformText('Hit me!'), - onPressed: () { - this._alertIsVisable = true; - _showAlert(context); - }), - Score(totalScore: _model.totalScore, round: _model.round) - ], - ), - ), + return Scaffold( + body: LayoutBuilder(builder: (context, constraints) { + if (isDesktop) + return desktopContainer(); + else + return mobileContainer(); + }), ); } void _showAlert(BuildContext context) { - Widget okButton = PlatformTextButton( + var okButton = PlatformTextButton( child: PlatformText("Awesome!"), onPressed: () { Navigator.of(context).pop(); diff --git a/lib/score.dart b/lib/score.dart index c8f634a..00218a3 100644 --- a/lib/score.dart +++ b/lib/score.dart @@ -13,7 +13,7 @@ class Score extends StatelessWidget { return Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - PlatformButton( + PlatformTextButton( child: PlatformText("Start Over"), onPressed: () {}, ), @@ -35,7 +35,7 @@ class Score extends StatelessWidget { ], ), ), - PlatformButton( + PlatformTextButton( child: PlatformText("Info"), onPressed: () {}, ) diff --git a/linux/CMakeLists.txt b/linux/CMakeLists.txt index 95d18ee..6c71015 100644 --- a/linux/CMakeLists.txt +++ b/linux/CMakeLists.txt @@ -1,8 +1,8 @@ cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) -set(BINARY_NAME "bullseye") -set(APPLICATION_ID "com.example.bullseye") +set(BINARY_NAME "Bullseye") +set(APPLICATION_ID "com.tonybark.bullseye") cmake_policy(SET CMP0063 NEW) diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index d38195a..8e42ee0 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -4,6 +4,10 @@ #include "generated_plugin_registrant.h" +#include void fl_register_plugins(FlPluginRegistry* registry) { + g_autoptr(FlPluginRegistrar) bitsdojo_window_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "BitsdojoWindowPlugin"); + bitsdojo_window_plugin_register_with_registrar(bitsdojo_window_linux_registrar); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 51436ae..9978ad3 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + bitsdojo_window_linux ) set(PLUGIN_BUNDLED_LIBRARIES) diff --git a/linux/my_application.cc b/linux/my_application.cc index 9dd089f..c0221d6 100644 --- a/linux/my_application.cc +++ b/linux/my_application.cc @@ -40,12 +40,12 @@ static void my_application_activate(GApplication* application) { if (use_header_bar) { GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); gtk_widget_show(GTK_WIDGET(header_bar)); - gtk_header_bar_set_title(header_bar, "bullseye"); + gtk_header_bar_set_title(header_bar, "Bullseye"); gtk_header_bar_set_show_close_button(header_bar, TRUE); gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); } else { - gtk_window_set_title(window, "bullseye"); + gtk_window_set_title(window, "Bullseye"); } gtk_window_set_default_size(window, 1280, 720); diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 0d56f51..ea04001 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,8 +5,10 @@ import FlutterMacOS import Foundation +import bitsdojo_window_macos import path_provider_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + BitsdojoWindowPlugin.register(with: registry.registrar(forPlugin: "BitsdojoWindowPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) } diff --git a/macos/Podfile.lock b/macos/Podfile.lock index 328ddd1..b4b68e5 100644 --- a/macos/Podfile.lock +++ b/macos/Podfile.lock @@ -1,19 +1,25 @@ PODS: + - bitsdojo_window_macos (0.0.1): + - FlutterMacOS - FlutterMacOS (1.0.0) - path_provider_macos (0.0.1): - FlutterMacOS DEPENDENCIES: + - bitsdojo_window_macos (from `Flutter/ephemeral/.symlinks/plugins/bitsdojo_window_macos/macos`) - FlutterMacOS (from `Flutter/ephemeral`) - path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`) EXTERNAL SOURCES: + bitsdojo_window_macos: + :path: Flutter/ephemeral/.symlinks/plugins/bitsdojo_window_macos/macos FlutterMacOS: :path: Flutter/ephemeral path_provider_macos: :path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos SPEC CHECKSUMS: + bitsdojo_window_macos: 7e9b1bbb09bdce418d9657ead7fc9d824203ff0d FlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424 path_provider_macos: a0a3fd666cb7cd0448e936fb4abad4052961002b diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj index 3ff81a7..9067a3c 100644 --- a/macos/Runner.xcodeproj/project.pbxproj +++ b/macos/Runner.xcodeproj/project.pbxproj @@ -56,7 +56,7 @@ 1FA37E1854051AEE30722181 /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = ""; }; 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = ""; }; - 33CC10ED2044A3C60003C045 /* bullseye.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = bullseye.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 33CC10ED2044A3C60003C045 /* Bullseye.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Bullseye.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = ""; }; 33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; @@ -112,7 +112,7 @@ 33CC10EE2044A3C60003C045 /* Products */ = { isa = PBXGroup; children = ( - 33CC10ED2044A3C60003C045 /* bullseye.app */, + 33CC10ED2044A3C60003C045 /* Bullseye.app */, ); name = Products; sourceTree = ""; @@ -159,7 +159,6 @@ 774797C801BB581636907200 /* Pods-Runner.release.xcconfig */, 6F8A7F66FBB30BD4E0A9315F /* Pods-Runner.profile.xcconfig */, ); - name = Pods; path = Pods; sourceTree = ""; }; @@ -193,7 +192,7 @@ ); name = Runner; productName = Runner; - productReference = 33CC10ED2044A3C60003C045 /* bullseye.app */; + productReference = 33CC10ED2044A3C60003C045 /* Bullseye.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ diff --git a/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index eba04a8..43416d9 100644 --- a/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -15,7 +15,7 @@ @@ -31,13 +31,13 @@ - - + + - - diff --git a/macos/Runner/Configs/AppInfo.xcconfig b/macos/Runner/Configs/AppInfo.xcconfig index 87d9254..0f37a69 100644 --- a/macos/Runner/Configs/AppInfo.xcconfig +++ b/macos/Runner/Configs/AppInfo.xcconfig @@ -5,10 +5,10 @@ // 'flutter create' template. // The application's name. By default this is also the title of the Flutter window. -PRODUCT_NAME = bullseye +PRODUCT_NAME = Bullseye; // The application's bundle identifier -PRODUCT_BUNDLE_IDENTIFIER = com.example.bullseye +PRODUCT_BUNDLE_IDENTIFIER = com.tonybark.bullseye; // The copyright displayed in application information PRODUCT_COPYRIGHT = Copyright © 2021 com.example. All rights reserved. diff --git a/macos/Runner/MainFlutterWindow.swift b/macos/Runner/MainFlutterWindow.swift index 2722837..2b53810 100644 --- a/macos/Runner/MainFlutterWindow.swift +++ b/macos/Runner/MainFlutterWindow.swift @@ -1,7 +1,13 @@ import Cocoa import FlutterMacOS +import bitsdojo_window_macos + +class MainFlutterWindow: BitsdojoWindow { + + override func bitsdojo_window_configure() -> UInt { + return BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP + } -class MainFlutterWindow: NSWindow { override func awakeFromNib() { let flutterViewController = FlutterViewController.init() let windowFrame = self.frame diff --git a/pubspec.yaml b/pubspec.yaml index 149e6b4..0b1ca1d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A new Flutter project. # The following line prevents the package from being accidentally published to # pub.dev using `pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: "none" # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 @@ -24,12 +24,12 @@ dependencies: flutter: sdk: flutter - # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 google_fonts: ^2.1.0 flutter_platform_widgets: ^1.9.0 + bitsdojo_window: ^0.1.0+1 dev_dependencies: flutter_test: @@ -40,23 +40,18 @@ dev_dependencies: # The following section is specific to Flutter. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. uses-material-design: true - # To add assets to your application, add an assets section, like this: # assets: # - images/a_dot_burr.jpeg # - images/a_dot_ham.jpeg - # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware. - # For details regarding adding assets from package dependencies, see # https://flutter.dev/assets-and-images/#from-packages - # To add custom fonts to your application, add a fonts section here, # in this "flutter" section. Each entry in this list should have a # "family" key with the font family name, and a "fonts" key with a diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 4bfa0f3..684e11f 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -4,6 +4,9 @@ #include "generated_plugin_registrant.h" +#include void RegisterPlugins(flutter::PluginRegistry* registry) { + BitsdojoWindowPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("BitsdojoWindowPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 4d10c25..065b15b 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + bitsdojo_window_windows ) set(PLUGIN_BUNDLED_LIBRARIES) diff --git a/windows/runner/main.cpp b/windows/runner/main.cpp index afc95a2..6018785 100644 --- a/windows/runner/main.cpp +++ b/windows/runner/main.cpp @@ -6,6 +6,9 @@ #include "run_loop.h" #include "utils.h" +#include +auto bdw = bitsdojo_window_configure(BDW_CUSTOM_FRAME | BDW_HIDE_ON_STARTUP); + int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, _In_ wchar_t *command_line, _In_ int show_command) { // Attach to console when present (e.g., 'flutter run') or create a