Skip to content

Commit

Permalink
Align code with latest Flutter version
Browse files Browse the repository at this point in the history
Signed-off-by: dmitry-erin <[email protected]>
  • Loading branch information
dmitry-erin committed Apr 11, 2024
1 parent f5184b5 commit 4c0393f
Show file tree
Hide file tree
Showing 13 changed files with 548 additions and 335 deletions.
26 changes: 24 additions & 2 deletions .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,27 @@
# This file should be version controlled and should not be manually edited.

version:
revision: f9bb4289e9fd861d70ae78bcc3a042ef1b35cc9d
channel: beta
revision: "6c4930c4ac86fb286f30e31d0ec8bffbcbb9953e"
channel: "stable"

project_type: app

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: 6c4930c4ac86fb286f30e31d0ec8bffbcbb9953e
base_revision: 6c4930c4ac86fb286f30e31d0ec8bffbcbb9953e
- platform: linux
create_revision: 6c4930c4ac86fb286f30e31d0ec8bffbcbb9953e
base_revision: 6c4930c4ac86fb286f30e31d0ec8bffbcbb9953e

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
93 changes: 37 additions & 56 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({Key? key, required this.title}) : super(key: key);

final String title;

Expand All @@ -25,91 +25,80 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {

String output = "0";

String _output = "0";
double num1 = 0.0;
double num2 = 0.0;
String operand = "";
bool operandPressed = false;

buttonPressed(String buttonText){

if(buttonText == "CLEAR"){

buttonPressed(String buttonText) {
if (buttonText == "CLEAR") {
_output = "0";
num1 = 0.0;
num2 = 0.0;
operand = "";

} else if (buttonText == "+" || buttonText == "-" || buttonText == "/" || buttonText == "X"){

} else if (buttonText == "+" ||
buttonText == "-" ||
buttonText == "/" ||
buttonText == "X") {
operandPressed = true;
num1 = double.parse(output);

operand = buttonText;

_output = "0";

} else if(buttonText == "."){

if(_output.contains(".")){
print("Already conatains a decimals");
} else if (buttonText == ".") {
if (_output.contains(".")) {
print("Already contains a decimals");
return;

} else {
_output = _output + buttonText;
}

} else if (buttonText == "="){

} else if (buttonText == "=") {
num2 = double.parse(output);

if(operand == "+"){
if (operand == "+") {
_output = (num1 + num2).toString();
}
if(operand == "-"){
if (operand == "-") {
_output = (num1 - num2).toString();
}
if(operand == "X"){
if (operand == "X") {
_output = (num1 * num2).toString();
}
if(operand == "/"){
if (operand == "/") {
_output = (num1 / num2).toString();
}

num1 = 0.0;
num2 = 0.0;
operand = "";

} else {

_output = _output + buttonText;

}

print(_output);

setState(() {

output = double.parse(_output).toStringAsFixed(2);

});

}

Widget buildButton(String buttonText) {
return new Expanded(
child: new OutlineButton(
padding: new EdgeInsets.all(24.0),
child: new Text(buttonText,
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold
return Expanded(
child: OutlinedButton(
onPressed: () => buttonPressed(buttonText),
style: ButtonStyle(
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(
EdgeInsets.all(24.0),
),
),
onPressed: () =>
buttonPressed(buttonText)
,
),
child: Text(
buttonText,
style: TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold),
),
),
);
}
Expand All @@ -124,50 +113,42 @@ class _MyHomePageState extends State<MyHomePage> {
child: new Column(
children: <Widget>[
new Container(
alignment: Alignment.centerRight,
padding: new EdgeInsets.symmetric(
vertical: 24.0,
horizontal: 12.0
),
child: new Text(output, style: new TextStyle(
fontSize: 48.0,
fontWeight: FontWeight.bold,

))),
alignment: Alignment.centerRight,
padding:
new EdgeInsets.symmetric(vertical: 24.0, horizontal: 12.0),
child: new Text(output,
style: new TextStyle(
fontSize: 48.0,
fontWeight: FontWeight.bold,
))),
new Expanded(
child: new Divider(),
),


new Column(children: [
new Row(children: [
buildButton("7"),
buildButton("8"),
buildButton("9"),
buildButton("/")
]),

new Row(children: [
buildButton("4"),
buildButton("5"),
buildButton("6"),
buildButton("X")
]),

new Row(children: [
buildButton("1"),
buildButton("2"),
buildButton("3"),
buildButton("-")
]),

new Row(children: [
buildButton("."),
buildButton("0"),
buildButton("00"),
buildButton("+")
]),

new Row(children: [
buildButton("CLEAR"),
buildButton("="),
Expand Down
1 change: 1 addition & 0 deletions linux/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flutter/ephemeral
139 changes: 139 additions & 0 deletions linux/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Project-level configuration.
cmake_minimum_required(VERSION 3.10)
project(runner LANGUAGES CXX)

# The name of the executable created for the application. Change this to change
# the on-disk name of your application.
set(BINARY_NAME "calculator_app")
# The unique GTK application identifier for this application. See:
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
set(APPLICATION_ID "com.example.calculator_app")

# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
# versions of CMake.
cmake_policy(SET CMP0063 NEW)

# Load bundled libraries from the lib/ directory relative to the binary.
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib")

# Root filesystem for cross-building.
if(FLUTTER_TARGET_PLATFORM_SYSROOT)
set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT})
set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
endif()

# Define build configuration options.
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Debug" CACHE
STRING "Flutter build mode" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Profile" "Release")
endif()

# Compilation settings that should be applied to most targets.
#
# Be cautious about adding new options here, as plugins use this function by
# default. In most cases, you should add new options to specific targets instead
# of modifying this function.
function(APPLY_STANDARD_SETTINGS TARGET)
target_compile_features(${TARGET} PUBLIC cxx_std_14)
target_compile_options(${TARGET} PRIVATE -Wall -Werror)
target_compile_options(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:-O3>")
target_compile_definitions(${TARGET} PRIVATE "$<$<NOT:$<CONFIG:Debug>>:NDEBUG>")
endfunction()

# Flutter library and tool build rules.
set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter")
add_subdirectory(${FLUTTER_MANAGED_DIR})

# System-level dependencies.
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)

add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")

# Define the application target. To change its name, change BINARY_NAME above,
# not the value here, or `flutter run` will no longer work.
#
# Any new source files that you add to the application should be added here.
add_executable(${BINARY_NAME}
"main.cc"
"my_application.cc"
"${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc"
)

# Apply the standard set of build settings. This can be removed for applications
# that need different build settings.
apply_standard_settings(${BINARY_NAME})

# Add dependency libraries. Add any application-specific dependencies here.
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)

# Run the Flutter tool portions of the build. This must not be removed.
add_dependencies(${BINARY_NAME} flutter_assemble)

# Only the install-generated bundle's copy of the executable will launch
# correctly, since the resources must in the right relative locations. To avoid
# people trying to run the unbundled copy, put it in a subdirectory instead of
# the default top-level location.
set_target_properties(${BINARY_NAME}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run"
)


# Generated plugin build rules, which manage building the plugins and adding
# them to the application.
include(flutter/generated_plugins.cmake)


# === Installation ===
# By default, "installing" just makes a relocatable bundle in the build
# directory.
set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle")
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
endif()

# Start with a clean build bundle directory every time.
install(CODE "
file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\")
" COMPONENT Runtime)

set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data")
set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")

install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}"
COMPONENT Runtime)

install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
COMPONENT Runtime)

install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)

foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES})
install(FILES "${bundled_library}"
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
endforeach(bundled_library)

# Fully re-copy the assets directory on each build to avoid having stale files
# from a previous install.
set(FLUTTER_ASSET_DIR_NAME "flutter_assets")
install(CODE "
file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\")
" COMPONENT Runtime)
install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}"
DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime)

# Install the AOT library on non-Debug builds only.
if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
endif()
Loading

0 comments on commit 4c0393f

Please sign in to comment.