Skip to content
25 changes: 25 additions & 0 deletions lib/domain/bus_stop.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'package:freezed_annotation/freezed_annotation.dart';

part 'bus_stop.freezed.dart';

@freezed
abstract class BusStop with _$BusStop {
const factory BusStop({
required int id,
required String name,
required List<String> routeList,
bool? reverse,
bool? selectable,
}) = _BusStop;

factory BusStop.fromFirebase(Map<String, dynamic> map) {
final routeList = (map['route'] as List).map((e) => e.toString()).toList();
return BusStop(
id: map['id'] as int,
name: map['name'] as String,
routeList: routeList,
reverse: map['reverse'] as bool?,
selectable: map['selectable'] as bool?,
);
}
}
28 changes: 14 additions & 14 deletions lib/feature/bus/domain/bus_trip.dart → lib/domain/bus_trip.dart
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
import 'package:dotto/feature/bus/domain/bus_stop.dart';
import 'package:dotto/domain/bus_stop.dart';
import 'package:freezed_annotation/freezed_annotation.dart';

final class BusTripStop {
const BusTripStop(this.time, this.stop, {this.terminal});
part 'bus_trip.freezed.dart';

@freezed
abstract class BusTripStop with _$BusTripStop {
const factory BusTripStop({required Duration time, required BusStop stop, int? terminal}) = _BusTripStop;

factory BusTripStop.fromFirebase(BusStop stop, Map<String, dynamic> map) {
final timeStrList = (map['time'] as String).split(':');
final hour = int.parse(timeStrList[0]);
final minute = int.parse(timeStrList[1]);
return BusTripStop(
Duration(hours: hour, minutes: minute),
stop,
time: Duration(hours: hour, minutes: minute),
stop: stop,
terminal: map['terminal'] as int?,
);
}
final Duration time;
final BusStop stop;
final int? terminal;
}

final class BusTrip {
const BusTrip(this.route, this.stops);
@freezed
abstract class BusTrip with _$BusTrip {
const factory BusTrip({required String route, required List<BusTripStop> stops}) = _BusTrip;

factory BusTrip.fromFirebase(Map<String, dynamic> map, List<BusStop> allStops) {
final stopsList = map['stops'] as List;
return BusTrip(
map['route'] as String,
stopsList.map((e) {
route: map['route'] as String,
stops: stopsList.map((e) {
final stopMap = Map<String, dynamic>.from(e as Map);
final id = stopMap['id'] as int;
final targetBusStop = allStops.firstWhere((busStop) => busStop.id == id);
return BusTripStop.fromFirebase(targetBusStop, stopMap);
}).toList(),
);
}
final String route;
final List<BusTripStop> stops;
}
File renamed without changes.
207 changes: 0 additions & 207 deletions lib/feature/bus/bus.dart

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import 'package:dotto/feature/bus/controller/bus_is_to_controller.dart';
import 'package:dotto/feature/bus/controller/my_bus_stop_controller.dart';
import 'package:dotto/feature/bus/domain/bus_type.dart';
import 'package:dotto/feature/bus/repository/bus_repository.dart';
import 'package:dotto/domain/bus_type.dart';
import 'package:dotto/feature/bus/bus_reducer.dart';
import 'package:dotto_design_system/style/semantic_color.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

final class BusCard extends ConsumerWidget {
const BusCard(
this.route,
this.beginTime,
this.endTime,
this.arriveAt, {
const BusCard({
required this.route,
required this.beginTime,
required this.endTime,
required this.arriveAt,
required this.isTo,
required this.myBusStopName,
super.key,
this.isKameda = false,
this.home = false,
Expand All @@ -20,6 +20,8 @@ final class BusCard extends ConsumerWidget {
final Duration beginTime;
final Duration endTime;
final Duration arriveAt;
final bool isTo;
final String myBusStopName;
final bool isKameda;
final bool home;

Expand All @@ -38,10 +40,8 @@ final class BusCard extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final busIsTo = ref.watch(busIsToProvider);
final myBusStop = ref.watch(myBusStopProvider);
final tripType = getType();
final headerText = tripType != BusType.other ? tripType.where + (busIsTo ? 'から' : '行き') : '';
final headerText = tripType != BusType.other ? tripType.where + (isTo ? 'から' : '行き') : '';
return Card(
color: Colors.white,
shadowColor: Colors.black,
Expand All @@ -56,7 +56,7 @@ final class BusCard extends ConsumerWidget {
children: [
Expanded(
child: Text(
busIsTo ? '${myBusStop.name} → 未来大' : '未来大 → ${myBusStop.name}',
isTo ? '$myBusStopName → 未来大' : '未来大 → $myBusStopName',
overflow: TextOverflow.ellipsis,
),
),
Expand All @@ -65,7 +65,7 @@ final class BusCard extends ConsumerWidget {
child: IconButton(
color: SemanticColor.light.accentInfo,
onPressed: () {
ref.read(busIsToProvider.notifier).toggle();
ref.read(busReducerProvider.notifier).toggleDirection();
},
icon: const Icon(Icons.swap_horiz_outlined),
padding: EdgeInsets.zero,
Expand All @@ -82,17 +82,14 @@ final class BusCard extends ConsumerWidget {
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(BusRepository().formatDuration(beginTime), style: Theme.of(context).textTheme.displayMedium),
Transform.translate(
offset: const Offset(0, -5),
child: Text(isKameda && busIsTo ? '亀田支所発' : '発'),
),
Text(formatDuration(beginTime), style: Theme.of(context).textTheme.displayMedium),
Transform.translate(offset: const Offset(0, -5), child: Text(isKameda && isTo ? '亀田支所発' : '発')),
const Spacer(),
Transform.translate(
offset: const Offset(0, -5),
child: Text(
'${BusRepository().formatDuration(endTime)}'
'${isKameda && !busIsTo ? '亀田支所着' : '着'}',
'${formatDuration(endTime)}'
'${isKameda && !isTo ? '亀田支所着' : '着'}',
),
),
],
Expand Down
Loading
Loading