Kenneth Bruen
5 years ago
30 changed files with 4539 additions and 301 deletions
@ -0,0 +1,12 @@ |
|||||||
|
v2.0.2 |
||||||
|
- added translucency to the navigation bar on iOS |
||||||
|
|
||||||
|
v2.0.1 |
||||||
|
- added a little separation between the arrows and the text in the stations list |
||||||
|
- fine tuned the positioning, centering items when they are supposed to be centered |
||||||
|
- changed text from "sosește" to "sosire", in order to match "plecare" |
||||||
|
|
||||||
|
v2.0.0 |
||||||
|
Rewritten! |
||||||
|
- separate UI for Android and iOS |
||||||
|
- uses WebView to get data on device instead of relying on server |
@ -0,0 +1 @@ |
|||||||
|
{"short_name":"ATC","operator":"Astra Trans Carpatic","data_export":"20171212","valabil":{"de_la":"20171210","pana_la":"20181208"},"versiune":"1","trenuri":[{"rang":"IR","numar":"15510","numar_intern":15510},{"rang":"IR","numar":"15511","numar_intern":15511},{"rang":"IR","numar":"15512","numar_intern":15512},{"rang":"IR","numar":"15513*","numar_intern":15513},{"rang":"IR","numar":"15513","numar_intern":15513},{"rang":"IR","numar":"15514","numar_intern":15514},{"rang":"IR","numar":"15514","numar_intern":15514},{"rang":"IR","numar":"15516","numar_intern":15516},{"rang":"IR","numar":"15520","numar_intern":15520},{"rang":"IR","numar":"15521*","numar_intern":15521},{"rang":"IR","numar":"15521","numar_intern":15521},{"rang":"IR","numar":"15522","numar_intern":15522},{"rang":"IR","numar":"15522","numar_intern":15522},{"rang":"IR","numar":"15523","numar_intern":15523},{"rang":"IR","numar":"15523","numar_intern":15523},{"rang":"IR","numar":"15527","numar_intern":15527},{"rang":"IR","numar":"15528","numar_intern":15528},{"rang":"IR","numar":"15529","numar_intern":15529},{"rang":"IR","numar":"15531","numar_intern":15531},{"rang":"IR","numar":"15532","numar_intern":15532},{"rang":"IR","numar":"15533","numar_intern":15533},{"rang":"IR","numar":"15533e","numar_intern":15533},{"rang":"IR","numar":"15534","numar_intern":15534},{"rang":"IR","numar":"15535","numar_intern":15535},{"rang":"IR","numar":"15536","numar_intern":15536},{"rang":"IR","numar":"15537-2","numar_intern":15537},{"rang":"IR","numar":"15538","numar_intern":15538},{"rang":"IR","numar":"15540","numar_intern":15540},{"rang":"IR","numar":"15541","numar_intern":15541},{"rang":"IR","numar":"15541","numar_intern":15541},{"rang":"IR","numar":"15542","numar_intern":15542},{"rang":"IR","numar":"15542","numar_intern":15542},{"rang":"IR","numar":"15543","numar_intern":15543},{"rang":"IR","numar":"15544","numar_intern":15544},{"rang":"IR","numar":"15545","numar_intern":15545},{"rang":"IR","numar":"15546*","numar_intern":15546},{"rang":"IR","numar":"15546","numar_intern":15546},{"rang":"IR","numar":"15547","numar_intern":15547},{"rang":"IR","numar":"15548","numar_intern":15548},{"rang":"IR","numar":"15549*","numar_intern":15549},{"rang":"IR","numar":"15549b","numar_intern":15549},{"rang":"IR","numar":"15551","numar_intern":15551},{"rang":"IR","numar":"15552","numar_intern":15552},{"rang":"IR","numar":"15553","numar_intern":15553},{"rang":"IR","numar":"15581","numar_intern":15581},{"rang":"IR","numar":"15582","numar_intern":15582},{"rang":"IR","numar":"15582***","numar_intern":15582},{"rang":"IR","numar":"15583","numar_intern":15583},{"rang":"IR","numar":"15590","numar_intern":15590},{"rang":"IR","numar":"15591","numar_intern":15591},{"rang":"IR","numar":"15592","numar_intern":15592},{"rang":"IR","numar":"15593","numar_intern":15593},{"rang":"R","numar":"*P18801","numar_intern":null},{"rang":"IR","numar":"*15546","numar_intern":null},{"rang":"R","numar":"**P18801","numar_intern":null},{"rang":"IR","numar":"*15591","numar_intern":null},{"rang":"R","numar":"**P18800","numar_intern":null},{"rang":"IR","numar":"15593","numar_intern":15593},{"rang":"IR","numar":"15594","numar_intern":15594},{"rang":"IR","numar":"15595-2","numar_intern":15595},{"rang":"R","numar":"18800","numar_intern":18800},{"rang":"R","numar":"18801","numar_intern":18801},{"rang":"IR","numar":"18826","numar_intern":18826},{"rang":"IR","numar":"18851","numar_intern":18851},{"rang":"IR","numar":"18852","numar_intern":18852}]} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,6 @@ |
|||||||
|
atc.json |
||||||
|
cfr.json |
||||||
|
interregional.json |
||||||
|
rc.json |
||||||
|
st.json |
||||||
|
tfc.json |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1 @@ |
|||||||
|
{"short_name":"Softrans","operator":"Softrans S.R.L.","data_export":"20181212","valabil":{"de_la":"20181209","pana_la":"20191214"},"versiune":"1","trenuri":[{"rang":"IR","numar":"15931-2","numar_intern":15931},{"rang":"IR","numar":"15932","numar_intern":15932},{"rang":"IR","numar":"15933-2","numar_intern":15933},{"rang":"IR","numar":"15934","numar_intern":15934},{"rang":"IR","numar":"15935-2","numar_intern":15935},{"rang":"IR","numar":"15936","numar_intern":15936},{"rang":"IR","numar":"15982","numar_intern":15982},{"rang":"IR","numar":"15984","numar_intern":15984}]} |
File diff suppressed because one or more lines are too long
@ -1 +1,2 @@ |
|||||||
|
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" |
||||||
#include "Generated.xcconfig" |
#include "Generated.xcconfig" |
||||||
|
@ -1 +1,2 @@ |
|||||||
|
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" |
||||||
#include "Generated.xcconfig" |
#include "Generated.xcconfig" |
||||||
|
@ -0,0 +1,74 @@ |
|||||||
|
# Uncomment this line to define a global platform for your project |
||||||
|
# platform :ios, '9.0' |
||||||
|
|
||||||
|
# CocoaPods analytics sends network stats synchronously affecting flutter build latency. |
||||||
|
ENV['COCOAPODS_DISABLE_STATS'] = 'true' |
||||||
|
|
||||||
|
project 'Runner', { |
||||||
|
'Debug' => :debug, |
||||||
|
'Profile' => :release, |
||||||
|
'Release' => :release, |
||||||
|
} |
||||||
|
|
||||||
|
def parse_KV_file(file, separator='=') |
||||||
|
file_abs_path = File.expand_path(file) |
||||||
|
if !File.exists? file_abs_path |
||||||
|
return []; |
||||||
|
end |
||||||
|
pods_ary = [] |
||||||
|
skip_line_start_symbols = ["#", "/"] |
||||||
|
File.foreach(file_abs_path) { |line| |
||||||
|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ } |
||||||
|
plugin = line.split(pattern=separator) |
||||||
|
if plugin.length == 2 |
||||||
|
podname = plugin[0].strip() |
||||||
|
path = plugin[1].strip() |
||||||
|
podpath = File.expand_path("#{path}", file_abs_path) |
||||||
|
pods_ary.push({:name => podname, :path => podpath}); |
||||||
|
else |
||||||
|
puts "Invalid plugin specification: #{line}" |
||||||
|
end |
||||||
|
} |
||||||
|
return pods_ary |
||||||
|
end |
||||||
|
|
||||||
|
target 'Runner' do |
||||||
|
use_frameworks! |
||||||
|
|
||||||
|
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock |
||||||
|
# referring to absolute paths on developers' machines. |
||||||
|
system('rm -rf .symlinks') |
||||||
|
system('mkdir -p .symlinks/plugins') |
||||||
|
|
||||||
|
# Flutter Pods |
||||||
|
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig') |
||||||
|
if generated_xcode_build_settings.empty? |
||||||
|
puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first." |
||||||
|
end |
||||||
|
generated_xcode_build_settings.map { |p| |
||||||
|
if p[:name] == 'FLUTTER_FRAMEWORK_DIR' |
||||||
|
symlink = File.join('.symlinks', 'flutter') |
||||||
|
File.symlink(File.dirname(p[:path]), symlink) |
||||||
|
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path])) |
||||||
|
end |
||||||
|
} |
||||||
|
|
||||||
|
# Plugin Pods |
||||||
|
plugin_pods = parse_KV_file('../.flutter-plugins') |
||||||
|
plugin_pods.map { |p| |
||||||
|
symlink = File.join('.symlinks', 'plugins', p[:name]) |
||||||
|
File.symlink(p[:path], symlink) |
||||||
|
pod p[:name], :path => File.join(symlink, 'ios') |
||||||
|
} |
||||||
|
end |
||||||
|
|
||||||
|
# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system. |
||||||
|
install! 'cocoapods', :disable_input_output_paths => true |
||||||
|
|
||||||
|
post_install do |installer| |
||||||
|
installer.pods_project.targets.each do |target| |
||||||
|
target.build_configurations.each do |config| |
||||||
|
config.build_settings['ENABLE_BITCODE'] = 'NO' |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,22 @@ |
|||||||
|
PODS: |
||||||
|
- Flutter (1.0.0) |
||||||
|
- webview_flutter (0.0.1): |
||||||
|
- Flutter |
||||||
|
|
||||||
|
DEPENDENCIES: |
||||||
|
- Flutter (from `.symlinks/flutter/ios`) |
||||||
|
- webview_flutter (from `.symlinks/plugins/webview_flutter/ios`) |
||||||
|
|
||||||
|
EXTERNAL SOURCES: |
||||||
|
Flutter: |
||||||
|
:path: ".symlinks/flutter/ios" |
||||||
|
webview_flutter: |
||||||
|
:path: ".symlinks/plugins/webview_flutter/ios" |
||||||
|
|
||||||
|
SPEC CHECKSUMS: |
||||||
|
Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a |
||||||
|
webview_flutter: 1aa7604e6cdb451a9b7ed2c37d5454c0b440246b |
||||||
|
|
||||||
|
PODFILE CHECKSUM: b6a0a141693093b304368d08511b46cf3d1d0ac5 |
||||||
|
|
||||||
|
COCOAPODS: 1.6.1 |
@ -0,0 +1,23 @@ |
|||||||
|
|
||||||
|
import 'package:flutter/widgets.dart'; |
||||||
|
import 'package:webview_flutter/webview_flutter.dart'; |
||||||
|
|
||||||
|
class HiddenWebView extends StatelessWidget { |
||||||
|
final WebView webView; |
||||||
|
final Widget child; |
||||||
|
|
||||||
|
HiddenWebView({@required this.child, this.webView}); |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
return Stack( |
||||||
|
children: <Widget>[ |
||||||
|
Offstage( |
||||||
|
offstage: true, |
||||||
|
child: webView, |
||||||
|
), |
||||||
|
Positioned.fill(child: child) |
||||||
|
], |
||||||
|
); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,70 @@ |
|||||||
|
import 'dart:io' show Platform; |
||||||
|
|
||||||
|
import 'package:flutter/material.dart'; |
||||||
|
import 'package:flutter/cupertino.dart'; |
||||||
|
|
||||||
|
import 'package:info_tren/models/train_data.dart'; |
||||||
|
import 'package:info_tren/train_info_page/train_info_cupertino.dart'; |
||||||
|
import 'package:info_tren/train_info_page/train_info_material.dart'; |
||||||
|
|
||||||
|
mixin TrainInfoMixin { |
||||||
|
String title; |
||||||
|
bool showTrainData; |
||||||
|
TrainLookupResult lookupResult; |
||||||
|
bool requestedData; |
||||||
|
} |
||||||
|
|
||||||
|
class TrainInfo extends StatelessWidget { |
||||||
|
final int trainNumber; |
||||||
|
|
||||||
|
TrainInfo({@required this.trainNumber}); |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
return TrainDataWebViewAdapter( |
||||||
|
builder: (context) { |
||||||
|
if (Platform.isAndroid) { |
||||||
|
return TrainInfoMaterial(trainNumber: trainNumber,); |
||||||
|
} |
||||||
|
else if (Platform.isIOS) { |
||||||
|
return TrainInfoCupertino(trainNumber: trainNumber,); |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
}, |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
typedef FutureDisplayCallback<T>(BuildContext context, T data); |
||||||
|
|
||||||
|
class FutureDisplay<T> extends StatelessWidget { |
||||||
|
final Future<T> future; |
||||||
|
final FutureDisplayCallback<T> builder; |
||||||
|
|
||||||
|
FutureDisplay({Key key, @required this.future, @required this.builder}): super(key: key); |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
return FutureBuilder( |
||||||
|
future: future, |
||||||
|
builder: (context, snapshot) { |
||||||
|
if (snapshot.hasData) return builder(context, snapshot.data); |
||||||
|
if (snapshot.hasError) throw snapshot.error; |
||||||
|
if (snapshot.connectionState == ConnectionState.done) return Container(); |
||||||
|
|
||||||
|
Widget loadingWidget; |
||||||
|
if (Platform.isAndroid) { |
||||||
|
loadingWidget = CircularProgressIndicator(); |
||||||
|
} |
||||||
|
else if (Platform.isIOS) { |
||||||
|
loadingWidget = CupertinoActivityIndicator(); |
||||||
|
} |
||||||
|
|
||||||
|
return Center( |
||||||
|
child: loadingWidget, |
||||||
|
); |
||||||
|
}, |
||||||
|
); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,254 @@ |
|||||||
|
import 'package:flutter/material.dart'; |
||||||
|
import 'package:flutter/cupertino.dart'; |
||||||
|
import 'package:info_tren/train_info_page/train_info_constants.dart'; |
||||||
|
|
||||||
|
import 'dart:io' show Platform; |
||||||
|
|
||||||
|
class AnimatedBackground extends StatefulWidget { |
||||||
|
final Color initialColor; |
||||||
|
final Color backgroundColor; |
||||||
|
final Widget child; |
||||||
|
final Duration animationDuration; |
||||||
|
|
||||||
|
AnimatedBackground({Key key, @required this.initialColor, @required this.backgroundColor, Duration animationDuration, @required this.child}) |
||||||
|
: this.animationDuration = animationDuration ?? Duration(milliseconds: 250) |
||||||
|
, super(key: key); |
||||||
|
|
||||||
|
@override |
||||||
|
State<AnimatedBackground> createState() => _AnimatedBackgroundState(); |
||||||
|
} |
||||||
|
|
||||||
|
class _AnimatedBackgroundState extends State<AnimatedBackground> with SingleTickerProviderStateMixin { |
||||||
|
AnimationController controller; |
||||||
|
Animatable<Color> animation; |
||||||
|
|
||||||
|
@override |
||||||
|
void initState() { |
||||||
|
super.initState(); |
||||||
|
controller = AnimationController(vsync: this, duration: widget.animationDuration); |
||||||
|
controller.forward(); |
||||||
|
animation = ColorTween(begin: widget.initialColor, end: widget.backgroundColor); |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
void didUpdateWidget(AnimatedBackground oldWidget) { |
||||||
|
super.didUpdateWidget(oldWidget); |
||||||
|
|
||||||
|
if (oldWidget.backgroundColor != widget.backgroundColor) { |
||||||
|
controller = AnimationController( |
||||||
|
duration: widget.animationDuration, |
||||||
|
vsync: this |
||||||
|
); |
||||||
|
controller.forward(); |
||||||
|
|
||||||
|
animation = ColorTween( |
||||||
|
begin: oldWidget.backgroundColor, |
||||||
|
end: widget.backgroundColor |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
return AnimatedBuilder( |
||||||
|
animation: controller, |
||||||
|
child: widget.child, |
||||||
|
builder: (context, child) { |
||||||
|
return Container( |
||||||
|
decoration: BoxDecoration( |
||||||
|
color: animation.evaluate(controller), |
||||||
|
), |
||||||
|
child: child, |
||||||
|
); |
||||||
|
}, |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class ProgressReportDisplayEntry extends StatefulWidget { |
||||||
|
final bool completed; |
||||||
|
final String waitingText; |
||||||
|
final String completedText; |
||||||
|
String get text => completed ? completedText : waitingText; |
||||||
|
|
||||||
|
ProgressReportDisplayEntry({Key key, @required this.completed, @required this.waitingText, @required this.completedText}): super(key: key); |
||||||
|
|
||||||
|
@override |
||||||
|
State<ProgressReportDisplayEntry> createState() { |
||||||
|
if (Platform.isIOS) { |
||||||
|
return _ProgressReportDisplayEntryCupertinoState(); |
||||||
|
} |
||||||
|
else if (Platform.isAndroid) { |
||||||
|
return _ProgressReportDisplayEntryMaterialState(); |
||||||
|
} |
||||||
|
else return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class _ProgressReportDisplayEntryCupertinoState extends State<ProgressReportDisplayEntry> with SingleTickerProviderStateMixin { |
||||||
|
Animatable<Color> background; |
||||||
|
Animatable<Color> checkMark; |
||||||
|
AnimationController _controller; |
||||||
|
|
||||||
|
initAnimation() { |
||||||
|
background = ColorTween( |
||||||
|
begin: CupertinoTheme.of(context).scaffoldBackgroundColor, |
||||||
|
end: BACKGROUND_GREEN, |
||||||
|
); |
||||||
|
checkMark = ColorTween( |
||||||
|
begin: FOREGROUND_WHITE, |
||||||
|
end: FOREGROUND_GREEN, |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
void initState() { |
||||||
|
super.initState(); |
||||||
|
|
||||||
|
_controller = AnimationController( |
||||||
|
duration: const Duration(milliseconds: 250), |
||||||
|
vsync: this, |
||||||
|
); |
||||||
|
_controller.value = widget.completed ? 1 : 0; |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
void didChangeDependencies() { |
||||||
|
super.didChangeDependencies(); |
||||||
|
initAnimation(); |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
void didUpdateWidget(ProgressReportDisplayEntry oldWidget) { |
||||||
|
super.didUpdateWidget(oldWidget); |
||||||
|
if (oldWidget.completed != widget.completed) { |
||||||
|
if (widget.completed) { |
||||||
|
_controller.forward(); |
||||||
|
} |
||||||
|
else { |
||||||
|
_controller.reverse(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
return AnimatedBuilder( |
||||||
|
animation: _controller, |
||||||
|
builder: (context, _) { |
||||||
|
return Container( |
||||||
|
decoration: BoxDecoration( |
||||||
|
color: background.evaluate(_controller) |
||||||
|
), |
||||||
|
child: Row( |
||||||
|
children: <Widget>[ |
||||||
|
Center( |
||||||
|
child: Padding( |
||||||
|
padding: const EdgeInsets.all(4), |
||||||
|
child: Container( |
||||||
|
width: 32, |
||||||
|
height: 32, |
||||||
|
child: |
||||||
|
!widget.completed |
||||||
|
? CupertinoActivityIndicator() |
||||||
|
: Icon(CupertinoIcons.check_mark_circled, color: checkMark.evaluate(_controller)), |
||||||
|
), |
||||||
|
), |
||||||
|
), |
||||||
|
Expanded( |
||||||
|
child: Padding( |
||||||
|
padding: const EdgeInsets.all(4), |
||||||
|
child: Text(widget.text), |
||||||
|
), |
||||||
|
) |
||||||
|
], |
||||||
|
), |
||||||
|
); |
||||||
|
} |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class _ProgressReportDisplayEntryMaterialState extends State<ProgressReportDisplayEntry> with SingleTickerProviderStateMixin { |
||||||
|
Animatable<Color> background; |
||||||
|
Animatable<Color> checkMark; |
||||||
|
AnimationController _controller; |
||||||
|
|
||||||
|
initAnimation() { |
||||||
|
background = ColorTween( |
||||||
|
begin: Theme.of(context).scaffoldBackgroundColor, |
||||||
|
end: Colors.green, |
||||||
|
); |
||||||
|
checkMark = ColorTween( |
||||||
|
begin: Colors.white, |
||||||
|
end: Colors.greenAccent, |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
void initState() { |
||||||
|
super.initState(); |
||||||
|
|
||||||
|
_controller = AnimationController( |
||||||
|
duration: const Duration(milliseconds: 250), |
||||||
|
vsync: this, |
||||||
|
); |
||||||
|
_controller.value = widget.completed ? 1 : 0; |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
void didChangeDependencies() { |
||||||
|
super.didChangeDependencies(); |
||||||
|
initAnimation(); |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
void didUpdateWidget(ProgressReportDisplayEntry oldWidget) { |
||||||
|
super.didUpdateWidget(oldWidget); |
||||||
|
if (oldWidget.completed != widget.completed) { |
||||||
|
if (widget.completed) { |
||||||
|
_controller.forward(); |
||||||
|
} |
||||||
|
else { |
||||||
|
_controller.reverse(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
return AnimatedBuilder( |
||||||
|
animation: _controller, |
||||||
|
builder: (context, _) { |
||||||
|
return Container( |
||||||
|
decoration: BoxDecoration( |
||||||
|
color: background.evaluate(_controller) |
||||||
|
), |
||||||
|
child: Row( |
||||||
|
children: <Widget>[ |
||||||
|
Center( |
||||||
|
child: Padding( |
||||||
|
padding: const EdgeInsets.all(4), |
||||||
|
child: Container( |
||||||
|
width: 32, |
||||||
|
height: 32, |
||||||
|
child: |
||||||
|
!widget.completed |
||||||
|
? CircularProgressIndicator(strokeWidth: 2, valueColor: AlwaysStoppedAnimation(Colors.orangeAccent),) |
||||||
|
: Icon(Icons.check_circle, color: checkMark.evaluate(_controller), size: 32,), |
||||||
|
), |
||||||
|
), |
||||||
|
), |
||||||
|
Expanded( |
||||||
|
child: Padding( |
||||||
|
padding: const EdgeInsets.all(4), |
||||||
|
child: Text(widget.text), |
||||||
|
), |
||||||
|
) |
||||||
|
], |
||||||
|
), |
||||||
|
); |
||||||
|
} |
||||||
|
); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,10 @@ |
|||||||
|
import 'dart:ui'; |
||||||
|
|
||||||
|
const BACKGROUND_GREEN = Color.fromRGBO(5, 66, 10, 1); |
||||||
|
const FOREGROUND_GREEN = Color.fromRGBO(20, 180, 50, 1); |
||||||
|
|
||||||
|
const BACKGROUND_RED = Color.fromRGBO(66, 10, 5, 1); |
||||||
|
|
||||||
|
const FOREGROUND_WHITE = Color.fromRGBO(240, 250, 240, 1); |
||||||
|
|
||||||
|
const FOREGROUND_DARK_GREY = Color.fromRGBO(55, 55, 55, 1); |
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,402 @@ |
|||||||
|
import 'dart:convert'; |
||||||
|
import 'dart:io' show Platform; |
||||||
|
|
||||||
|
import 'package:flutter/material.dart'; |
||||||
|
import 'package:flutter/cupertino.dart'; |
||||||
|
import 'package:flutter/services.dart'; |
||||||
|
import 'package:info_tren/train_info_page/train_info.dart'; |
||||||
|
import 'package:json_annotation/json_annotation.dart'; |
||||||
|
import 'package:tuple/tuple.dart'; |
||||||
|
|
||||||
|
part 'train_info_prompt.g.dart'; |
||||||
|
|
||||||
|
typedef TrainSelectedCallback(int trainNumber); |
||||||
|
|
||||||
|
mixin TrainInfoPromptAction { |
||||||
|
onTrainSelected(BuildContext context, int selection) { |
||||||
|
if (Platform.isAndroid) { |
||||||
|
Navigator.of(context).push( |
||||||
|
MaterialPageRoute( |
||||||
|
builder: (context) { |
||||||
|
return TrainInfo( |
||||||
|
trainNumber: selection, |
||||||
|
); |
||||||
|
}, |
||||||
|
) |
||||||
|
); |
||||||
|
} |
||||||
|
else if (Platform.isIOS) { |
||||||
|
Navigator.of(context).push( |
||||||
|
CupertinoPageRoute( |
||||||
|
title: "Informații despre trenul $selection", |
||||||
|
builder: (context) { |
||||||
|
return TrainInfo( |
||||||
|
trainNumber: selection, |
||||||
|
); |
||||||
|
}, |
||||||
|
) |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
mixin TrainInfoPromptListHandling { |
||||||
|
List<TrainOperatorLines> operators = List(); |
||||||
|
|
||||||
|
Future loadOperators(BuildContext context) async { |
||||||
|
operators = List(); |
||||||
|
|
||||||
|
final operatorsString = await DefaultAssetBundle.of(context).loadString("assets/lines/files.txt"); |
||||||
|
final operatorsFilesList = operatorsString.split("\n"); |
||||||
|
|
||||||
|
final decoder = JsonDecoder(); |
||||||
|
|
||||||
|
for (final operatorFile in operatorsFilesList) { |
||||||
|
final operatorString = await DefaultAssetBundle.of(context).loadString("assets/lines/$operatorFile"); |
||||||
|
final operatorData = decoder.convert(operatorString); |
||||||
|
final _operator = TrainOperatorLines.fromJson(operatorData); |
||||||
|
operators.add(_operator); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
Widget getOperatorsListView(BuildContext context, {String currentInput = "", @required TrainSelectedCallback onTrainSelected}) { |
||||||
|
var sliversTuple = operators.map( |
||||||
|
(op) => Tuple2( |
||||||
|
getFilteredLines(op, currentInput), |
||||||
|
getOperatorSliver(context, op, currentInput, onTrainSelected) |
||||||
|
) |
||||||
|
) |
||||||
|
.where((tuple) => tuple.item1.isNotEmpty).toList(); |
||||||
|
if (currentInput.isNotEmpty) sliversTuple.sort((a, b) { |
||||||
|
final aTrain = a.item1.first; |
||||||
|
final bTrain = b.item1.first; |
||||||
|
|
||||||
|
final inputAsRegExp = RegExp(currentInput); |
||||||
|
|
||||||
|
final matchOnA = inputAsRegExp.firstMatch(aTrain.number); |
||||||
|
final matchOnB = inputAsRegExp.firstMatch(bTrain.number); |
||||||
|
|
||||||
|
if (matchOnA.start != matchOnB.start) return matchOnA.start - matchOnB.start; |
||||||
|
|
||||||
|
if (aTrain.number.length != bTrain.number.length) return aTrain.number.length - bTrain.number.length; |
||||||
|
|
||||||
|
return aTrain.number.compareTo(bTrain.number); |
||||||
|
}); |
||||||
|
var slivers = sliversTuple.map((tuple) => tuple.item2).toList(); |
||||||
|
|
||||||
|
return CustomScrollView( |
||||||
|
slivers: <Widget>[ |
||||||
|
...slivers, |
||||||
|
SliverToBoxAdapter( |
||||||
|
child: getUseCurrentInputWidget(currentInput, onTrainSelected), |
||||||
|
), |
||||||
|
SliverToBoxAdapter( |
||||||
|
child: Container( |
||||||
|
height: MediaQuery.of(context).viewPadding.bottom, |
||||||
|
), |
||||||
|
), |
||||||
|
], |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
Widget getUseCurrentInputWidget(String currentInput, TrainSelectedCallback onTrainSelected) { |
||||||
|
if (currentInput.isEmpty) { |
||||||
|
return Container(); |
||||||
|
} |
||||||
|
|
||||||
|
if (int.tryParse(currentInput) == null) { |
||||||
|
return Container(); |
||||||
|
} |
||||||
|
|
||||||
|
return Column( |
||||||
|
mainAxisSize: MainAxisSize.min, |
||||||
|
children: <Widget>[ |
||||||
|
if (Platform.isAndroid) |
||||||
|
ListTile( |
||||||
|
title: Text("Caută trenul cu numărul $currentInput"), |
||||||
|
onTap: () { |
||||||
|
onTrainSelected(int.parse(currentInput)); |
||||||
|
}, |
||||||
|
) |
||||||
|
else if (Platform.isIOS) |
||||||
|
GestureDetector( |
||||||
|
onTap: () { |
||||||
|
onTrainSelected(int.parse(currentInput)); |
||||||
|
}, |
||||||
|
child: Padding( |
||||||
|
padding: const EdgeInsets.all(8), |
||||||
|
child: Column( |
||||||
|
mainAxisSize: MainAxisSize.min, |
||||||
|
children: <Widget>[ |
||||||
|
Text("Caută trenul cu numărul $currentInput") |
||||||
|
], |
||||||
|
) |
||||||
|
), |
||||||
|
), |
||||||
|
Divider(), |
||||||
|
], |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
List<_TrainOperatorTrainDescription> getFilteredLines(TrainOperatorLines _operator, String currentInput) { |
||||||
|
if (currentInput.isNotEmpty) { |
||||||
|
final filteredLines = _operator.trains |
||||||
|
.where((elem) => elem.number.contains(currentInput)) |
||||||
|
.toList(); |
||||||
|
|
||||||
|
filteredLines.sort((a, b) { |
||||||
|
final inputAsRegExp = RegExp(currentInput); |
||||||
|
|
||||||
|
final matchOnA = inputAsRegExp.firstMatch(a.number); |
||||||
|
final matchOnB = inputAsRegExp.firstMatch(b.number); |
||||||
|
|
||||||
|
if (matchOnA.start != matchOnB.start) return matchOnA.start - matchOnB.start; |
||||||
|
|
||||||
|
if (a.number.length != b.number.length) return a.number.length - b.number.length; |
||||||
|
|
||||||
|
return a.number.compareTo(b.number); |
||||||
|
}); |
||||||
|
|
||||||
|
return filteredLines; |
||||||
|
} |
||||||
|
else { |
||||||
|
return _operator.trains; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
Widget getOperatorSliver(BuildContext context, TrainOperatorLines _operator, String currentInput, TrainSelectedCallback onTrainSelected) { |
||||||
|
final filteredLines = getFilteredLines(_operator, currentInput); |
||||||
|
|
||||||
|
if (filteredLines.isEmpty) { |
||||||
|
return SliverToBoxAdapter(child: Container(),); |
||||||
|
} |
||||||
|
|
||||||
|
return SliverPrototypeExtentList( |
||||||
|
prototypeItem: Column( |
||||||
|
children: <Widget>[ |
||||||
|
getLineListItem( |
||||||
|
context, |
||||||
|
op: TrainOperatorLines(), |
||||||
|
line: _TrainOperatorTrainDescription() |
||||||
|
), |
||||||
|
Divider(), |
||||||
|
], |
||||||
|
), |
||||||
|
delegate: SliverChildBuilderDelegate( |
||||||
|
(context, index) { |
||||||
|
return Column( |
||||||
|
children: <Widget>[ |
||||||
|
getLineListItem( |
||||||
|
context, |
||||||
|
op: _operator, |
||||||
|
line: filteredLines[index], |
||||||
|
onTrainSelected: onTrainSelected |
||||||
|
), |
||||||
|
Divider(), |
||||||
|
], |
||||||
|
); |
||||||
|
}, |
||||||
|
childCount: filteredLines.length, |
||||||
|
addSemanticIndexes: true, |
||||||
|
), |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
Widget getLineListItem(BuildContext context, {TrainOperatorLines op, _TrainOperatorTrainDescription line, TrainSelectedCallback onTrainSelected}) { |
||||||
|
if (Platform.isAndroid) { |
||||||
|
return ListTile( |
||||||
|
dense: true, |
||||||
|
title: Text("${line.rang ?? ""} ${line.number ?? ""}"), |
||||||
|
subtitle: Text(op.operator ?? ""), |
||||||
|
onTap: () { |
||||||
|
onTrainSelected(line.internalNumber); |
||||||
|
}, |
||||||
|
); |
||||||
|
} |
||||||
|
else if (Platform.isIOS) { |
||||||
|
return GestureDetector( |
||||||
|
onTap: () { |
||||||
|
onTrainSelected(line.internalNumber); |
||||||
|
}, |
||||||
|
child: Padding( |
||||||
|
padding: const EdgeInsets.fromLTRB(16, 2, 16, 2), |
||||||
|
child: SizedBox( |
||||||
|
width: double.infinity, |
||||||
|
child: Column( |
||||||
|
mainAxisSize: MainAxisSize.min, |
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch, |
||||||
|
children: <Widget>[ |
||||||
|
Text( |
||||||
|
op.operator ?? "", |
||||||
|
style: CupertinoTheme.of(context).textTheme.textStyle.copyWith(fontSize: 10, fontWeight: FontWeight.w200), |
||||||
|
textAlign: TextAlign.left, |
||||||
|
), |
||||||
|
Text( |
||||||
|
"${line.rang ?? ""} ${line.number ?? ""}", |
||||||
|
textAlign: TextAlign.left, |
||||||
|
), |
||||||
|
], |
||||||
|
), |
||||||
|
), |
||||||
|
), |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class TrainInfoPromptMaterial extends StatefulWidget { |
||||||
|
@override |
||||||
|
_TrainInfoPromptMaterialState createState() => _TrainInfoPromptMaterialState(); |
||||||
|
} |
||||||
|
|
||||||
|
class _TrainInfoPromptMaterialState extends State<TrainInfoPromptMaterial> with TrainInfoPromptAction, TrainInfoPromptListHandling { |
||||||
|
TextEditingController trainNoController = TextEditingController(); |
||||||
|
|
||||||
|
@override |
||||||
|
void initState() { |
||||||
|
super.initState(); |
||||||
|
|
||||||
|
loadOperators(context).then((_) { |
||||||
|
setState(() {}); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
return Scaffold( |
||||||
|
appBar: AppBar( |
||||||
|
title: Text("Informații despre tren"), |
||||||
|
centerTitle: true, |
||||||
|
), |
||||||
|
body: SafeArea( |
||||||
|
bottom: false, |
||||||
|
child: Column( |
||||||
|
mainAxisSize: MainAxisSize.max, |
||||||
|
children: <Widget>[ |
||||||
|
Padding( |
||||||
|
padding: const EdgeInsets.all(4), |
||||||
|
child: TextField( |
||||||
|
controller: trainNoController, |
||||||
|
autofocus: true, |
||||||
|
decoration: InputDecoration( |
||||||
|
border: OutlineInputBorder(), |
||||||
|
labelText: "Numărul trenului", |
||||||
|
), |
||||||
|
inputFormatters: [ |
||||||
|
WhitelistingTextInputFormatter.digitsOnly, |
||||||
|
], |
||||||
|
textInputAction: TextInputAction.search, |
||||||
|
keyboardType: TextInputType.number, |
||||||
|
onChanged: (_) { |
||||||
|
setState(() {}); |
||||||
|
}, |
||||||
|
), |
||||||
|
), |
||||||
|
Expanded( |
||||||
|
child: getOperatorsListView(context, currentInput: trainNoController.text, onTrainSelected: (number) { |
||||||
|
onTrainSelected(context, number); |
||||||
|
}) |
||||||
|
) |
||||||
|
], |
||||||
|
), |
||||||
|
), |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
class TrainInfoPromptCupertino extends StatefulWidget { |
||||||
|
@override |
||||||
|
_TrainInfoPromptCupertinoState createState() => _TrainInfoPromptCupertinoState(); |
||||||
|
} |
||||||
|
|
||||||
|
class _TrainInfoPromptCupertinoState extends State<TrainInfoPromptCupertino> with TrainInfoPromptAction, TrainInfoPromptListHandling { |
||||||
|
TextEditingController trainNoController = TextEditingController(); |
||||||
|
|
||||||
|
@override |
||||||
|
void initState() { |
||||||
|
super.initState(); |
||||||
|
|
||||||
|
loadOperators(context).then((_) { |
||||||
|
setState(() {}); |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
@override |
||||||
|
Widget build(BuildContext context) { |
||||||
|
return CupertinoPageScaffold( |
||||||
|
navigationBar: CupertinoNavigationBar( |
||||||
|
middle: Text("Informații despre tren"), |
||||||
|
), |
||||||
|
child: SafeArea( |
||||||
|
bottom: false, |
||||||
|
child: Column( |
||||||
|
mainAxisSize: MainAxisSize.max, |
||||||
|
children: <Widget>[ |
||||||
|
Padding( |
||||||
|
padding: const EdgeInsets.all(4), |
||||||
|
child: CupertinoTextField( |
||||||
|
controller: trainNoController, |
||||||
|
autofocus: true, |
||||||
|
placeholder: "Numărul trenului", |
||||||
|
textInputAction: TextInputAction.search, |
||||||
|
keyboardType: TextInputType.number, |
||||||
|
onChanged: (_) { |
||||||
|
setState(() {}); |
||||||
|
}, |
||||||
|
inputFormatters: [ |
||||||
|
WhitelistingTextInputFormatter.digitsOnly, |
||||||
|
], |
||||||
|
), |
||||||
|
), |
||||||
|
Expanded( |
||||||
|
child: getOperatorsListView(context, currentInput: trainNoController.text, onTrainSelected: (number) { |
||||||
|
onTrainSelected(context, number); |
||||||
|
}) |
||||||
|
) |
||||||
|
], |
||||||
|
), |
||||||
|
), |
||||||
|
); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@JsonSerializable() |
||||||
|
class TrainOperatorLines { |
||||||
|
@JsonKey(name: "short_name") |
||||||
|
final String shortName; |
||||||
|
final String operator; |
||||||
|
@JsonKey(name: "versiune") |
||||||
|
final String version; |
||||||
|
@JsonKey(name: "trenuri") |
||||||
|
final List<_TrainOperatorTrainDescription> trains; |
||||||
|
|
||||||
|
TrainOperatorLines({ |
||||||
|
this.operator, |
||||||
|
this.shortName = "", |
||||||
|
this.version, |
||||||
|
this.trains, |
||||||
|
}); |
||||||
|
|
||||||
|
factory TrainOperatorLines.fromJson(Map<String, dynamic> json) => _$TrainOperatorLinesFromJson(json); |
||||||
|
Map<String, dynamic> toJson() => _$TrainOperatorLinesToJson(this); |
||||||
|
} |
||||||
|
|
||||||
|
@JsonSerializable() |
||||||
|
class _TrainOperatorTrainDescription { |
||||||
|
final String rang; |
||||||
|
@JsonKey(name: "numar") |
||||||
|
final String number; |
||||||
|
@JsonKey(name: "numar_intern") |
||||||
|
final int internalNumber; |
||||||
|
|
||||||
|
_TrainOperatorTrainDescription({ |
||||||
|
this.number, |
||||||
|
this.rang, |
||||||
|
this.internalNumber |
||||||
|
}); |
||||||
|
|
||||||
|
factory _TrainOperatorTrainDescription.fromJson(Map<String, dynamic> json) => _$_TrainOperatorTrainDescriptionFromJson(json); |
||||||
|
Map<String, dynamic> toJson() => _$_TrainOperatorTrainDescriptionToJson(this); |
||||||
|
} |
@ -0,0 +1,44 @@ |
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND |
||||||
|
|
||||||
|
part of 'train_info_prompt.dart'; |
||||||
|
|
||||||
|
// ************************************************************************** |
||||||
|
// JsonSerializableGenerator |
||||||
|
// ************************************************************************** |
||||||
|
|
||||||
|
TrainOperatorLines _$TrainOperatorLinesFromJson(Map<String, dynamic> json) { |
||||||
|
return TrainOperatorLines( |
||||||
|
operator: json['operator'] as String, |
||||||
|
shortName: json['short_name'] as String, |
||||||
|
version: json['versiune'] as String, |
||||||
|
trains: (json['trenuri'] as List) |
||||||
|
?.map((e) => e == null |
||||||
|
? null |
||||||
|
: _TrainOperatorTrainDescription.fromJson( |
||||||
|
e as Map<String, dynamic>)) |
||||||
|
?.toList()); |
||||||
|
} |
||||||
|
|
||||||
|
Map<String, dynamic> _$TrainOperatorLinesToJson(TrainOperatorLines instance) => |
||||||
|
<String, dynamic>{ |
||||||
|
'short_name': instance.shortName, |
||||||
|
'operator': instance.operator, |
||||||
|
'versiune': instance.version, |
||||||
|
'trenuri': instance.trains |
||||||
|
}; |
||||||
|
|
||||||
|
_TrainOperatorTrainDescription _$_TrainOperatorTrainDescriptionFromJson( |
||||||
|
Map<String, dynamic> json) { |
||||||
|
return _TrainOperatorTrainDescription( |
||||||
|
number: json['numar'] as String, |
||||||
|
rang: json['rang'] as String, |
||||||
|
internalNumber: json['numar_intern'] as int); |
||||||
|
} |
||||||
|
|
||||||
|
Map<String, dynamic> _$_TrainOperatorTrainDescriptionToJson( |
||||||
|
_TrainOperatorTrainDescription instance) => |
||||||
|
<String, dynamic>{ |
||||||
|
'rang': instance.rang, |
||||||
|
'numar': instance.number, |
||||||
|
'numar_intern': instance.internalNumber |
||||||
|
}; |
@ -0,0 +1,10 @@ |
|||||||
|
import 'dart:async'; |
||||||
|
|
||||||
|
Stream<List<T>> listifyStream<T>(Stream<T> stream) async* { |
||||||
|
List<T> list = List(); |
||||||
|
|
||||||
|
await for (T item in stream) { |
||||||
|
list.add(item); |
||||||
|
yield list; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
import 'dart:convert'; |
||||||
|
import 'dart:io' show Platform; |
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart'; |
||||||
|
import 'package:webview_flutter/webview_flutter.dart'; |
||||||
|
|
||||||
|
/// Evaluates a JavaScript function on the given WebView. |
||||||
|
/// |
||||||
|
/// The JavaScript function must return a String. |
||||||
|
/// |
||||||
|
/// On Android, the `String` resulted from the evaluation |
||||||
|
/// is JSON parsed. On iOS, the `String` is returned as is. |
||||||
|
/// |
||||||
|
/// Other platforms are not supported. The returned value |
||||||
|
/// in this case will be `null`. |
||||||
|
Future<String> wInvoke({ |
||||||
|
@required WebViewController webViewController, |
||||||
|
@required String jsFunctionContent, |
||||||
|
bool isFunctionAlready = false |
||||||
|
}) async { |
||||||
|
final actualJS = isFunctionAlready ? |
||||||
|
jsFunctionContent : |
||||||
|
""" |
||||||
|
(() => { |
||||||
|
$jsFunctionContent |
||||||
|
})() |
||||||
|
"""; |
||||||
|
|
||||||
|
final res = await webViewController.evaluateJavascript(actualJS); |
||||||
|
|
||||||
|
if (Platform.isAndroid) return JsonDecoder().convert(res) as String; |
||||||
|
else if (Platform.isIOS) return res; |
||||||
|
else return null; |
||||||
|
} |
Loading…
Reference in new issue