Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushik committed Jun 26, 2024
1 parent 8ff92c9 commit fc179a7
Show file tree
Hide file tree
Showing 11 changed files with 119 additions and 143 deletions.
66 changes: 31 additions & 35 deletions app/lib/ui/flow/geofence/add/addnew/add_new_place_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:yourspace_flutter/ui/app_route.dart';
import 'package:yourspace_flutter/ui/components/app_page.dart';

import '../../../../../gen/assets.gen.dart';
import '../../../../components/error_snakebar.dart';
import 'add_new_place_view_model.dart';

class AddNewPlaceView extends ConsumerStatefulWidget {
Expand All @@ -25,32 +26,29 @@ class _AddNewPlaceViewState extends ConsumerState<AddNewPlaceView> {

@override
Widget build(BuildContext context) {
notifier = ref.watch(addNewPLaceStateProvider.notifier);
notifier = ref.watch(addNewPlaceStateProvider.notifier);

_observeError();

return AppPage(
title: context.l10n.add_new_place_title,
body: _body(),
);
}

Widget _body() {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_searchTextField(),
const SizedBox(height: 56),
_locateOnMapView(),
const SizedBox(height: 40),
Text(
context.l10n.add_new_place_suggestion_text,
style: AppTextStyle.caption.copyWith(
color: context.colorScheme.textDisabled,
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_searchTextField(),
const SizedBox(height: 40),
_locateOnMapView(),
const SizedBox(height: 40),
Text(
context.l10n.add_new_place_suggestion_text,
style: AppTextStyle.caption.copyWith(
color: context.colorScheme.textDisabled,
),
),
),
_placeSuggestionView()
],
],
),
),
);
}
Expand All @@ -76,19 +74,12 @@ class _AddNewPlaceViewState extends ConsumerState<AddNewPlaceView> {
color: context.colorScheme.textDisabled,
),
contentPadding: const EdgeInsets.symmetric(vertical: 0),
prefixIconConstraints: const BoxConstraints(
minHeight: 0,
minWidth: 0,
),
border: UnderlineInputBorder(
borderSide: BorderSide(
color: context.colorScheme.textDisabled,
),
prefixIconConstraints: const BoxConstraints(),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: context.colorScheme.outline),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: context.colorScheme.primary,
),
borderSide: BorderSide(color: context.colorScheme.primary),
),
),
),
Expand Down Expand Up @@ -135,7 +126,12 @@ class _AddNewPlaceViewState extends ConsumerState<AddNewPlaceView> {
);
}

Widget _placeSuggestionView() {
return Container();
void _observeError() {
ref.listen(addNewPlaceStateProvider.select((state) => state.error),
(previous, next) {
if (next != null) {
showErrorSnackBar(context, next.toString());
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:freezed_annotation/freezed_annotation.dart';

part 'add_new_place_view_model.freezed.dart';

final addNewPLaceStateProvider = StateNotifierProvider.autoDispose<
final addNewPlaceStateProvider = StateNotifierProvider.autoDispose<
AddNewPlaceViewNotifier, AddNewPlaceState>((ref) {
return AddNewPlaceViewNotifier(ref.read(placeServiceProvider));
});
Expand All @@ -34,7 +34,7 @@ class AddNewPlaceViewNotifier extends StateNotifier<AddNewPlaceState> {
} catch (error, stack) {
state = state.copyWith(error: error, loading: false);
logger.e(
'PlaceListNotifier: Error while deleting place',
'AddNewPlaceViewNotifier: Error while finding place',
error: error,
stackTrace: stack,
);
Expand Down
4 changes: 2 additions & 2 deletions app/lib/ui/flow/geofence/add/locate/locate_on_map_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ class _LocateOnMapViewState extends ConsumerState<LocateOnMapView> {
onCameraMove: notifier.showLocateBtn,
),
),
Center(child: _centerLocateView()),
Center(child: _locateMarkerView()),
Align(
alignment: Alignment.bottomRight, child: _locateIconButton(context))
]),
);
}

Widget _centerLocateView() {
Widget _locateMarkerView() {
return Container(
width: 40,
height: 40,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class LocateOnMapVieNotifier extends StateNotifier<LocateOnMapState> {
@freezed
class LocateOnMapState with _$LocateOnMapState {
const factory LocateOnMapState({
@Default(false) bool loading,
CameraPosition? centerPosition,
}) = _LocateOnMapState;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ final _privateConstructorUsedError = UnsupportedError(

/// @nodoc
mixin _$LocateOnMapState {
bool get loading => throw _privateConstructorUsedError;
CameraPosition? get centerPosition => throw _privateConstructorUsedError;

@JsonKey(ignore: true)
Expand All @@ -30,7 +29,7 @@ abstract class $LocateOnMapStateCopyWith<$Res> {
LocateOnMapState value, $Res Function(LocateOnMapState) then) =
_$LocateOnMapStateCopyWithImpl<$Res, LocateOnMapState>;
@useResult
$Res call({bool loading, CameraPosition? centerPosition});
$Res call({CameraPosition? centerPosition});
}

/// @nodoc
Expand All @@ -46,14 +45,9 @@ class _$LocateOnMapStateCopyWithImpl<$Res, $Val extends LocateOnMapState>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? loading = null,
Object? centerPosition = freezed,
}) {
return _then(_value.copyWith(
loading: null == loading
? _value.loading
: loading // ignore: cast_nullable_to_non_nullable
as bool,
centerPosition: freezed == centerPosition
? _value.centerPosition
: centerPosition // ignore: cast_nullable_to_non_nullable
Expand All @@ -70,7 +64,7 @@ abstract class _$$LocateOnMapStateImplCopyWith<$Res>
__$$LocateOnMapStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({bool loading, CameraPosition? centerPosition});
$Res call({CameraPosition? centerPosition});
}

/// @nodoc
Expand All @@ -84,14 +78,9 @@ class __$$LocateOnMapStateImplCopyWithImpl<$Res>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? loading = null,
Object? centerPosition = freezed,
}) {
return _then(_$LocateOnMapStateImpl(
loading: null == loading
? _value.loading
: loading // ignore: cast_nullable_to_non_nullable
as bool,
centerPosition: freezed == centerPosition
? _value.centerPosition
: centerPosition // ignore: cast_nullable_to_non_nullable
Expand All @@ -103,31 +92,27 @@ class __$$LocateOnMapStateImplCopyWithImpl<$Res>
/// @nodoc
class _$LocateOnMapStateImpl implements _LocateOnMapState {
const _$LocateOnMapStateImpl({this.loading = false, this.centerPosition});
const _$LocateOnMapStateImpl({this.centerPosition});

@override
@JsonKey()
final bool loading;
@override
final CameraPosition? centerPosition;

@override
String toString() {
return 'LocateOnMapState(loading: $loading, centerPosition: $centerPosition)';
return 'LocateOnMapState(centerPosition: $centerPosition)';
}

@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$LocateOnMapStateImpl &&
(identical(other.loading, loading) || other.loading == loading) &&
(identical(other.centerPosition, centerPosition) ||
other.centerPosition == centerPosition));
}

@override
int get hashCode => Object.hash(runtimeType, loading, centerPosition);
int get hashCode => Object.hash(runtimeType, centerPosition);

@JsonKey(ignore: true)
@override
Expand All @@ -138,12 +123,9 @@ class _$LocateOnMapStateImpl implements _LocateOnMapState {
}

abstract class _LocateOnMapState implements LocateOnMapState {
const factory _LocateOnMapState(
{final bool loading,
final CameraPosition? centerPosition}) = _$LocateOnMapStateImpl;
const factory _LocateOnMapState({final CameraPosition? centerPosition}) =
_$LocateOnMapStateImpl;

@override
bool get loading;
@override
CameraPosition? get centerPosition;
@override
Expand Down
91 changes: 49 additions & 42 deletions app/lib/ui/flow/geofence/add/placename/choose_place_name_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:yourspace_flutter/ui/flow/geofence/add/placename/choose_place_na

import '../../../../../domain/extenstions/widget_extensions.dart';
import '../../../../../gen/assets.gen.dart';
import '../../../../components/error_snakebar.dart';
import '../../../home/map/map_view.dart';

class ChoosePlaceNameView extends ConsumerStatefulWidget {
Expand Down Expand Up @@ -45,36 +46,34 @@ class _ChoosePlaceNameViewState extends ConsumerState<ChoosePlaceNameView> {

@override
Widget build(BuildContext context) {
final state = ref.watch(choosePlaceViewStateProvider);

_observeError();
_observePopToPlacesListScreen();

return AppPage(
title: context.l10n.choose_place_screen_title,
body: _body(),
);
}

Widget _body() {
final state = ref.watch(choosePlaceViewStateProvider);

return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_searchTextField(),
const SizedBox(height: 40),
Text(
context.l10n.choose_place_suggestion_text,
style: AppTextStyle.caption
.copyWith(color: context.colorScheme.textDisabled),
),
const SizedBox(height: 16),
_suggestionsView(state.suggestions),
const Spacer(),
Align(
alignment: Alignment.center,
child: _addPlaceView(state),
)
],
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_searchTextField(),
const SizedBox(height: 40),
Text(
context.l10n.choose_place_suggestion_text,
style: AppTextStyle.caption
.copyWith(color: context.colorScheme.textDisabled),
),
const SizedBox(height: 16),
_suggestionsView(state.suggestions),
const Spacer(),
Align(
alignment: Alignment.center,
child: _addPlaceButtonView(state),
)
],
),
),
);
}
Expand All @@ -84,6 +83,13 @@ class _ChoosePlaceNameViewState extends ConsumerState<ChoosePlaceNameView> {
children: [
TextField(
controller: _textController,
onChanged: (value) {
if (value.isEmpty) {
setState(() {
_textController.text = '';
});
}
},
style: AppTextStyle.subtitle3,
decoration: InputDecoration(
prefixIcon: Padding(
Expand All @@ -98,19 +104,12 @@ class _ChoosePlaceNameViewState extends ConsumerState<ChoosePlaceNameView> {
color: context.colorScheme.textDisabled,
),
contentPadding: const EdgeInsets.symmetric(vertical: 0),
prefixIconConstraints: const BoxConstraints(
minHeight: 0,
minWidth: 0,
),
border: UnderlineInputBorder(
borderSide: BorderSide(
color: context.colorScheme.textDisabled,
),
prefixIconConstraints: const BoxConstraints(),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: context.colorScheme.outline),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: context.colorScheme.primary,
),
borderSide: BorderSide(color: context.colorScheme.primary),
),
),
),
Expand All @@ -136,9 +135,7 @@ class _ChoosePlaceNameViewState extends ConsumerState<ChoosePlaceNameView> {
style: AppTextStyle.body2
.copyWith(color: context.colorScheme.textSecondary),
),
labelPadding: const EdgeInsets.symmetric(
horizontal: 16,
),
labelPadding: const EdgeInsets.symmetric(horizontal: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30),
),
Expand All @@ -150,8 +147,9 @@ class _ChoosePlaceNameViewState extends ConsumerState<ChoosePlaceNameView> {
);
}

Widget _addPlaceView(ChoosePlaceViewState state) {
Widget _addPlaceButtonView(ChoosePlaceViewState state) {
final enable = _textController.text.isNotEmpty && !state.addingPlace;

return Padding(
padding: EdgeInsets.only(bottom: context.mediaQueryPadding.bottom + 24),
child: PrimaryButton(
Expand All @@ -167,6 +165,15 @@ class _ChoosePlaceNameViewState extends ConsumerState<ChoosePlaceNameView> {
);
}

void _observeError() {
ref.listen(choosePlaceViewStateProvider.select((state) => state.error),
(previous, next) {
if (next != null) {
showErrorSnackBar(context, next.toString());
}
});
}

void _observePopToPlacesListScreen() {
ref.listen(
choosePlaceViewStateProvider.select((state) => state.popToPlaceList),
Expand Down
Loading

0 comments on commit fc179a7

Please sign in to comment.