-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from jeffsieu/md3-migration
Md3 migration
- Loading branch information
Showing
52 changed files
with
2,381 additions
and
2,242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,7 @@ android { | |
|
||
lintOptions { | ||
disable 'InvalidPackage' | ||
checkReleaseBuilds false | ||
} | ||
|
||
defaultConfig { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import 'package:flutter_bloc/flutter_bloc.dart'; | ||
|
||
import '../../models/bus_stop.dart'; | ||
import '../../utils/database_utils.dart'; | ||
|
||
part 'bus_stop_sheet_event.dart'; | ||
|
||
class BusStopSheetBloc extends Bloc<BusStopSheetEvent, BusStopSheetState> { | ||
BusStopSheetBloc() : super(BusStopSheetState.initial()) { | ||
on<SheetRequested>(_onSheetRequested); | ||
on<SheetHidden>(_onSheetHidden); | ||
on<EditModeEntered>(_onEditModeEntered); | ||
on<EditModeExited>(_onEditModeExited); | ||
on<RenameRequested>(_onRenameRequested); | ||
on<RenameExited>(_onRenameExited); | ||
on<BusStopRenamed>(_onBusStopRenamed); | ||
} | ||
|
||
Future<void> _onSheetRequested( | ||
SheetRequested event, Emitter<BusStopSheetState> emit) async { | ||
final busStop = event.busStop; | ||
final routeId = event.routeId; | ||
|
||
final isInRoute = await isBusStopInRouteWithId(busStop, routeId); | ||
|
||
emit(state.copyWith( | ||
busStop: busStop, | ||
routeId: routeId, | ||
visible: true, | ||
isEditing: event.withEdit, | ||
isInRoute: isInRoute, | ||
isRenaming: false, | ||
latestOpenTimestamp: DateTime.now().millisecondsSinceEpoch, | ||
)); | ||
|
||
/// TODO: Make it await until the sheet is fully open | ||
} | ||
|
||
void _onSheetHidden(SheetHidden event, Emitter<BusStopSheetState> emit) { | ||
emit(state.copyWith( | ||
visible: false, | ||
isRenaming: false, | ||
isEditing: false, | ||
)); | ||
} | ||
|
||
void _onEditModeEntered( | ||
EditModeEntered event, Emitter<BusStopSheetState> emit) { | ||
emit(state.copyWith(isEditing: true)); | ||
} | ||
|
||
void _onEditModeExited( | ||
EditModeExited event, Emitter<BusStopSheetState> emit) { | ||
emit(state.copyWith(isEditing: false)); | ||
} | ||
|
||
void _onRenameRequested( | ||
RenameRequested event, Emitter<BusStopSheetState> emit) { | ||
emit(state.copyWith(isRenaming: true)); | ||
} | ||
|
||
void _onRenameExited(RenameExited event, Emitter<BusStopSheetState> emit) { | ||
emit(state.copyWith(isRenaming: false)); | ||
} | ||
|
||
void _onBusStopRenamed( | ||
BusStopRenamed event, Emitter<BusStopSheetState> emit) { | ||
if (state.busStop == null) { | ||
return; | ||
} | ||
final newBusStop = state.busStop!.copyWith(displayName: event.newName); | ||
updateBusStop(newBusStop); | ||
emit(state.copyWith( | ||
busStop: newBusStop, | ||
)); | ||
} | ||
} | ||
|
||
class BusStopSheetState { | ||
final BusStop? busStop; | ||
final int? routeId; | ||
final bool visible; | ||
final bool isEditing; | ||
final bool isRenaming; | ||
final bool isInRoute; | ||
|
||
/// The timestamp of the last time the sheet was opened. | ||
/// Used to force the state to be different when the sheet is opened again. | ||
final int latestOpenTimestamp; | ||
|
||
BusStopSheetState.initial() | ||
: busStop = null, | ||
routeId = null, | ||
visible = false, | ||
isEditing = false, | ||
isRenaming = false, | ||
isInRoute = false, | ||
latestOpenTimestamp = 0; | ||
BusStopSheetState({ | ||
required this.busStop, | ||
required this.routeId, | ||
required this.visible, | ||
required this.isEditing, | ||
required this.isRenaming, | ||
required this.isInRoute, | ||
required this.latestOpenTimestamp, | ||
}); | ||
|
||
BusStopSheetState copyWith({ | ||
BusStop? busStop, | ||
int? routeId, | ||
bool? visible, | ||
bool? isEditing, | ||
bool? isRenaming, | ||
bool? isInRoute, | ||
int? latestOpenTimestamp, | ||
}) { | ||
return BusStopSheetState( | ||
busStop: busStop ?? this.busStop, | ||
routeId: routeId ?? this.routeId, | ||
visible: visible ?? this.visible, | ||
isEditing: isEditing ?? this.isEditing, | ||
isRenaming: isRenaming ?? this.isRenaming, | ||
isInRoute: isInRoute ?? this.isInRoute, | ||
latestOpenTimestamp: latestOpenTimestamp ?? this.latestOpenTimestamp, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
part of 'bus_stop_sheet_bloc.dart'; | ||
|
||
class BusStopSheetEvent { | ||
const BusStopSheetEvent(); | ||
} | ||
|
||
class SheetRequested extends BusStopSheetEvent { | ||
final BusStop busStop; | ||
final int routeId; | ||
final bool withEdit; | ||
|
||
const SheetRequested(this.busStop, this.routeId) : withEdit = false; | ||
const SheetRequested.withEdit(this.busStop, this.routeId) : withEdit = true; | ||
} | ||
|
||
class SheetHidden extends BusStopSheetEvent { | ||
const SheetHidden(); | ||
} | ||
|
||
class EditModeEntered extends BusStopSheetEvent { | ||
const EditModeEntered(); | ||
} | ||
|
||
class EditModeExited extends BusStopSheetEvent { | ||
const EditModeExited(); | ||
} | ||
|
||
class RenameRequested extends BusStopSheetEvent { | ||
const RenameRequested(); | ||
} | ||
|
||
class RenameExited extends BusStopSheetEvent { | ||
const RenameExited(); | ||
} | ||
|
||
class BusStopRenamed extends BusStopSheetEvent { | ||
final String newName; | ||
|
||
const BusStopRenamed(this.newName); | ||
} |
Oops, something went wrong.