70 lines
1.8 KiB
Dart
70 lines
1.8 KiB
Dart
|
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,
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
}
|