Last active
August 14, 2024 19:07
-
-
Save eernstg/32325b7ff1ebdc4961cbf622ca2377c3 to your computer and use it in GitHub Desktop.
Variant of detail_page.dart that uses several hypothetical features of Dart to reduce verbosity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart' show Divider; | |
import 'package:landmarks/widgets/favorite_button.dart'; | |
import '../model/landmarks_model.dart'; | |
import '../model/landmark.dart'; | |
import '../widgets/circle_image.dart'; | |
import '../widgets/map_view.dart'; | |
extension on BuildContext { | |
TextStyle textStyleWith({color in CupertinoColors, ...}) ==> | |
CupertinoTheme.of(this).textTheme.textStyle.copyWith; | |
} | |
class DetailPage extends StatelessWidget { | |
final Landmark landmark; | |
const DetailPage({super.key, this.landmark}); | |
override build(context) { | |
return CupertinoPageScaffold( | |
navigationBar: CupertinoNavigationBar( | |
middle: Text(landmark.name), | |
previousPageTitle: 'Landmarks', | |
), | |
SingleChildScrollView( | |
Column( | |
[ | |
Stack( | |
alignment: .topStart, | |
[ | |
MapView(height: 300, coordinates: landmark.coordinates), | |
Padding( | |
padding: const .fromLTRB(0, 170, 0, 0), | |
Center(CircleImage(image: landmark.image)), | |
), | |
], | |
), | |
Padding( | |
padding: const .all(16), | |
Column( | |
mainAxisSize: .min, | |
crossAxisAlignment: .start, | |
[ | |
Row( | |
[ | |
Text(landmark.name, | |
style: context.textStyleWith(fontSize: 25)), | |
Padding( | |
padding: const .symmetric(horizontal: 10), | |
FavoriteButton( | |
isSet: landmark.isFavorite, | |
onTap: () { | |
LandmarksModel.of(context).updateLandmark( | |
landmark.id, | |
landmark.copyWith( | |
isFavorite: !landmark.isFavorite)); | |
}, | |
), | |
) | |
], | |
), | |
Row( | |
[ | |
Text(landmark.park, | |
style: context.textStyleWith( | |
fontSize: 15, color: .systemGrey)), | |
const Spacer(), | |
Text(landmark.state, | |
style: context.textStyleWith( | |
fontSize: 15, color: .systemGrey)), | |
], | |
), | |
const Divider(), | |
Text('About ${landmark.name}', | |
style: context.textStyleWith(fontSize: 22)), | |
Flexible( | |
Text(landmark.description, | |
style: context.textStyleWith(fontSize: 17)), | |
), | |
], | |
), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumed hypothetical language features used in this example:
Forwarding functions, github.com/dart-lang/language/issues/3444,
needed for
textStyleWith
.Parameter default scopes, github.com/dart-lang/language/issues/3834,
needed to allow
.systemGrey
rather thanCupertinoColors.systemGrey
.Also needed to similarly omit other scope names.
AlignmentDirectional.topStart
: Many ways to do this.EdgeInsets.fromLTRB
: Can use static extension and default scope.EdgeInsets.all
,EdgeInsets.symmetric
: Similar.MainAxisSize.min
,CrossAxisAlignment.start
: Trivial.Inferred
required
,https://com/dart-lang/language/blob/main/working/0015-infer-required/feature-specification.md,
needed to omit
required
in constructor.Optionally named parameters, github.com/dart-lang/language/issues/831,
needed in order to omit
child:
andchildren:
(other proposals could do this, too).