Skip to content

Commit

Permalink
wip: flutter web
Browse files Browse the repository at this point in the history
  • Loading branch information
kekland committed Mar 4, 2021
1 parent 56a0d1b commit bca3a49
Show file tree
Hide file tree
Showing 22 changed files with 304 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"geolocator","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator-6.1.6/","dependencies":[]},{"name":"shared_preferences","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.12+4/","dependencies":[]}],"android":[{"name":"geolocator","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator-6.1.6/","dependencies":[]},{"name":"shared_preferences","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.12+4/","dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+11/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+2/","dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-0.0.2+4/","dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-0.0.4+3/","dependencies":[]},{"name":"shared_preferences_windows","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_windows-0.0.1+3/","dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+7/","dependencies":[]}]},"dependencyGraph":[{"name":"geolocator","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2020-11-29 12:54:29.441319","version":"1.22.0"}
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"geolocator","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator-6.1.6/","dependencies":[]},{"name":"shared_preferences","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.12+4/","dependencies":[]}],"android":[{"name":"geolocator","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/geolocator-6.1.6/","dependencies":[]},{"name":"shared_preferences","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.12+4/","dependencies":[]}],"macos":[{"name":"shared_preferences_macos","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+11/","dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_linux-0.0.1+2/","dependencies":[]},{"name":"shared_preferences_linux","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_linux-0.0.2+4/","dependencies":["path_provider_linux"]}],"windows":[{"name":"path_provider_windows","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_windows-0.0.4+3/","dependencies":[]},{"name":"shared_preferences_windows","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_windows-0.0.1+3/","dependencies":["path_provider_windows"]}],"web":[{"name":"shared_preferences_web","path":"/Users/kekland/sdk/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+7/","dependencies":[]}]},"dependencyGraph":[{"name":"geolocator","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_linux","shared_preferences_macos","shared_preferences_web","shared_preferences_windows"]},{"name":"shared_preferences_linux","dependencies":["path_provider_linux"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"shared_preferences_windows","dependencies":["path_provider_windows"]}],"date_created":"2021-03-04 10:23:20.355440","version":"2.0.0"}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.kekland.almetro_app

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}
12 changes: 12 additions & 0 deletions android/app/src/main/res/drawable-v21/launch_background.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Modify this file to customize your launch splash screen -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="?android:colorBackground" />

<!-- You can insert your own image assets here -->
<!-- <item>
<bitmap
android:gravity="center"
android:src="@mipmap/launch_image" />
</item> -->
</layer-list>
18 changes: 18 additions & 0 deletions android/app/src/main/res/values-night/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
<!-- Show a splash screen on the activity. Automatically removed when
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- Theme applied to the Android Window as soon as the process has started.
This theme determines the color of the Android Window while your
Flutter UI initializes, as well as behind your Flutter UI while its
running.
This Theme is only used starting with V2 of Flutter's Android embedding. -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">?android:colorBackground</item>
</style>
</resources>
Binary file added assets/icon-raster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions assets/l10n/de.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"featureDiscoveryGpsDescription": "Tippen Sie, um mit GPS die nächstliegende Station zu finden",
"featureDiscoveryGpsTitle": "Nächstliegende Station",
"featureDiscoveryStationInfoDescription": "Hier können Sie die Zeit sehen, bevor die nächste Bahn ankommt",
"featureDiscoveryStationInfoTitle": "Bahnfahrplan",
"featureDiscoveryStationPickerDescription": "Tippen Sie, um alle Stationen anzuzeigen",
"featureDiscoveryStationPickerTitle": "Wählen Sie eine Station",
"labelAppVersion": "Almetro Version",
"labelAutoupdate": "Automatisch aktualisieren",
"labelChangeBrightness": "Thema wechseln",
"labelChangeSettings": "Sie können den Fahrplan in Einstellungen wechseln",
"labelDateTimeIn": "in",
"labelDateTimeNow": "jetzt",
"labelLastCacheRefresh": "Wurde aktualisiert",
"labelLoadingError": "Ein Fehler ist aufgetreten",
"labelLoadingErrorTooltip": "Wenn Sie die App zum ersten Mal benutzen, prüfen Sie bitte Ihre Internetverbindung über",
"labelRefreshCache": "Cache aktualisieren",
"labelShortHour": "St.",
"labelShortMinute": "Min.",
"labelShortSecond": "Sek.",
"labelShowHolidaySchedule": "Wochenendefahrplan anzeigen",
"labelShowingHolidaySchedule": "Wochenendefahrplan wird angezeigt",
"labelStation": "Station",
"labelToday": "Heute",
"labelToStation": "Zu Station",
"labelTryAgain": "Versuchen Sie nochmal",
"snackbarCacheRefreshResultFailure": "Fehler beim Aktualisieren des Fahrplans",
"snackbarCacheRefreshResultSuccess": "Der Fahrplan wurde erfolgreich aktualisiert",
"snackbarGpsResultSuccess": "Die nächstliegende Station wird gewählt"
}
96 changes: 96 additions & 0 deletions lib/api/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,102 @@ abstract class Api {
}

class AlmetroApi implements Api {
@override
Future<Map<String, dynamic>> downloadSubwayData() async {
final response = await http.get('http://209.182.216.197:5134/data/');
return jsonDecode(response.body);
}

Time _parseTime(String line) {
final data = line.split(':');
return Time(
hour: int.parse(data[0]),
minute: int.parse(data[1]),
second: int.parse(data[2]),
);
}

SubwayData _getSubwayDataFromResponse(
Map<String, dynamic> response,
ScheduleType type,
) {
final scheduleData = response['schedules']
[type == ScheduleType.normal ? 'normal' : 'holiday'];

final stations = response['stations']
.map(
(v) => SubwayStation(
id: int.parse(v['id']),
order: v['order'],
latitude: v['position']['latitude'],
longitude: v['position']['longitude'],
name: SubwayStationName(
en: v['name']['name_en'],
ru: v['name']['name_ru'],
kk: v['name']['name_kz'],
),
connections: {},
schedule: {},
),
)
.cast<SubwayStation>()
.toList();

for (final station in stations) {
for (final connection in scheduleData[station.id.toString()]) {
if (connection['to'].isEmpty) continue;

final to = int.parse(connection['to']);
final schedule = (connection['schedule'])
.cast<String>()
.map(_parseTime)
.cast<Time>()
.toList();
station.populateSchedule(stationId: to, schedule: schedule);
}
}

final line = SubwayLine(
id: 0,
stations: stations,
segments: [],
);

line.stations.sort((a, b) => b.order - a.order);

return SubwayData(
lines: [line],
lineConnections: {},
);
}

@override
Subway getSubwayFromResponse(Map<String, dynamic> response) {
return Subway(
holidays: response['holidays']
.map(
(holiday) => Tuple2(
DateTime.parse(holiday['date']),
holiday['name'] as String,
),
)
.cast<Tuple2<DateTime, String>>()
.toList(),
schedules: {
ScheduleType.normal: _getSubwayDataFromResponse(
response,
ScheduleType.normal,
),
ScheduleType.holiday: _getSubwayDataFromResponse(
response,
ScheduleType.holiday,
),
},
);
}
}

class MetroWithArtsApi implements Api {
Future<Map<String, dynamic>> downloadSubwayData() async {
final response = await http.get(
'http://metro.witharts.kz/metro/api/0/all',
Expand Down
2 changes: 2 additions & 0 deletions lib/api/model/station.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class SubwayStationName {
return kk;
case 'en':
return en;
case 'de':
return en;
default:
return resolveFromLocale(fallbackLocale);
}
Expand Down
15 changes: 15 additions & 0 deletions lib/generated_plugin_registrant.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Generated file. Do not edit.
//

// ignore_for_file: lines_longer_than_80_chars

import 'package:shared_preferences_web/shared_preferences_web.dart';

import 'package:flutter_web_plugins/flutter_web_plugins.dart';

// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
SharedPreferencesPlugin.registerWith(registrar);
registrar.registerMessageHandler();
}
5 changes: 2 additions & 3 deletions lib/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:almaty_metro/api/api.dart';
import 'package:almaty_metro/l10n/localization.dart';
import 'package:almaty_metro/utils/snackbar.dart';
import 'package:almaty_metro/widgets/app_logo.dart';
import 'package:almaty_metro/widgets/feature_discovery/feature.dart';
import 'package:almaty_metro/widgets/feature_discovery/feature_discovery_manager.dart';
import 'package:almaty_metro/widgets/holiday_card.dart';
Expand All @@ -11,7 +12,6 @@ import 'package:almaty_metro/widgets/station_info.dart';
import 'package:almaty_metro/widgets/station_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart';

class HomePage extends StatefulWidget {
Expand Down Expand Up @@ -66,8 +66,7 @@ class _HomePageBody extends StatelessWidget {
alignment: Alignment.center,
child: Hero(
tag: 'app_logo',
child: SvgPicture.asset(
'assets/icon.svg',
child: AppLogo(
height: 24.0,
),
),
Expand Down
1 change: 1 addition & 0 deletions lib/l10n/delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class AlmetroLocalizationsDelegate
Locale('ru'),
Locale('en'),
Locale('kk'),
Locale('de'),
];

@override
Expand Down
5 changes: 2 additions & 3 deletions lib/loading_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:almaty_metro/home_page.dart';
import 'package:almaty_metro/l10n/localization.dart';
import 'package:almaty_metro/model/app_model.dart';
import 'package:almaty_metro/widgets/app_logo.dart';
import 'package:almaty_metro/widgets/transitions/circular_reveal_page_route.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:provider/provider.dart';

class LoadingPage extends StatefulWidget {
Expand Down Expand Up @@ -61,8 +61,7 @@ class _LoadingPageState extends State<LoadingPage> {
),
Hero(
tag: 'app_logo',
child: SvgPicture.asset(
'assets/icon.svg',
child: AppLogo(
height: 80.0,
),
),
Expand Down
1 change: 1 addition & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class MyApp extends StatelessWidget {
if (list.contains(locale)) return locale;
return Locale('ru');
},
locale: Locale('ru'),
theme: ThemeData(
primaryColor: accentRed,
accentColor: accentRed,
Expand Down
1 change: 1 addition & 0 deletions lib/model/app_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class AppModel extends ChangeNotifier {

Future<void> loadFromCache([bool notify = true]) async {
final cache = settings.cachedData;

if (cache == null) {
return;
}
Expand Down
17 changes: 17 additions & 0 deletions lib/widgets/app_logo.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:flutter/widgets.dart';

class AppLogo extends StatelessWidget {
final double height;

const AppLogo({
Key key,
@required this.height,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Image.asset(
'assets/icon-raster.png',
height: 24.0,
);
}
}
Loading

0 comments on commit bca3a49

Please sign in to comment.