Skip to content

Commit

Permalink
🟢 Add Windows platform
Browse files Browse the repository at this point in the history
  • Loading branch information
Keddnyo committed Sep 26, 2024
1 parent f16b49a commit a693d18
Show file tree
Hide file tree
Showing 24 changed files with 1,090 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ migration:
- platform: root
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
- platform: android
- platform: windows
create_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730
base_revision: 2663184aa79047d0a33a14a3b607954f8fdd8730

Expand Down
62 changes: 0 additions & 62 deletions lib/firebase_options.dart

This file was deleted.

14 changes: 3 additions & 11 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import 'package:firebase_core/firebase_core.dart';
import 'package:firedart/firedart.dart';
import 'package:flutter/material.dart';

import 'firebase_options.dart';
import 'src/app/application.dart';

void main() {
WidgetsFlutterBinding.ensureInitialized();

Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
).then(
(_) => runApp(
const Application(),
),
);
Firestore.initialize('anhuiwatch');
runApp(const Application());
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firedart/firedart.dart';

import '../entity/watch_face_entity.dart';

class WatchFaceEntityMapper {
static WatchFaceEntity toWatchFaceEntity(
DocumentSnapshot<Map<String, dynamic>> document,
) =>
static WatchFaceEntity toWatchFaceEntity(Document document) =>
WatchFaceEntity(
id: document.id,
title: document['title'],
imageUrl: document['imageUrl'],
fileUrl: document['fileUrl'],
);

static Map<String, dynamic> toFirestoreModel(
WatchFaceEntity watchface,
) =>
{
static Map<String, dynamic> toFirestoreModel(WatchFaceEntity watchface) => {
'title': watchface.title,
'imageUrl': watchface.imageUrl,
'fileUrl': watchface.fileUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firedart/firedart.dart';

import 'entity/watch_face_entity.dart';
import 'mapper/watch_face_entity_mapper.dart';

class WatchFaceDatabase {
WatchFaceDatabase(String deviceCode)
: _watchFacesCollection = FirebaseFirestore.instance
.collection('/wearables/$deviceCode/watch_faces')
.withConverter<WatchFaceEntity>(
fromFirestore: (snapshot, options) =>
WatchFaceEntityMapper.toWatchFaceEntity(snapshot),
toFirestore: (snapshot, options) =>
WatchFaceEntityMapper.toFirestoreModel(snapshot),
);
: watchFacesCollection = Firestore.instance.collection(
'/wearables/$deviceCode/watch_faces',
);

final CollectionReference<WatchFaceEntity> _watchFacesCollection;
final CollectionReference watchFacesCollection;

void cacheWatchFace(WatchFaceEntity watchFace) async {
final watchFaceDocument = _watchFacesCollection.doc(watchFace.title);
final watchFaceDocumentSnapshot = await watchFaceDocument.get();
final watchFaceData = watchFaceDocumentSnapshot.data();
final watchFaceDocument = watchFacesCollection.document(watchFace.title);
final isWatchFaceCached = await watchFaceDocument.exists;

if (watchFaceData == null) {
watchFaceDocument.set(watchFace);
if (isWatchFaceCached) {
watchFaceDocument.set(
WatchFaceEntityMapper.toFirestoreModel(watchFace),
);
}
}

Stream<List<WatchFaceEntity>> getWatchFaces() => _watchFacesCollection
.orderBy('title')
.snapshots()
.map((query) => query.docs.map((doc) => doc.data()).toList());
Stream<List<WatchFaceEntity>> getWatchFaces() =>
watchFacesCollection.stream.map(
(documents) => documents
.map(
(document) => WatchFaceEntityMapper.toWatchFaceEntity(document),
)
.toList(),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class WatchFaceCatalogScreen extends StatelessWidget {

return GridView.builder(
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: 384,
maxCrossAxisExtent: 256,
),
itemBuilder: (context, index) {
final watchFace = watchFaces[index];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firedart/firedart.dart';

import '../entity/wearable_entity.dart';

class WearableMapper {
static WearableEntity toWearableEntity(
DocumentSnapshot<Map<String, dynamic>> documentSnapshot,
) =>
WearableEntity(
id: documentSnapshot.id,
deviceName: documentSnapshot.data()?['deviceName'],
deviceCode: documentSnapshot.id,
static WearableEntity toWearableEntity(Document document) => WearableEntity(
id: document.id,
deviceName: document['deviceName'],
deviceCode: document.id,
);
}
17 changes: 11 additions & 6 deletions lib/src/features/wearables/data/firebase/wearable_firestore.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firedart/firedart.dart';

import 'entity/wearable_entity.dart';
import 'mapper/wearable_mapper.dart';

class WearableFirestore {
static Stream<List<WearableEntity>> get wearables => FirebaseFirestore
.instance
.collection('/wearables')
.snapshots()
.map((query) => query.docs.map(WearableMapper.toWearableEntity).toList());
static Stream<List<WearableEntity>> get wearables => Firestore.instance
.collection(
'/wearables',
)
.stream
.map(
(documents) => documents
.map((document) => WearableMapper.toWearableEntity(document))
.toList(),
);
}
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ environment:
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^5.4.2
http: ^1.2.2
firebase_core: ^3.5.0
url_launcher: ^6.3.0
firedart: ^0.9.8

dev_dependencies:
flutter_test:
Expand Down
17 changes: 17 additions & 0 deletions windows/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
flutter/ephemeral/

# Visual Studio user-specific files.
*.suo
*.user
*.userosscache
*.sln.docstates

# Visual Studio build-related files.
x64/
x86/

# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
108 changes: 108 additions & 0 deletions windows/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Project-level configuration.
cmake_minimum_required(VERSION 3.14)
project(anhuiwatch 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 "anhuiwatch")

# Explicitly opt in to modern CMake behaviors to avoid warnings with recent
# versions of CMake.
cmake_policy(VERSION 3.14...3.25)

# Define build configuration option.
get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(IS_MULTICONFIG)
set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release"
CACHE STRING "" FORCE)
else()
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()
endif()
# Define settings for the Profile build mode.
set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}")
set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}")

# Use Unicode for all projects.
add_definitions(-DUNICODE -D_UNICODE)

# 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_17)
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100")
target_compile_options(${TARGET} PRIVATE /EHsc)
target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0")
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:_DEBUG>")
endfunction()

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

# Application build; see runner/CMakeLists.txt.
add_subdirectory("runner")


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


# === Installation ===
# Support files are copied into place next to the executable, so that it can
# run in place. This is done instead of making a separate bundle (as on Linux)
# so that building and running from within Visual Studio will work.
set(BUILD_BUNDLE_DIR "$<TARGET_FILE_DIR:${BINARY_NAME}>")
# Make the "install" step default, as it's required to run.
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE)
endif()

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

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)

if(PLUGIN_BUNDLED_LIBRARIES)
install(FILES "${PLUGIN_BUNDLED_LIBRARIES}"
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
endif()

# Copy the native assets provided by the build.dart from all packages.
set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/")
install(DIRECTORY "${NATIVE_ASSETS_DIR}"
DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)

# 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.
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}"
CONFIGURATIONS Profile;Release
COMPONENT Runtime)
Loading

0 comments on commit a693d18

Please sign in to comment.