mirror of
https://github.com/flutter/samples.git
synced 2025-11-11 23:39:14 +00:00
[Gallery] Fix directory structure (#312)
This commit is contained in:
294
gallery/lib/studies/crane/model/data.dart
Normal file
294
gallery/lib/studies/crane/model/data.dart
Normal file
@@ -0,0 +1,294 @@
|
||||
// Copyright 2019 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gallery/l10n/gallery_localizations.dart';
|
||||
import 'package:gallery/studies/crane/model/destination.dart';
|
||||
|
||||
// TODO: localize durations
|
||||
|
||||
List<FlyDestination> getFlyDestinations(BuildContext context) =>
|
||||
<FlyDestination>[
|
||||
FlyDestination(
|
||||
id: 0,
|
||||
destination: GalleryLocalizations.of(context).craneFly0,
|
||||
stops: 1,
|
||||
duration: Duration(hours: 6, minutes: 15),
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneFly0SemanticLabel,
|
||||
),
|
||||
FlyDestination(
|
||||
id: 1,
|
||||
destination: GalleryLocalizations.of(context).craneFly1,
|
||||
stops: 0,
|
||||
duration: Duration(hours: 13, minutes: 30),
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneFly1SemanticLabel,
|
||||
),
|
||||
FlyDestination(
|
||||
id: 2,
|
||||
destination: GalleryLocalizations.of(context).craneFly2,
|
||||
stops: 0,
|
||||
duration: Duration(hours: 5, minutes: 16),
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneFly2SemanticLabel,
|
||||
),
|
||||
FlyDestination(
|
||||
id: 3,
|
||||
destination: GalleryLocalizations.of(context).craneFly3,
|
||||
stops: 2,
|
||||
duration: Duration(hours: 19, minutes: 40),
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneFly3SemanticLabel,
|
||||
),
|
||||
FlyDestination(
|
||||
id: 4,
|
||||
destination: GalleryLocalizations.of(context).craneFly4,
|
||||
stops: 0,
|
||||
duration: Duration(hours: 8, minutes: 24),
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneFly4SemanticLabel,
|
||||
),
|
||||
FlyDestination(
|
||||
id: 5,
|
||||
destination: GalleryLocalizations.of(context).craneFly5,
|
||||
stops: 1,
|
||||
duration: Duration(hours: 14, minutes: 12),
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneFly5SemanticLabel,
|
||||
),
|
||||
FlyDestination(
|
||||
id: 6,
|
||||
destination: GalleryLocalizations.of(context).craneFly6,
|
||||
stops: 0,
|
||||
duration: Duration(hours: 5, minutes: 24),
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneFly6SemanticLabel,
|
||||
),
|
||||
FlyDestination(
|
||||
id: 7,
|
||||
destination: GalleryLocalizations.of(context).craneFly7,
|
||||
stops: 1,
|
||||
duration: Duration(hours: 5, minutes: 43),
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneFly7SemanticLabel,
|
||||
),
|
||||
FlyDestination(
|
||||
id: 8,
|
||||
destination: GalleryLocalizations.of(context).craneFly8,
|
||||
stops: 0,
|
||||
duration: Duration(hours: 8, minutes: 25),
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneFly8SemanticLabel,
|
||||
),
|
||||
FlyDestination(
|
||||
id: 9,
|
||||
destination: GalleryLocalizations.of(context).craneFly9,
|
||||
stops: 1,
|
||||
duration: Duration(hours: 15, minutes: 52),
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneFly9SemanticLabel,
|
||||
),
|
||||
FlyDestination(
|
||||
id: 10,
|
||||
destination: GalleryLocalizations.of(context).craneFly10,
|
||||
stops: 0,
|
||||
duration: Duration(hours: 5, minutes: 57),
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneFly10SemanticLabel,
|
||||
),
|
||||
FlyDestination(
|
||||
id: 11,
|
||||
destination: GalleryLocalizations.of(context).craneFly11,
|
||||
stops: 1,
|
||||
duration: Duration(hours: 13, minutes: 24),
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneFly11SemanticLabel,
|
||||
),
|
||||
FlyDestination(
|
||||
id: 12,
|
||||
destination: GalleryLocalizations.of(context).craneFly12,
|
||||
stops: 2,
|
||||
duration: Duration(hours: 10, minutes: 20),
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneFly12SemanticLabel,
|
||||
),
|
||||
FlyDestination(
|
||||
id: 13,
|
||||
destination: GalleryLocalizations.of(context).craneFly13,
|
||||
stops: 0,
|
||||
duration: Duration(hours: 7, minutes: 15),
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneFly13SemanticLabel,
|
||||
),
|
||||
];
|
||||
|
||||
List<SleepDestination> getSleepDestinations(BuildContext context) =>
|
||||
<SleepDestination>[
|
||||
SleepDestination(
|
||||
id: 0,
|
||||
destination: GalleryLocalizations.of(context).craneSleep0,
|
||||
total: 2241,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneSleep0SemanticLabel,
|
||||
),
|
||||
SleepDestination(
|
||||
id: 1,
|
||||
destination: GalleryLocalizations.of(context).craneSleep1,
|
||||
total: 876,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneSleep1SemanticLabel,
|
||||
),
|
||||
SleepDestination(
|
||||
id: 2,
|
||||
destination: GalleryLocalizations.of(context).craneSleep2,
|
||||
total: 1286,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneSleep2SemanticLabel,
|
||||
),
|
||||
SleepDestination(
|
||||
id: 3,
|
||||
destination: GalleryLocalizations.of(context).craneSleep3,
|
||||
total: 496,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneSleep3SemanticLabel,
|
||||
),
|
||||
SleepDestination(
|
||||
id: 4,
|
||||
destination: GalleryLocalizations.of(context).craneSleep4,
|
||||
total: 390,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneSleep4SemanticLabel,
|
||||
),
|
||||
SleepDestination(
|
||||
id: 5,
|
||||
destination: GalleryLocalizations.of(context).craneSleep5,
|
||||
total: 876,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneSleep5SemanticLabel,
|
||||
),
|
||||
SleepDestination(
|
||||
id: 6,
|
||||
destination: GalleryLocalizations.of(context).craneSleep6,
|
||||
total: 989,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneSleep6SemanticLabel,
|
||||
),
|
||||
SleepDestination(
|
||||
id: 7,
|
||||
destination: GalleryLocalizations.of(context).craneSleep7,
|
||||
total: 306,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneSleep7SemanticLabel,
|
||||
),
|
||||
SleepDestination(
|
||||
id: 8,
|
||||
destination: GalleryLocalizations.of(context).craneSleep8,
|
||||
total: 385,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneSleep8SemanticLabel,
|
||||
),
|
||||
SleepDestination(
|
||||
id: 9,
|
||||
destination: GalleryLocalizations.of(context).craneSleep9,
|
||||
total: 989,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneSleep9SemanticLabel,
|
||||
),
|
||||
SleepDestination(
|
||||
id: 10,
|
||||
destination: GalleryLocalizations.of(context).craneSleep10,
|
||||
total: 1380,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneSleep10SemanticLabel,
|
||||
),
|
||||
SleepDestination(
|
||||
id: 11,
|
||||
destination: GalleryLocalizations.of(context).craneSleep11,
|
||||
total: 1109,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneSleep11SemanticLabel,
|
||||
),
|
||||
];
|
||||
|
||||
List<EatDestination> getEatDestinations(BuildContext context) =>
|
||||
<EatDestination>[
|
||||
EatDestination(
|
||||
id: 0,
|
||||
destination: GalleryLocalizations.of(context).craneEat0,
|
||||
total: 354,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneEat0SemanticLabel,
|
||||
),
|
||||
EatDestination(
|
||||
id: 1,
|
||||
destination: GalleryLocalizations.of(context).craneEat1,
|
||||
total: 623,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneEat1SemanticLabel,
|
||||
),
|
||||
EatDestination(
|
||||
id: 2,
|
||||
destination: GalleryLocalizations.of(context).craneEat2,
|
||||
total: 124,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneEat2SemanticLabel,
|
||||
),
|
||||
EatDestination(
|
||||
id: 3,
|
||||
destination: GalleryLocalizations.of(context).craneEat3,
|
||||
total: 495,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneEat3SemanticLabel,
|
||||
),
|
||||
EatDestination(
|
||||
id: 4,
|
||||
destination: GalleryLocalizations.of(context).craneEat4,
|
||||
total: 683,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneEat4SemanticLabel,
|
||||
),
|
||||
EatDestination(
|
||||
id: 5,
|
||||
destination: GalleryLocalizations.of(context).craneEat5,
|
||||
total: 786,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneEat5SemanticLabel,
|
||||
),
|
||||
EatDestination(
|
||||
id: 6,
|
||||
destination: GalleryLocalizations.of(context).craneEat6,
|
||||
total: 323,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneEat6SemanticLabel,
|
||||
),
|
||||
EatDestination(
|
||||
id: 7,
|
||||
destination: GalleryLocalizations.of(context).craneEat7,
|
||||
total: 285,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneEat7SemanticLabel,
|
||||
),
|
||||
EatDestination(
|
||||
id: 8,
|
||||
destination: GalleryLocalizations.of(context).craneEat8,
|
||||
total: 323,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneEat8SemanticLabel,
|
||||
),
|
||||
EatDestination(
|
||||
id: 9,
|
||||
destination: GalleryLocalizations.of(context).craneEat9,
|
||||
total: 1406,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneEat9SemanticLabel,
|
||||
),
|
||||
EatDestination(
|
||||
id: 10,
|
||||
destination: GalleryLocalizations.of(context).craneEat10,
|
||||
total: 849,
|
||||
assetSemanticLabel:
|
||||
GalleryLocalizations.of(context).craneEat10SemanticLabel,
|
||||
),
|
||||
];
|
||||
127
gallery/lib/studies/crane/model/destination.dart
Normal file
127
gallery/lib/studies/crane/model/destination.dart
Normal file
@@ -0,0 +1,127 @@
|
||||
// Copyright 2019 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gallery/data/gallery_options.dart';
|
||||
|
||||
import 'package:gallery/studies/crane/model/formatters.dart';
|
||||
|
||||
import '../../../l10n/gallery_localizations.dart';
|
||||
|
||||
abstract class Destination {
|
||||
const Destination({
|
||||
@required this.id,
|
||||
@required this.destination,
|
||||
@required this.assetSemanticLabel,
|
||||
}) : assert(id != null),
|
||||
assert(destination != null);
|
||||
|
||||
final int id;
|
||||
final String destination;
|
||||
final String assetSemanticLabel;
|
||||
|
||||
String get assetName;
|
||||
|
||||
String subtitle(BuildContext context);
|
||||
String subtitleSemantics(BuildContext context) => subtitle(context);
|
||||
|
||||
@override
|
||||
String toString() => '$destination (id=$id)';
|
||||
}
|
||||
|
||||
class FlyDestination extends Destination {
|
||||
const FlyDestination({
|
||||
@required int id,
|
||||
@required String destination,
|
||||
@required String assetSemanticLabel,
|
||||
@required this.stops,
|
||||
this.duration,
|
||||
}) : assert(stops != null),
|
||||
assert(destination != null),
|
||||
super(
|
||||
id: id,
|
||||
destination: destination,
|
||||
assetSemanticLabel: assetSemanticLabel,
|
||||
);
|
||||
|
||||
final int stops;
|
||||
final Duration duration;
|
||||
|
||||
String get assetName => 'assets/crane/destinations/fly_$id.jpg';
|
||||
|
||||
String subtitle(BuildContext context) {
|
||||
final stopsText = GalleryLocalizations.of(context).craneFlyStops(stops);
|
||||
|
||||
if (duration == null) {
|
||||
return stopsText;
|
||||
} else {
|
||||
final textDirection = GalleryOptions.of(context).textDirection();
|
||||
final durationText =
|
||||
formattedDuration(context, duration, abbreviated: true);
|
||||
return textDirection == TextDirection.ltr
|
||||
? '$stopsText · $durationText'
|
||||
: '$durationText · $stopsText';
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
String subtitleSemantics(BuildContext context) {
|
||||
final stopsText = GalleryLocalizations.of(context).craneFlyStops(stops);
|
||||
|
||||
if (duration == null) {
|
||||
return stopsText;
|
||||
} else {
|
||||
final durationText =
|
||||
formattedDuration(context, duration, abbreviated: false);
|
||||
return '$stopsText, $durationText';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class SleepDestination extends Destination {
|
||||
const SleepDestination({
|
||||
@required int id,
|
||||
@required String destination,
|
||||
@required String assetSemanticLabel,
|
||||
@required this.total,
|
||||
}) : assert(total != null),
|
||||
assert(destination != null),
|
||||
super(
|
||||
id: id,
|
||||
destination: destination,
|
||||
assetSemanticLabel: assetSemanticLabel,
|
||||
);
|
||||
|
||||
final int total;
|
||||
|
||||
String get assetName => 'assets/crane/destinations/sleep_$id.jpg';
|
||||
|
||||
String subtitle(BuildContext context) {
|
||||
return GalleryLocalizations.of(context).craneSleepProperties(total);
|
||||
}
|
||||
}
|
||||
|
||||
class EatDestination extends Destination {
|
||||
const EatDestination({
|
||||
@required int id,
|
||||
@required String destination,
|
||||
@required String assetSemanticLabel,
|
||||
@required this.total,
|
||||
}) : assert(total != null),
|
||||
assert(destination != null),
|
||||
super(
|
||||
id: id,
|
||||
destination: destination,
|
||||
assetSemanticLabel: assetSemanticLabel,
|
||||
);
|
||||
|
||||
final int total;
|
||||
|
||||
String get assetName => 'assets/crane/destinations/eat_$id.jpg';
|
||||
|
||||
String subtitle(BuildContext context) {
|
||||
return GalleryLocalizations.of(context).craneEatRestaurants(total);
|
||||
}
|
||||
}
|
||||
17
gallery/lib/studies/crane/model/formatters.dart
Normal file
17
gallery/lib/studies/crane/model/formatters.dart
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2019 The Flutter team. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gallery/l10n/gallery_localizations.dart';
|
||||
|
||||
// Duration of time (e.g. 16h 12m)
|
||||
String formattedDuration(BuildContext context, Duration duration,
|
||||
{bool abbreviated}) {
|
||||
final hoursShortForm =
|
||||
GalleryLocalizations.of(context).craneHours(duration.inHours.toInt());
|
||||
final minutesShortForm =
|
||||
GalleryLocalizations.of(context).craneMinutes(duration.inMinutes % 60);
|
||||
return GalleryLocalizations.of(context)
|
||||
.craneFlightDuration(hoursShortForm, minutesShortForm);
|
||||
}
|
||||
Reference in New Issue
Block a user