Calendar implementation

This commit is contained in:
2025-10-10 16:57:11 +02:00
parent ff0d6b7796
commit dc86955721
17 changed files with 1194 additions and 103 deletions
+5 -17
View File
@@ -4,7 +4,7 @@
# This file should be version controlled and should not be manually edited.
version:
revision: "c23637390482d4cf9598c3ce3f2be31aa7332daf"
revision: "ea121f8859e4b13e47a8f845e4586164519588bc"
channel: "stable"
project_type: app
@@ -13,23 +13,11 @@ project_type: app
migration:
platforms:
- platform: root
create_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
base_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
- platform: android
create_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
base_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
- platform: ios
create_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
base_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
create_revision: ea121f8859e4b13e47a8f845e4586164519588bc
base_revision: ea121f8859e4b13e47a8f845e4586164519588bc
- platform: linux
create_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
base_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
- platform: macos
create_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
base_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
- platform: web
create_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
base_revision: c23637390482d4cf9598c3ce3f2be31aa7332daf
create_revision: ea121f8859e4b13e47a8f845e4586164519588bc
base_revision: ea121f8859e4b13e47a8f845e4586164519588bc
# User provided section
+10 -6
View File
@@ -1,16 +1,20 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Flutter (lib\\main.dart)",
"type": "dart",
"name": "Flutter on Emulator",
"request": "launch",
"program": "lib\\main.dart"
"type": "dart",
"deviceId": "emulator-5554",
"flutterMode": "debug"
},
{
"name": "Flutter (lib\\main.dart)",
"type": "dart",
"name": "Flutter on Phone",
"request": "launch",
"program": "lib\\main.dart"
"type": "dart",
"deviceId": "56463f6d",
"flutterMode": "debug"
}
]
}
+3
View File
@@ -0,0 +1,3 @@
description: This file stores settings for Dart & Flutter DevTools.
documentation: https://docs.flutter.dev/tools/devtools/extensions#configure-extension-enablement-states
extensions:
+511 -31
View File
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
import 'package:intl/intl.dart';
import 'package:shared_preferences/shared_preferences.dart';
import '../services/google_calendar_service.dart';
class CalendarScreen extends StatefulWidget {
const CalendarScreen({super.key});
@@ -9,59 +11,537 @@ class CalendarScreen extends StatefulWidget {
}
class _CalendarScreenState extends State<CalendarScreen> {
late final WebViewController _controller;
bool _isLoading = true;
bool _hasError = false;
final GoogleCalendarService _calendarService = GoogleCalendarService();
bool _isLoading = false;
List<CalendarEvent> _events = [];
String? _errorMessage;
String _bulletColor = 'Blue';
@override
void initState() {
super.initState();
_controller = WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..setNavigationDelegate(
NavigationDelegate(
onPageStarted: (_) => setState(() {
_loadBulletColor();
_loadEvents();
}
@override
void dispose() {
_calendarService.dispose();
super.dispose();
}
Future<void> _loadBulletColor() async {
final prefs = await SharedPreferences.getInstance();
setState(() {
_bulletColor = prefs.getString('bulletColor') ?? 'Blue';
});
}
Color _getAccentColor() {
switch (_bulletColor.toLowerCase()) {
case 'blue':
return Colors.blue;
case 'green':
return Colors.green;
case 'yellow':
return Colors.yellow;
case 'purple':
return Colors.purple;
case 'cyan':
return Colors.cyan;
case 'teal':
return Colors.teal;
case 'indigo':
return Colors.indigo;
case 'pink':
return Colors.pink;
case 'lime':
return Colors.lime;
case 'mint':
return Colors.greenAccent;
case 'orange':
return Colors.orange;
case 'violet':
return Colors.deepPurpleAccent;
case 'amber':
return Colors.amber;
case 'brown':
return Colors.brown;
case 'grey':
return Colors.grey;
default:
return Colors.blue;
}
}
bool _isValidEvent(CalendarEvent event) {
// Filter out events that are just single names or too short
if (event.summary == null || event.summary!.trim().isEmpty) {
return false;
}
final summary = event.summary!.trim();
// Exclude if it's just a single word (likely just a name)
if (!summary.contains(' ') && summary.length < 15) {
return false;
}
return true;
}
Future<void> _loadEvents() async {
setState(() {
_isLoading = true;
_hasError = false;
}),
onPageFinished: (_) => setState(() => _isLoading = false),
onWebResourceError: (error) => setState(() {
_hasError = true;
_isLoading = false;
}),
),
)
..loadRequest(Uri.parse(
'https://calendar.google.com/calendar/u/0/embed?src=b9c267252d5be63d5cdc880be499885a88421eefd0e34e1392890daba0d8471e@group.calendar.google.com&ctz=Europe/Belgrade'));
_errorMessage = null;
});
try {
final events = await _calendarService.getEvents(
startDate: DateTime.now(),
endDate: DateTime.now().add(const Duration(days: 365)),
);
// Get today's date at midnight for comparison
final now = DateTime.now();
final today = DateTime(now.year, now.month, now.day);
// Filter: valid events AND events from today onwards
final filteredEvents = events.where((event) {
if (!_isValidEvent(event)) return false;
// Only include events that are today or in the future
if (event.startTime != null) {
final eventDate = DateTime(
event.startTime!.year,
event.startTime!.month,
event.startTime!.day,
);
return eventDate.isAtSameMomentAs(today) || eventDate.isAfter(today);
}
return false;
}).toList();
filteredEvents.sort((a, b) {
if (a.startTime == null) return 1;
if (b.startTime == null) return -1;
return a.startTime!.compareTo(b.startTime!);
});
setState(() {
_events = filteredEvents;
});
} catch (e) {
setState(() {
_errorMessage = 'Error loading events: $e';
});
} finally {
setState(() => _isLoading = false);
}
}
@override
Widget build(BuildContext context) {
final accentColor = _getAccentColor();
if (_isLoading && _events.isEmpty) {
return Scaffold(
body: Stack(
body: Center(
child: CircularProgressIndicator(color: accentColor),
),
);
}
if (_errorMessage != null && _events.isEmpty) {
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
WebViewWidget(controller: _controller),
if (_isLoading)
const Center(child: CircularProgressIndicator()),
if (_hasError)
Icon(Icons.error_outline, size: 64, color: accentColor),
const SizedBox(height: 24),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 32),
child: Text(
_errorMessage!,
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 16),
),
),
const SizedBox(height: 16),
ElevatedButton.icon(
onPressed: _loadEvents,
icon: const Icon(Icons.refresh),
label: const Text('Retry'),
style: ElevatedButton.styleFrom(
backgroundColor: accentColor,
foregroundColor: Colors.white,
),
),
],
),
),
);
}
return Scaffold(
backgroundColor: Colors.white,
body: RefreshIndicator(
onRefresh: _loadEvents,
color: accentColor,
child: _events.isEmpty
? ListView(
children: [
SizedBox(height: MediaQuery.of(context).size.height * 0.3),
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.event_available, size: 64, color: Colors.grey[400]),
const SizedBox(height: 16),
const Text(
"Failed to load Google Calendar.",
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
'No upcoming events',
style: TextStyle(fontSize: 16, color: Colors.grey),
),
const SizedBox(height: 10),
ElevatedButton(
onPressed: () => _controller.reload(),
child: const Text("Retry"),
const SizedBox(height: 8),
Text(
'Pull down to refresh',
style: TextStyle(fontSize: 14, color: Colors.grey[400]),
),
],
),
),
],
)
: ListView.builder(
itemCount: _events.length,
padding: const EdgeInsets.all(8),
itemBuilder: (context, index) {
final event = _events[index];
return _buildEventCard(event, accentColor);
},
),
),
);
}
Widget _buildEventCard(CalendarEvent event, Color accentColor) {
final startTime = event.startTime;
final isAllDay = event.isAllDay;
String timeText;
if (isAllDay) {
timeText = 'All day';
} else if (startTime != null) {
timeText = DateFormat('HH:mm').format(startTime.toLocal());
} else {
timeText = '';
}
// Format the date for display
String dateText = '';
bool isToday = false;
if (startTime != null) {
final now = DateTime.now();
final today = DateTime(now.year, now.month, now.day);
final eventDay = DateTime(startTime.year, startTime.month, startTime.day);
final difference = eventDay.difference(today).inDays;
if (difference == 0) {
dateText = 'Today';
isToday = true;
} else if (difference == 1) {
dateText = 'Tomorrow';
} else {
dateText = DateFormat('EEEE, MMMM d').format(startTime);
}
}
return Container(
margin: const EdgeInsets.symmetric(vertical: 6, horizontal: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: () => _showEventDetails(event, accentColor),
borderRadius: BorderRadius.circular(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Date header
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
color: isToday
? accentColor.withValues(alpha: 0.15)
: Colors.grey[50],
borderRadius: const BorderRadius.only(
topLeft: Radius.circular(12),
topRight: Radius.circular(12),
),
),
child: Row(
children: [
Container(
width: 4,
height: 16,
decoration: BoxDecoration(
color: accentColor,
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(width: 8),
Text(
dateText,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: isToday ? accentColor : Colors.black87,
),
),
if (isToday) ...[
const SizedBox(width: 8),
Container(
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
decoration: BoxDecoration(
color: accentColor,
borderRadius: BorderRadius.circular(8),
),
child: const Text(
'NOW',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
],
],
),
),
// Time and title
Padding(
padding: const EdgeInsets.all(16),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// Time indicator with accent color
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
color: accentColor.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(12),
),
child: Center(
child: Text(
timeText,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: isAllDay ? 12 : 14,
fontWeight: FontWeight.bold,
color: accentColor,
),
),
),
),
const SizedBox(width: 16),
// Title
Expanded(
child: Text(
event.summary ?? 'Untitled Event',
style: const TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: Colors.black87,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 8),
// Arrow icon
Icon(
Icons.arrow_forward_ios,
size: 16,
color: Colors.grey[400],
),
],
),
),
],
),
),
),
);
}
void _showEventDetails(CalendarEvent event, Color accentColor) {
final startTime = event.startTime;
final endTime = event.endTime;
final isAllDay = event.isAllDay;
showDialog(
context: context,
builder: (context) => Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
child: Container(
constraints: const BoxConstraints(maxWidth: 400),
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
width: 4,
height: 24,
decoration: BoxDecoration(
color: accentColor,
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(width: 12),
Expanded(
child: Text(
event.summary ?? 'Event Details',
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
),
),
],
),
const SizedBox(height: 24),
if (startTime != null) ...[
_buildDetailRow(
icon: Icons.calendar_today,
label: 'Date',
value: DateFormat('EEEE, MMMM d, y').format(startTime),
accentColor: accentColor,
),
const SizedBox(height: 16),
],
if (!isAllDay && startTime != null && endTime != null) ...[
_buildDetailRow(
icon: Icons.access_time,
label: 'Time',
value:
'${DateFormat('HH:mm').format(startTime.toLocal())} - ${DateFormat('HH:mm').format(endTime.toLocal())}',
accentColor: accentColor,
),
const SizedBox(height: 16),
],
if (isAllDay) ...[
_buildDetailRow(
icon: Icons.access_time,
label: 'Duration',
value: 'All day event',
accentColor: accentColor,
),
const SizedBox(height: 16),
],
if (event.location != null && event.location!.isNotEmpty) ...[
_buildDetailRow(
icon: Icons.location_on,
label: 'Location',
value: event.location!,
accentColor: accentColor,
),
const SizedBox(height: 16),
],
if (event.description != null && event.description!.isNotEmpty) ...[
_buildDetailRow(
icon: Icons.notes,
label: 'Notes',
value: event.description!,
accentColor: accentColor,
),
const SizedBox(height: 16),
],
const SizedBox(height: 8),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () => Navigator.pop(context),
style: ElevatedButton.styleFrom(
backgroundColor: accentColor,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: const Text(
'Close',
style: TextStyle(fontWeight: FontWeight.w600),
),
),
),
],
),
),
),
);
}
Widget _buildDetailRow({
required IconData icon,
required String label,
required String value,
required Color accentColor,
}) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: accentColor.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
),
child: Icon(icon, size: 20, color: accentColor),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w600,
color: Colors.grey[600],
),
),
const SizedBox(height: 4),
Text(
value,
style: const TextStyle(
fontSize: 14,
color: Colors.black87,
),
),
],
),
),
],
);
}
}
+154
View File
@@ -0,0 +1,154 @@
import 'package:http/http.dart' as http;
class CalendarEvent {
final String? summary;
final String? description;
final String? location;
final DateTime? startTime;
final DateTime? endTime;
final bool isAllDay;
CalendarEvent({
this.summary,
this.description,
this.location,
this.startTime,
this.endTime,
this.isAllDay = false,
});
}
class GoogleCalendarService {
static const String calendarId =
'b9c267252d5be63d5cdc880be499885a88421eefd0e34e1392890daba0d8471e@group.calendar.google.com';
final http.Client _httpClient = http.Client();
Future<List<CalendarEvent>> getEvents({
DateTime? startDate,
DateTime? endDate,
}) async {
try {
// Use the public iCal feed URL
final url = Uri.parse(
'https://calendar.google.com/calendar/ical/$calendarId/public/basic.ics');
final response = await _httpClient.get(url);
if (response.statusCode == 200) {
return _parseICalendar(response.body);
} else {
throw Exception('Failed to load calendar: ${response.statusCode}');
}
} catch (e) {
throw Exception('Error fetching events: $e');
}
}
List<CalendarEvent> _parseICalendar(String icalData) {
final events = <CalendarEvent>[];
final lines = icalData.split('\n');
String? summary;
String? description;
String? location;
DateTime? startTime;
DateTime? endTime;
bool isAllDay = false;
for (var i = 0; i < lines.length; i++) {
var line = lines[i].trim();
// Handle line continuations
while (i + 1 < lines.length && lines[i + 1].startsWith(' ')) {
i++;
line += lines[i].trim();
}
if (line.startsWith('BEGIN:VEVENT')) {
summary = null;
description = null;
location = null;
startTime = null;
endTime = null;
isAllDay = false;
} else if (line.startsWith('SUMMARY:')) {
summary = _unescapeText(line.substring(8));
} else if (line.startsWith('DESCRIPTION:')) {
description = _unescapeText(line.substring(12));
} else if (line.startsWith('LOCATION:')) {
location = _unescapeText(line.substring(9));
} else if (line.startsWith('DTSTART')) {
final dateStr = line.split(':')[1];
if (line.contains('VALUE=DATE')) {
isAllDay = true;
startTime = _parseDate(dateStr);
} else {
startTime = _parseDateTime(dateStr);
}
} else if (line.startsWith('DTEND')) {
final dateStr = line.split(':')[1];
if (line.contains('VALUE=DATE')) {
endTime = _parseDate(dateStr);
} else {
endTime = _parseDateTime(dateStr);
}
} else if (line.startsWith('END:VEVENT')) {
events.add(CalendarEvent(
summary: summary,
description: description,
location: location,
startTime: startTime,
endTime: endTime,
isAllDay: isAllDay,
));
}
}
return events;
}
String _unescapeText(String text) {
return text
.replaceAll('\\n', '\n')
.replaceAll('\\,', ',')
.replaceAll('\\;', ';')
.replaceAll('\\\\', '\\');
}
DateTime? _parseDate(String dateStr) {
try {
// Format: YYYYMMDD
final year = int.parse(dateStr.substring(0, 4));
final month = int.parse(dateStr.substring(4, 6));
final day = int.parse(dateStr.substring(6, 8));
return DateTime(year, month, day);
} catch (e) {
return null;
}
}
DateTime? _parseDateTime(String dateStr) {
try {
// Format: YYYYMMDDTHHMMSSZ or YYYYMMDDTHHMMSS
final year = int.parse(dateStr.substring(0, 4));
final month = int.parse(dateStr.substring(4, 6));
final day = int.parse(dateStr.substring(6, 8));
final hour = int.parse(dateStr.substring(9, 11));
final minute = int.parse(dateStr.substring(11, 13));
final second = int.parse(dateStr.substring(13, 15));
if (dateStr.endsWith('Z')) {
return DateTime.utc(year, month, day, hour, minute, second);
} else {
return DateTime(year, month, day, hour, minute, second);
}
} catch (e) {
return null;
}
}
void dispose() {
_httpClient.close();
}
}
+1
View File
@@ -0,0 +1 @@
flutter/ephemeral
+128
View File
@@ -0,0 +1,128 @@
# Project-level configuration.
cmake_minimum_required(VERSION 3.13)
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 "test1")
# The unique GTK application identifier for this application. See:
# https://wiki.gnome.org/HowDoI/ChooseApplicationID
set(APPLICATION_ID "com.example.test1")
# 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)
# Application build; see runner/CMakeLists.txt.
add_subdirectory("runner")
# 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)
# Copy the native assets provided by the build.dart from all packages.
set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/")
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.
if(NOT CMAKE_BUILD_TYPE MATCHES "Debug")
install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}"
COMPONENT Runtime)
endif()
+88
View File
@@ -0,0 +1,88 @@
# This file controls Flutter-level build steps. It should not be edited.
cmake_minimum_required(VERSION 3.10)
set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral")
# Configuration provided via flutter tool.
include(${EPHEMERAL_DIR}/generated_config.cmake)
# TODO: Move the rest of this into files in ephemeral. See
# https://github.com/flutter/flutter/issues/57146.
# Serves the same purpose as list(TRANSFORM ... PREPEND ...),
# which isn't available in 3.10.
function(list_prepend LIST_NAME PREFIX)
set(NEW_LIST "")
foreach(element ${${LIST_NAME}})
list(APPEND NEW_LIST "${PREFIX}${element}")
endforeach(element)
set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE)
endfunction()
# === Flutter Library ===
# System-level dependencies.
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0)
pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0)
pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0)
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so")
# Published to parent scope for install step.
set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE)
set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE)
set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE)
set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE)
list(APPEND FLUTTER_LIBRARY_HEADERS
"fl_basic_message_channel.h"
"fl_binary_codec.h"
"fl_binary_messenger.h"
"fl_dart_project.h"
"fl_engine.h"
"fl_json_message_codec.h"
"fl_json_method_codec.h"
"fl_message_codec.h"
"fl_method_call.h"
"fl_method_channel.h"
"fl_method_codec.h"
"fl_method_response.h"
"fl_plugin_registrar.h"
"fl_plugin_registry.h"
"fl_standard_message_codec.h"
"fl_standard_method_codec.h"
"fl_string_codec.h"
"fl_value.h"
"fl_view.h"
"flutter_linux.h"
)
list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/")
add_library(flutter INTERFACE)
target_include_directories(flutter INTERFACE
"${EPHEMERAL_DIR}"
)
target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}")
target_link_libraries(flutter INTERFACE
PkgConfig::GTK
PkgConfig::GLIB
PkgConfig::GIO
)
add_dependencies(flutter flutter_assemble)
# === Flutter tool backend ===
# _phony_ is a non-existent file to force this command to run every time,
# since currently there's no way to get a full input/output list from the
# flutter tool.
add_custom_command(
OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS}
${CMAKE_CURRENT_BINARY_DIR}/_phony_
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh"
${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE}
VERBATIM
)
add_custom_target(flutter_assemble DEPENDS
"${FLUTTER_LIBRARY}"
${FLUTTER_LIBRARY_HEADERS}
)
@@ -0,0 +1,15 @@
//
// Generated file. Do not edit.
//
// clang-format off
#include "generated_plugin_registrant.h"
#include <file_selector_linux/file_selector_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
}
@@ -0,0 +1,15 @@
//
// Generated file. Do not edit.
//
// clang-format off
#ifndef GENERATED_PLUGIN_REGISTRANT_
#define GENERATED_PLUGIN_REGISTRANT_
#include <flutter_linux/flutter_linux.h>
// Registers Flutter plugins.
void fl_register_plugins(FlPluginRegistry* registry);
#endif // GENERATED_PLUGIN_REGISTRANT_
+25
View File
@@ -0,0 +1,25 @@
#
# Generated file, do not edit.
#
list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST
tflite_flutter
)
set(PLUGIN_BUNDLED_LIBRARIES)
foreach(plugin ${FLUTTER_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin})
target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin)
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)
foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)
+26
View File
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.13)
project(runner LANGUAGES CXX)
# Define the application target. To change its name, change BINARY_NAME in the
# top-level CMakeLists.txt, 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 preprocessor definitions for the application ID.
add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}")
# Add dependency libraries. Add any application-specific dependencies here.
target_link_libraries(${BINARY_NAME} PRIVATE flutter)
target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK)
target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
+6
View File
@@ -0,0 +1,6 @@
#include "my_application.h"
int main(int argc, char** argv) {
g_autoptr(MyApplication) app = my_application_new();
return g_application_run(G_APPLICATION(app), argc, argv);
}
+130
View File
@@ -0,0 +1,130 @@
#include "my_application.h"
#include <flutter_linux/flutter_linux.h>
#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#endif
#include "flutter/generated_plugin_registrant.h"
struct _MyApplication {
GtkApplication parent_instance;
char** dart_entrypoint_arguments;
};
G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION)
// Implements GApplication::activate.
static void my_application_activate(GApplication* application) {
MyApplication* self = MY_APPLICATION(application);
GtkWindow* window =
GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application)));
// Use a header bar when running in GNOME as this is the common style used
// by applications and is the setup most users will be using (e.g. Ubuntu
// desktop).
// If running on X and not using GNOME then just use a traditional title bar
// in case the window manager does more exotic layout, e.g. tiling.
// If running on Wayland assume the header bar will work (may need changing
// if future cases occur).
gboolean use_header_bar = TRUE;
#ifdef GDK_WINDOWING_X11
GdkScreen* screen = gtk_window_get_screen(window);
if (GDK_IS_X11_SCREEN(screen)) {
const gchar* wm_name = gdk_x11_screen_get_window_manager_name(screen);
if (g_strcmp0(wm_name, "GNOME Shell") != 0) {
use_header_bar = FALSE;
}
}
#endif
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, "test1");
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, "test1");
}
gtk_window_set_default_size(window, 1280, 720);
gtk_widget_show(GTK_WIDGET(window));
g_autoptr(FlDartProject) project = fl_dart_project_new();
fl_dart_project_set_dart_entrypoint_arguments(project, self->dart_entrypoint_arguments);
FlView* view = fl_view_new(project);
gtk_widget_show(GTK_WIDGET(view));
gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view));
fl_register_plugins(FL_PLUGIN_REGISTRY(view));
gtk_widget_grab_focus(GTK_WIDGET(view));
}
// Implements GApplication::local_command_line.
static gboolean my_application_local_command_line(GApplication* application, gchar*** arguments, int* exit_status) {
MyApplication* self = MY_APPLICATION(application);
// Strip out the first argument as it is the binary name.
self->dart_entrypoint_arguments = g_strdupv(*arguments + 1);
g_autoptr(GError) error = nullptr;
if (!g_application_register(application, nullptr, &error)) {
g_warning("Failed to register: %s", error->message);
*exit_status = 1;
return TRUE;
}
g_application_activate(application);
*exit_status = 0;
return TRUE;
}
// Implements GApplication::startup.
static void my_application_startup(GApplication* application) {
//MyApplication* self = MY_APPLICATION(object);
// Perform any actions required at application startup.
G_APPLICATION_CLASS(my_application_parent_class)->startup(application);
}
// Implements GApplication::shutdown.
static void my_application_shutdown(GApplication* application) {
//MyApplication* self = MY_APPLICATION(object);
// Perform any actions required at application shutdown.
G_APPLICATION_CLASS(my_application_parent_class)->shutdown(application);
}
// Implements GObject::dispose.
static void my_application_dispose(GObject* object) {
MyApplication* self = MY_APPLICATION(object);
g_clear_pointer(&self->dart_entrypoint_arguments, g_strfreev);
G_OBJECT_CLASS(my_application_parent_class)->dispose(object);
}
static void my_application_class_init(MyApplicationClass* klass) {
G_APPLICATION_CLASS(klass)->activate = my_application_activate;
G_APPLICATION_CLASS(klass)->local_command_line = my_application_local_command_line;
G_APPLICATION_CLASS(klass)->startup = my_application_startup;
G_APPLICATION_CLASS(klass)->shutdown = my_application_shutdown;
G_OBJECT_CLASS(klass)->dispose = my_application_dispose;
}
static void my_application_init(MyApplication* self) {}
MyApplication* my_application_new() {
// Set the program name to the application ID, which helps various systems
// like GTK and desktop environments map this running application to its
// corresponding .desktop file. This ensures better integration by allowing
// the application to be recognized beyond its binary name.
g_set_prgname(APPLICATION_ID);
return MY_APPLICATION(g_object_new(my_application_get_type(),
"application-id", APPLICATION_ID,
"flags", G_APPLICATION_NON_UNIQUE,
nullptr));
}
+18
View File
@@ -0,0 +1,18 @@
#ifndef FLUTTER_MY_APPLICATION_H_
#define FLUTTER_MY_APPLICATION_H_
#include <gtk/gtk.h>
G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION,
GtkApplication)
/**
* my_application_new:
*
* Creates a new Flutter-based application.
*
* Returns: a new #MyApplication.
*/
MyApplication* my_application_new();
#endif // FLUTTER_MY_APPLICATION_H_
+39 -31
View File
@@ -1,6 +1,14 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
_discoveryapis_commons:
dependency: transitive
description:
name: _discoveryapis_commons
sha256: "113c4100b90a5b70a983541782431b82168b3cae166ab130649c36eb3559d498"
url: "https://pub.dev"
source: hosted
version: "1.0.7"
archive:
dependency: transitive
description:
@@ -320,6 +328,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.12.4+4"
googleapis:
dependency: "direct main"
description:
name: googleapis
sha256: "864f222aed3f2ff00b816c675edf00a39e2aaf373d728d8abec30b37bee1a81c"
url: "https://pub.dev"
source: hosted
version: "13.2.0"
googleapis_auth:
dependency: "direct main"
description:
name: googleapis_auth
sha256: befd71383a955535060acde8792e7efc11d2fccd03dd1d3ec434e85b68775938
url: "https://pub.dev"
source: hosted
version: "1.6.0"
http:
dependency: "direct overridden"
description:
@@ -680,6 +704,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.4.1"
simple_gesture_detector:
dependency: transitive
description:
name: simple_gesture_detector
sha256: ba2cd5af24ff20a0b8d609cec3f40e5b0744d2a71804a2616ae086b9c19d19a3
url: "https://pub.dev"
source: hosted
version: "0.2.1"
sky_engine:
dependency: transitive
description: flutter
@@ -725,30 +757,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.4.1"
syncfusion_flutter_calendar:
dependency: "direct overridden"
table_calendar:
dependency: "direct main"
description:
name: syncfusion_flutter_calendar
sha256: "87761c6e73997d8d39181741f9e6244daf29b521aafaccf46b1bf31e86767a3f"
name: table_calendar
sha256: "0c0c6219878b363a2d5f40c7afb159d845f253d061dc3c822aa0d5fe0f721982"
url: "https://pub.dev"
source: hosted
version: "28.2.12"
syncfusion_flutter_core:
dependency: transitive
description:
name: syncfusion_flutter_core
sha256: f1d2b52697543e13bdefdc62d15868124a265987577f53224a7dbe176c8448f0
url: "https://pub.dev"
source: hosted
version: "28.2.12"
syncfusion_flutter_datepicker:
dependency: transitive
description:
name: syncfusion_flutter_datepicker
sha256: cfc91ebacee63b2c5220e541736f8df211d4f0bfbf34265778862ae20faf094f
url: "https://pub.dev"
source: hosted
version: "28.2.12"
version: "3.2.0"
term_glyph:
dependency: transitive
description:
@@ -769,18 +785,10 @@ packages:
dependency: "direct main"
description:
name: tflite_flutter
sha256: ffb8651fdb116ab0131d6dc47ff73883e0f634ad1ab12bb2852eef1bbeab4a6a
sha256: "48e6fde2ad97162bb66a16a142f4c4698add9e8cd397ce9d1cc7451b55537ac1"
url: "https://pub.dev"
source: hosted
version: "0.10.4"
timezone:
dependency: transitive
description:
name: timezone
sha256: ffc9d5f4d1193534ef051f9254063fa53d588609418c84299956c3db9383587d
url: "https://pub.dev"
source: hosted
version: "0.10.0"
version: "0.11.0"
typed_data:
dependency: transitive
description:
+4 -2
View File
@@ -12,6 +12,8 @@ dependencies:
sdk: flutter
cupertino_icons: ^1.0.8
google_sign_in: ^6.1.5
googleapis: ^13.2.0
googleapis_auth: ^1.6.0
shared_preferences: ^2.2.2
photo_view: ^0.15.0
screenshot: ^3.0.0
@@ -24,8 +26,9 @@ dependencies:
flutter_launcher_icons: ^0.14.3
flutter_svg: ^2.0.9
collection: ^1.17.2
table_calendar: ^3.1.2
tflite_flutter: ^0.10.4
tflite_flutter: ^0.11.0
image: ^4.5.4
camera: ^0.10.0
path_provider: ^2.0.15
@@ -33,7 +36,6 @@ dependencies:
wakelock_plus: ^1.2.11
dependency_overrides:
syncfusion_flutter_calendar: ^28.2.9
http: ^0.13.6