1
0
mirror of https://github.com/flutter/samples.git synced 2026-06-01 11:59:03 +00:00

Flutter 3.29 beta (#2571)

This commit is contained in:
Eric Windmill
2025-02-12 18:08:01 -05:00
committed by GitHub
parent d62c784789
commit 719fd72c38
685 changed files with 76244 additions and 53721 deletions

View File

@@ -18,8 +18,8 @@ class ResultsViewModel extends ChangeNotifier {
ResultsViewModel({
required DestinationRepository destinationRepository,
required ItineraryConfigRepository itineraryConfigRepository,
}) : _destinationRepository = destinationRepository,
_itineraryConfigRepository = itineraryConfigRepository {
}) : _destinationRepository = destinationRepository,
_itineraryConfigRepository = itineraryConfigRepository {
updateItineraryConfig = Command1<void, String>(_updateItineraryConfig);
search = Command0(_search)..execute();
}
@@ -67,10 +67,13 @@ class ResultsViewModel extends ChangeNotifier {
case Ok():
{
// If the result is Ok, update the list of destinations
_destinations = result.value
.where((destination) =>
destination.continent == _itineraryConfig!.continent)
.toList();
_destinations =
result.value
.where(
(destination) =>
destination.continent == _itineraryConfig!.continent,
)
.toList();
_log.fine('Destinations (${_destinations.length}) loaded');
}
case Error():
@@ -99,16 +102,11 @@ class ResultsViewModel extends ChangeNotifier {
}
final itineraryConfig = resultConfig.value;
final result = await _itineraryConfigRepository
.setItineraryConfig(itineraryConfig.copyWith(
destination: destinationRef,
activities: [],
));
final result = await _itineraryConfigRepository.setItineraryConfig(
itineraryConfig.copyWith(destination: destinationRef, activities: []),
);
if (result is Error) {
_log.warning(
'Failed to store ItineraryConfig',
result.error,
);
_log.warning('Failed to store ItineraryConfig', result.error);
}
return result;
}

View File

@@ -10,11 +10,7 @@ import '../../../utils/image_error_listener.dart';
import '../../core/ui/tag_chip.dart';
class ResultCard extends StatelessWidget {
const ResultCard({
super.key,
required this.destination,
required this.onTap,
});
const ResultCard({super.key, required this.destination, required this.onTap});
final Destination destination;
final GestureTapCallback onTap;
@@ -40,13 +36,8 @@ class ResultCard extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
destination.name.toUpperCase(),
style: _cardTitleStyle,
),
const SizedBox(
height: 6,
),
Text(destination.name.toUpperCase(), style: _cardTitleStyle),
const SizedBox(height: 6),
Wrap(
spacing: 4.0,
runSpacing: 4.0,
@@ -61,9 +52,7 @@ class ResultCard extends StatelessWidget {
Positioned.fill(
child: Material(
color: Colors.transparent,
child: InkWell(
onTap: onTap,
),
child: InkWell(onTap: onTap),
),
),
],
@@ -80,10 +69,7 @@ final _cardTitleStyle = GoogleFonts.rubik(
letterSpacing: 1,
shadows: [
// Helps to read the text a bit better
Shadow(
blurRadius: 3.0,
color: Colors.black,
)
Shadow(blurRadius: 3.0, color: Colors.black),
],
),
);

View File

@@ -14,10 +14,7 @@ import '../view_models/results_viewmodel.dart';
import 'result_card.dart';
class ResultsScreen extends StatefulWidget {
const ResultsScreen({
super.key,
required this.viewModel,
});
const ResultsScreen({super.key, required this.viewModel});
final ResultsViewModel viewModel;
@@ -64,13 +61,16 @@ class _ResultsScreenState extends State<ResultsScreen> {
_AppSearchBar(widget: widget),
if (widget.viewModel.search.running)
const Expanded(
child: Center(child: CircularProgressIndicator())),
child: Center(child: CircularProgressIndicator()),
),
if (widget.viewModel.search.error)
Expanded(
child: Center(
child: ErrorIndicator(
title: AppLocalization.of(context)
.errorWhileLoadingDestinations,
title:
AppLocalization.of(
context,
).errorWhileLoadingDestinations,
label: AppLocalization.of(context).tryAgain,
onPressed: widget.viewModel.search.execute,
),
@@ -86,9 +86,7 @@ class _ResultsScreenState extends State<ResultsScreen> {
padding: Dimens.of(context).edgeInsetsScreenHorizontal,
child: CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: _AppSearchBar(widget: widget),
),
SliverToBoxAdapter(child: _AppSearchBar(widget: widget)),
_Grid(viewModel: widget.viewModel),
],
),
@@ -118,9 +116,7 @@ class _ResultsScreenState extends State<ResultsScreen> {
}
class _AppSearchBar extends StatelessWidget {
const _AppSearchBar({
required this.widget,
});
const _AppSearchBar({required this.widget});
final ResultsScreen widget;
@@ -147,9 +143,7 @@ class _AppSearchBar extends StatelessWidget {
}
class _Grid extends StatelessWidget {
const _Grid({
required this.viewModel,
});
const _Grid({required this.viewModel});
final ResultsViewModel viewModel;
@@ -162,19 +156,16 @@ class _Grid extends StatelessWidget {
mainAxisSpacing: 8.0,
childAspectRatio: 182 / 222,
),
delegate: SliverChildBuilderDelegate(
(context, index) {
final destination = viewModel.destinations[index];
return ResultCard(
key: ValueKey(destination.ref),
destination: destination,
onTap: () {
viewModel.updateItineraryConfig.execute(destination.ref);
},
);
},
childCount: viewModel.destinations.length,
),
delegate: SliverChildBuilderDelegate((context, index) {
final destination = viewModel.destinations[index];
return ResultCard(
key: ValueKey(destination.ref),
destination: destination,
onTap: () {
viewModel.updateItineraryConfig.execute(destination.ref);
},
);
}, childCount: viewModel.destinations.length),
);
}
}