Skip to content

Commit

Permalink
improve widget trees
Browse files Browse the repository at this point in the history
  • Loading branch information
BenjaminCanape committed Feb 10, 2024
1 parent 1b480a6 commit f8145fe
Show file tree
Hide file tree
Showing 13 changed files with 123 additions and 112 deletions.
4 changes: 3 additions & 1 deletion lib/presentation/common/activity/widgets/activity_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class ActivityItem extends HookConsumerWidget {
final state = ref.watch(activityItemViewModelProvider(activity.id));

final List<Color> colors = ColorUtils.generateColorTupleFromIndex(index);
final titleColor = colors.first;

final startColor = colors.first;
final endColor = colors.last;
const double borderRadius = 24;
Expand Down Expand Up @@ -111,7 +113,7 @@ class ActivityItem extends HookConsumerWidget {
ActivityItemDetails(
displayUserName: displayUserName,
activity: activity,
color: startColor),
color: titleColor),
],
),
),
Expand Down
1 change: 1 addition & 0 deletions lib/presentation/common/core/widgets/share_map_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class ShareMapButton extends HookConsumerWidget {
}

return FloatingActionButton(
heroTag: 'share_button',
onPressed: () async {
try {
Uint8List? image = await ImageUtils.captureWidgetToImage(boundaryKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ import '../../timer/viewmodel/timer_view_model.dart';
import 'state/location_state.dart';

/// Provider for the [LocationViewModel].
final locationViewModelProvider =
/*final locationViewModelProvider =
StateNotifierProvider.autoDispose<LocationViewModel, LocationState>(
(ref) => LocationViewModel(ref),
);*/

final locationViewModelProvider =
StateNotifierProvider<LocationViewModel, LocationState>(
(ref) => LocationViewModel(ref),
);

/// View model for managing location-related functionality.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ class CurrentLocationMap extends HookConsumerWidget {
);
}

return LocationMap(points: points, markers: markers);
return Expanded(child: LocationMap(points: points, markers: markers));
}
}
46 changes: 22 additions & 24 deletions lib/presentation/common/location/widgets/location_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,29 @@ class LocationMap extends HookConsumerWidget {
final center = MapUtils.getCenterOfMap(points);
final zoomLevel = MapUtils.getZoomLevel(points, center);

return Expanded(
child: SizedBox(
height: 500,
child: FlutterMap(
mapController: provider.mapController,
options: MapOptions(
initialCenter: points.isNotEmpty
? center
: LatLng(state.currentPosition?.latitude ?? 0,
state.currentPosition?.longitude ?? 0),
initialZoom: zoomLevel,
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
),
PolylineLayer(
polylines: [
Polyline(
points: points, strokeWidth: 4, color: ColorUtils.blueGrey),
],
),
MarkerLayer(markers: markers),
],
return SizedBox(
height: 500,
child: FlutterMap(
mapController: provider.mapController,
options: MapOptions(
initialCenter: points.isNotEmpty
? center
: LatLng(state.currentPosition?.latitude ?? 0,
state.currentPosition?.longitude ?? 0),
initialZoom: zoomLevel,
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
),
PolylineLayer(
polylines: [
Polyline(
points: points, strokeWidth: 4, color: ColorUtils.blueGrey),
],
),
MarkerLayer(markers: markers),
],
),
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/presentation/common/timer/viewmodel/timer_view_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class TimerViewModel extends StateNotifier<TimerState> {
final distance = metricsProvider.distance;
final globalSpeed = metricsProvider.globalSpeed;

ref.read(locationViewModelProvider.notifier).cancelLocationStream();

var textToSay = StringBuffer();

textToSay.write('${l10nConf.congrats}.');
Expand Down Expand Up @@ -101,8 +103,6 @@ class TimerViewModel extends StateNotifier<TimerState> {
"${l10nConf.speed}: $km,$meters ${l10nConf.kilometers} ${l10nConf.per} ${l10nConf.hours}");

await ref.read(textToSpeechService).say(textToSay.toString());

ref.read(locationViewModelProvider.notifier).cancelLocationStream();
}

void resetTimerState() {
Expand Down
1 change: 1 addition & 0 deletions lib/presentation/common/timer/widgets/timer_pause.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class TimerPause extends HookConsumerWidget {
);
},
child: FloatingActionButton(
heroTag: 'pause_resume_button',
backgroundColor: ColorUtils.main,
key: ValueKey<bool>(isRunning),
tooltip: timerViewModel.isTimerRunning() ? 'Pause' : 'Resume',
Expand Down
1 change: 1 addition & 0 deletions lib/presentation/common/timer/widgets/timer_start.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TimerStart extends HookConsumerWidget {
final timerViewModel = ref.watch(timerViewModelProvider.notifier);

return FloatingActionButton(
heroTag: 'start_button',
backgroundColor:
timerViewModel.hasTimerStarted() ? ColorUtils.red : ColorUtils.main,
elevation: 4.0,
Expand Down
107 changes: 54 additions & 53 deletions lib/presentation/common/user/screens/profile_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,35 @@ class ProfileScreen extends HookConsumerWidget {

var activitiesStateProvider = ref.watch(activitiesDataFutureProvider(user));

return state.isLoading
? Expanded(child: Center(child: UIUtils.loader))
: Scaffold(
body: SafeArea(
child: Column(
return Scaffold(
body: SafeArea(
child: state.isLoading
? Expanded(child: Center(child: UIUtils.loader))
: Column(
children: [
Container(
padding:
const EdgeInsets.only(left: 16, top: 16, right: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(150),
child: Container(
alignment: Alignment.center,
width: 150,
height: 150,
child: profilePicture != null
? Image.memory(
profilePicture,
fit: BoxFit.cover,
)
: const Icon(Icons.person, size: 100),
),
padding:
const EdgeInsets.only(left: 16, top: 16, right: 16),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(150),
child: Container(
alignment: Alignment.center,
width: 150,
height: 150,
child: profilePicture != null
? Image.memory(
profilePicture,
fit: BoxFit.cover,
)
: const Icon(Icons.person, size: 100),
),
Flexible(
child: Column(children: [
),
Expanded(
child: Column(
children: [
Text(
UserUtils.getNameOrUsername(user),
style: const TextStyle(
Expand All @@ -93,38 +94,37 @@ class ProfileScreen extends HookConsumerWidget {
return widget;
},
loading: () {
return Expanded(
child: Center(child: UIUtils.loader));
return Center(child: UIUtils.loader);
},
error: (error, stackTrace) {
return Text('$error');
},
)
]),
],
),
],
)),
),
],
),
),
const Divider(),
const SizedBox(height: 20),
Expanded(
child: RefreshIndicator(
key: _refreshIndicatorKey,
onRefresh: () async {
provider.refreshList();
return ref
.refresh(activitiesDataFutureProvider(user));
},
child: Column(children: [
key: _refreshIndicatorKey,
onRefresh: () async {
provider.refreshList();
return ref.refresh(activitiesDataFutureProvider(user));
},
child: Column(
children: [
activitiesStateProvider.when(
data: (initialData) {
return ActivityList(
id:
'${InfiniteScrollListEnum.profile}_${user.id}',
activities: initialData.list,
total: initialData.total,
canOpenActivity: false,
bottomListScrollFct:
provider.fetchActivities);
id: '${InfiniteScrollListEnum.profile}_${user.id}',
activities: initialData.list,
total: initialData.total,
canOpenActivity: false,
bottomListScrollFct: provider.fetchActivities,
);
},
loading: () {
return Expanded(
Expand All @@ -133,15 +133,16 @@ class ProfileScreen extends HookConsumerWidget {
error: (error, stackTrace) {
return Text('$error');
},
)
])),
)
),
],
),
),
),
],
),
),
floatingActionButtonLocation:
FloatingActionButtonLocation.centerFloat,
floatingActionButton: UIUtils.createBackButton(context),
);
),
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
floatingActionButton: UIUtils.createBackButton(context),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class BackToHomeButton extends HookConsumerWidget {
final provider = ref.watch(activityListViewModelProvider.notifier);

return FloatingActionButton(
heroTag: 'back_button',
backgroundColor: ColorUtils.main,
elevation: 4.0,
child: Icon(
Expand Down
59 changes: 29 additions & 30 deletions lib/presentation/my_activities/widgets/details_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,40 +81,39 @@ class DetailsTab extends HookConsumerWidget {
}

return Scaffold(
body: Column(
children: [
const SizedBox(height: 10),
state.isEditing
? Column(children: [
ActivityUtils.buildActivityTypeDropdown(
context, selectedType, provider),
const SizedBox(height: 20)
])
: Container(),
Date(date: displayedActivity.startDatetime),
Column(
children: [
const SizedBox(height: 30),
Center(
child: TimerText(timeInMs: displayedActivity.time.toInt()),
),
const SizedBox(height: 15),
Metrics(
distance: displayedActivity.distance,
speed: displayedActivity.speed,
),
],
),
Expanded(
child: RepaintBoundary(
key: state.boundaryKey,
child: LocationMap(points: points, markers: markers),
body: SafeArea(
child: Column(
children: [
const SizedBox(height: 10),
state.isEditing
? Column(children: [
ActivityUtils.buildActivityTypeDropdown(
context, selectedType, provider),
const SizedBox(height: 20)
])
: Container(),
Date(date: displayedActivity.startDatetime),
const SizedBox(height: 30),
Center(
child: TimerText(timeInMs: displayedActivity.time.toInt()),
),
)
],
const SizedBox(height: 15),
Metrics(
distance: displayedActivity.distance,
speed: displayedActivity.speed,
),
Expanded(
child: RepaintBoundary(
key: state.boundaryKey,
child: LocationMap(points: points, markers: markers),
),
)
],
),
),
floatingActionButton: state.isEditing || state.isLoading
? FloatingActionButton(
heroTag: 'save_button',
backgroundColor: ColorUtils.main,
elevation: 4.0,
onPressed: state.isLoading
Expand Down
1 change: 1 addition & 0 deletions lib/presentation/new_activity/widgets/save_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SaveButton extends HookConsumerWidget {
opacity: disabled ? 0.5 : 1.0,
duration: animationDuration,
child: FloatingActionButton(
heroTag: 'save_button',
backgroundColor: ColorUtils.main,
elevation: 4.0,
onPressed: disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class EditPasswordScreen extends HookConsumerWidget {
bottom: 16,
right: 80,
child: FloatingActionButton(
heroTag: 'save_button',
backgroundColor: ColorUtils.main,
elevation: 4.0,
child: Icon(
Expand Down

0 comments on commit f8145fe

Please sign in to comment.