Skip to content

Commit

Permalink
Merge pull request #23 from jeffsieu/md3-migration
Browse files Browse the repository at this point in the history
Md3 migration
  • Loading branch information
jeffsieu authored Jun 6, 2022
2 parents 1823cd3 + 21faeb5 commit 084764b
Show file tree
Hide file tree
Showing 52 changed files with 2,381 additions and 2,242 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/web.yml → .github/workflows/web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ jobs:
- name: Install flutter
uses: subosito/flutter-action@v1.5.3
with:
# The Flutter version to make available on the path
flutter-version: '2.8.0'
flutter-version: '2.10.1'

- run: flutter config --enable-web

Expand Down
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ analyzer:

linter:
rules:
- always_specify_types
- always_declare_return_types
- omit_local_variable_types
- avoid_returning_null_for_future
- await_only_futures
- prefer_null_aware_operators
Expand Down
1 change: 1 addition & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ android {

lintOptions {
disable 'InvalidPackage'
checkReleaseBuilds false
}

defaultConfig {
Expand Down
128 changes: 128 additions & 0 deletions lib/bus_stop_sheet/bloc/bus_stop_sheet_bloc.dart
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,
);
}
}
40 changes: 40 additions & 0 deletions lib/bus_stop_sheet/bloc/bus_stop_sheet_event.dart
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);
}
Loading

0 comments on commit 084764b

Please sign in to comment.