Skip to content

Instantly share code, notes, and snippets.

@eernstg
Last active August 14, 2024 19:07
Show Gist options
  • Save eernstg/32325b7ff1ebdc4961cbf622ca2377c3 to your computer and use it in GitHub Desktop.
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
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)),
),
],
),
),
],
),
),
);
}
}
@eernstg
Copy link
Author

eernstg commented Aug 14, 2024

Assumed hypothetical language features used in this example:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment