mirror of
https://github.com/flutter/samples.git
synced 2026-07-12 03:52:29 +00:00
Flutter 3.29 beta (#2571)
This commit is contained in:
@@ -62,10 +62,7 @@ class ServingInfoChart extends StatelessWidget {
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Text(
|
||||
'Calories',
|
||||
style: Styles.detailsServingLabelText(themeData),
|
||||
),
|
||||
Text('Calories', style: Styles.detailsServingLabelText(themeData)),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'${veggie.caloriesPerServing} kCal',
|
||||
@@ -78,30 +75,18 @@ class ServingInfoChart extends StatelessWidget {
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Text(
|
||||
'Vitamin A',
|
||||
style: Styles.detailsServingLabelText(themeData),
|
||||
),
|
||||
Text('Vitamin A', style: Styles.detailsServingLabelText(themeData)),
|
||||
const Spacer(),
|
||||
_buildVitaminText(
|
||||
veggie.vitaminAPercentage,
|
||||
prefs.desiredCalories,
|
||||
),
|
||||
_buildVitaminText(veggie.vitaminAPercentage, prefs.desiredCalories),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Text(
|
||||
'Vitamin C',
|
||||
style: Styles.detailsServingLabelText(themeData),
|
||||
),
|
||||
Text('Vitamin C', style: Styles.detailsServingLabelText(themeData)),
|
||||
const Spacer(),
|
||||
_buildVitaminText(
|
||||
veggie.vitaminCPercentage,
|
||||
prefs.desiredCalories,
|
||||
),
|
||||
_buildVitaminText(veggie.vitaminCPercentage, prefs.desiredCalories),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
@@ -139,20 +124,14 @@ class InfoView extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
veggie.name,
|
||||
style: Styles.detailsTitleText(themeData),
|
||||
),
|
||||
Text(veggie.name, style: Styles.detailsTitleText(themeData)),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
veggie.shortDescription,
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Seasons',
|
||||
style: Styles.detailsServingLabelText(themeData),
|
||||
),
|
||||
Text('Seasons', style: Styles.detailsServingLabelText(themeData)),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
@@ -164,17 +143,19 @@ class InfoView extends StatelessWidget {
|
||||
children: [
|
||||
Icon(
|
||||
Styles.seasonIconData[season],
|
||||
color: veggie.seasons.contains(season)
|
||||
? Styles.seasonColors[season]
|
||||
: const Color.fromRGBO(128, 128, 128, 1),
|
||||
color:
|
||||
veggie.seasons.contains(season)
|
||||
? Styles.seasonColors[season]
|
||||
: const Color.fromRGBO(128, 128, 128, 1),
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
season.name.characters.first.toUpperCase() +
|
||||
season.name.characters.skip(1).string,
|
||||
style: Styles.minorText(CupertinoTheme.of(context))
|
||||
.copyWith(fontSize: 11),
|
||||
style: Styles.minorText(
|
||||
CupertinoTheme.of(context),
|
||||
).copyWith(fontSize: 11),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -227,37 +208,37 @@ class DetailsScreen extends StatelessWidget {
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ShareButton(
|
||||
() {
|
||||
showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return CupertinoActionSheet(
|
||||
title: Text('Share ${veggie.name}'),
|
||||
message: Text(veggie.shortDescription),
|
||||
actions: [
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
ShareButton(() {
|
||||
showCupertinoModalPopup<void>(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return CupertinoActionSheet(
|
||||
title: Text('Share ${veggie.name}'),
|
||||
message: Text(veggie.shortDescription),
|
||||
actions: [
|
||||
CupertinoActionSheetAction(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('OK'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}),
|
||||
const SizedBox(width: 8),
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final appState = Provider.of<AppState>(context);
|
||||
final veggie = appState.getVeggie(id);
|
||||
|
||||
return FavoriteButton(
|
||||
() => appState.setFavorite(id, !veggie.isFavorite),
|
||||
veggie.isFavorite,
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Builder(builder: (context) {
|
||||
final appState = Provider.of<AppState>(context);
|
||||
final veggie = appState.getVeggie(id);
|
||||
|
||||
return FavoriteButton(
|
||||
() => appState.setFavorite(id, !veggie.isFavorite),
|
||||
veggie.isFavorite,
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -25,25 +25,26 @@ class FavoritesScreen extends StatelessWidget {
|
||||
middle: Text('My Garden'),
|
||||
),
|
||||
child: Center(
|
||||
child: model.favoriteVeggies.isEmpty
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Text(
|
||||
'You haven\'t added any favorite veggies to your garden yet.',
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
child:
|
||||
model.favoriteVeggies.isEmpty
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Text(
|
||||
'You haven\'t added any favorite veggies to your garden yet.',
|
||||
style: CupertinoTheme.of(context).textTheme.textStyle,
|
||||
),
|
||||
)
|
||||
: ListView(
|
||||
restorationId: 'list',
|
||||
children: [
|
||||
const SizedBox(height: 24),
|
||||
for (Veggie veggie in model.favoriteVeggies)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 24),
|
||||
child: VeggieHeadline(veggie),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: ListView(
|
||||
restorationId: 'list',
|
||||
children: [
|
||||
const SizedBox(height: 24),
|
||||
for (Veggie veggie in model.favoriteVeggies)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 24),
|
||||
child: VeggieHeadline(veggie),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -16,16 +16,20 @@ class ListScreen extends StatelessWidget {
|
||||
|
||||
final String? restorationId;
|
||||
|
||||
Widget _generateVeggieCard(Veggie veggie, Preferences prefs,
|
||||
{bool inSeason = true}) {
|
||||
Widget _generateVeggieCard(
|
||||
Veggie veggie,
|
||||
Preferences prefs, {
|
||||
bool inSeason = true,
|
||||
}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 16, right: 16, bottom: 24),
|
||||
child: FutureBuilder<Set<VeggieCategory>>(
|
||||
future: prefs.preferredCategories,
|
||||
builder: (context, snapshot) {
|
||||
final data = snapshot.data ?? <VeggieCategory>{};
|
||||
return VeggieCard(veggie, inSeason, data.contains(veggie.category));
|
||||
}),
|
||||
future: prefs.preferredCategories,
|
||||
builder: (context, snapshot) {
|
||||
final data = snapshot.data ?? <VeggieCategory>{};
|
||||
return VeggieCard(veggie, inSeason, data.contains(veggie.category));
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -39,7 +43,8 @@ class ListScreen extends StatelessWidget {
|
||||
final themeData = CupertinoTheme.of(context);
|
||||
return AnnotatedRegion<SystemUiOverlayStyle>(
|
||||
value: SystemUiOverlayStyle(
|
||||
statusBarBrightness: MediaQuery.platformBrightnessOf(context)),
|
||||
statusBarBrightness: MediaQuery.platformBrightnessOf(context),
|
||||
),
|
||||
child: SafeArea(
|
||||
bottom: false,
|
||||
child: ListView.builder(
|
||||
@@ -49,8 +54,10 @@ class ListScreen extends StatelessWidget {
|
||||
if (index == 0) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 24, 16, 16),
|
||||
child: Text('In season today',
|
||||
style: Styles.headlineText(themeData)),
|
||||
child: Text(
|
||||
'In season today',
|
||||
style: Styles.headlineText(themeData),
|
||||
),
|
||||
);
|
||||
} else if (index <= appState.availableVeggies.length) {
|
||||
return _generateVeggieCard(
|
||||
@@ -60,15 +67,19 @@ class ListScreen extends StatelessWidget {
|
||||
} else if (index <= appState.availableVeggies.length + 1) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 24, 16, 16),
|
||||
child: Text('Not in season',
|
||||
style: Styles.headlineText(themeData)),
|
||||
child: Text(
|
||||
'Not in season',
|
||||
style: Styles.headlineText(themeData),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
var relativeIndex =
|
||||
index - (appState.availableVeggies.length + 2);
|
||||
return _generateVeggieCard(
|
||||
appState.unavailableVeggies[relativeIndex], prefs,
|
||||
inSeason: false);
|
||||
appState.unavailableVeggies[relativeIndex],
|
||||
prefs,
|
||||
inSeason: false,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
|
||||
@@ -58,10 +58,7 @@ class VeggieCategorySettingsScreen extends StatelessWidget {
|
||||
},
|
||||
);
|
||||
} else {
|
||||
toggle = const CupertinoSwitch(
|
||||
value: false,
|
||||
onChanged: null,
|
||||
);
|
||||
toggle = const CupertinoSwitch(value: false, onChanged: null);
|
||||
}
|
||||
|
||||
tiles.add(
|
||||
@@ -136,9 +133,10 @@ class CalorieSettingsScreen extends StatelessWidget {
|
||||
: Styles.transparentColor,
|
||||
backgroundColor: Styles.transparentColor,
|
||||
),
|
||||
onTap: snapshot.hasData
|
||||
? () => model.setDesiredCalories(cals)
|
||||
: null,
|
||||
onTap:
|
||||
snapshot.hasData
|
||||
? () => model.setDesiredCalories(cals)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -147,12 +145,14 @@ class CalorieSettingsScreen extends StatelessWidget {
|
||||
header: Text(
|
||||
'Available calorie levels'.toUpperCase(),
|
||||
style: Styles.settingsGroupHeaderText(
|
||||
CupertinoTheme.of(context)),
|
||||
CupertinoTheme.of(context),
|
||||
),
|
||||
),
|
||||
footer: Text(
|
||||
'These are used for serving calculations',
|
||||
style: Styles.settingsGroupFooterText(
|
||||
CupertinoTheme.of(context)),
|
||||
CupertinoTheme.of(context),
|
||||
),
|
||||
),
|
||||
children: tiles,
|
||||
);
|
||||
@@ -176,7 +176,9 @@ class SettingsScreen extends StatefulWidget {
|
||||
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
CupertinoListTile _buildCaloriesTile(
|
||||
BuildContext context, Preferences prefs) {
|
||||
BuildContext context,
|
||||
Preferences prefs,
|
||||
) {
|
||||
return CupertinoListTile.notched(
|
||||
leading: const SettingsIcon(
|
||||
backgroundColor: CupertinoColors.systemBlue,
|
||||
@@ -198,7 +200,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
}
|
||||
|
||||
CupertinoListTile _buildCategoriesTile(
|
||||
BuildContext context, Preferences prefs) {
|
||||
BuildContext context,
|
||||
Preferences prefs,
|
||||
) {
|
||||
return CupertinoListTile.notched(
|
||||
leading: const SettingsIcon(
|
||||
backgroundColor: CupertinoColors.systemOrange,
|
||||
@@ -211,7 +215,9 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
}
|
||||
|
||||
CupertinoListTile _buildRestoreDefaultsTile(
|
||||
BuildContext context, Preferences prefs) {
|
||||
BuildContext context,
|
||||
Preferences prefs,
|
||||
) {
|
||||
return CupertinoListTile.notched(
|
||||
leading: const SettingsIcon(
|
||||
backgroundColor: CupertinoColors.systemRed,
|
||||
@@ -221,28 +227,29 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
onTap: () {
|
||||
showCupertinoDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => CupertinoAlertDialog(
|
||||
title: const Text('Are you sure?'),
|
||||
content: const Text(
|
||||
'Are you sure you want to reset the current settings?',
|
||||
),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
isDestructiveAction: true,
|
||||
child: const Text('Yes'),
|
||||
onPressed: () async {
|
||||
await prefs.restoreDefaults();
|
||||
if (!context.mounted) return;
|
||||
context.pop();
|
||||
},
|
||||
builder:
|
||||
(context) => CupertinoAlertDialog(
|
||||
title: const Text('Are you sure?'),
|
||||
content: const Text(
|
||||
'Are you sure you want to reset the current settings?',
|
||||
),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
isDestructiveAction: true,
|
||||
child: const Text('Yes'),
|
||||
onPressed: () async {
|
||||
await prefs.restoreDefaults();
|
||||
if (!context.mounted) return;
|
||||
context.pop();
|
||||
},
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
isDefaultAction: true,
|
||||
child: const Text('No'),
|
||||
onPressed: () => context.pop(),
|
||||
),
|
||||
],
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
isDefaultAction: true,
|
||||
child: const Text('No'),
|
||||
onPressed: () => context.pop(),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
@@ -253,29 +260,24 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
||||
final prefs = Provider.of<Preferences>(context);
|
||||
|
||||
return CupertinoPageScaffold(
|
||||
backgroundColor:
|
||||
Styles.scaffoldBackground(CupertinoTheme.brightnessOf(context)),
|
||||
backgroundColor: Styles.scaffoldBackground(
|
||||
CupertinoTheme.brightnessOf(context),
|
||||
),
|
||||
child: CustomScrollView(
|
||||
slivers: <Widget>[
|
||||
const CupertinoSliverNavigationBar(
|
||||
largeTitle: Text('Settings'),
|
||||
),
|
||||
const CupertinoSliverNavigationBar(largeTitle: Text('Settings')),
|
||||
SliverList(
|
||||
delegate: SliverChildListDelegate(
|
||||
[
|
||||
CupertinoListSection.insetGrouped(
|
||||
children: [
|
||||
_buildCaloriesTile(context, prefs),
|
||||
_buildCategoriesTile(context, prefs),
|
||||
],
|
||||
),
|
||||
CupertinoListSection.insetGrouped(
|
||||
children: [
|
||||
_buildRestoreDefaultsTile(context, prefs),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
delegate: SliverChildListDelegate([
|
||||
CupertinoListSection.insetGrouped(
|
||||
children: [
|
||||
_buildCaloriesTile(context, prefs),
|
||||
_buildCategoriesTile(context, prefs),
|
||||
],
|
||||
),
|
||||
CupertinoListSection.insetGrouped(
|
||||
children: [_buildRestoreDefaultsTile(context, prefs)],
|
||||
),
|
||||
]),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -302,13 +304,7 @@ class SettingsIcon extends StatelessWidget {
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
color: backgroundColor,
|
||||
),
|
||||
child: Center(
|
||||
child: Icon(
|
||||
icon,
|
||||
color: foregroundColor,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
child: Center(child: Icon(icon, color: foregroundColor, size: 20)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user