1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-12 07:48:55 +00:00

Landing beta changes in master for the new stable release (#747)

This commit is contained in:
Andrew Brogdon
2021-03-03 11:44:35 -08:00
committed by GitHub
parent 6c81510d6e
commit 8c1cd0b049
101 changed files with 1006 additions and 1040 deletions

View File

@@ -116,7 +116,7 @@ class _PlatformAdaptingHomePageState extends State<PlatformAdaptingHomePage> {
);
default:
assert(false, 'Unexpected tab');
return null;
return SizedBox.shrink();
}
},
);

View File

@@ -22,9 +22,9 @@ class NewsTab extends StatefulWidget {
class _NewsTabState extends State<NewsTab> {
static const _itemsLength = 20;
List<Color> colors;
List<String> titles;
List<String> contents;
late final List<Color> colors;
late final List<String> titles;
late final List<String> contents;
@override
void initState() {
@@ -36,8 +36,6 @@ class _NewsTabState extends State<NewsTab> {
}
Widget _listBuilder(BuildContext context, int index) {
if (index >= _itemsLength) return null;
return SafeArea(
top: false,
bottom: false,
@@ -101,6 +99,7 @@ class _NewsTabState extends State<NewsTab> {
),
body: Container(
child: ListView.builder(
itemCount: _itemsLength,
itemBuilder: _listBuilder,
),
),
@@ -111,6 +110,7 @@ class _NewsTabState extends State<NewsTab> {
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(),
child: ListView.builder(
itemCount: _itemsLength,
itemBuilder: _listBuilder,
),
);

View File

@@ -109,7 +109,11 @@ class ProfileTab extends StatelessWidget {
}
class PreferenceCard extends StatelessWidget {
const PreferenceCard({this.header, this.content, this.preferenceChoices});
const PreferenceCard({
required this.header,
required this.content,
required this.preferenceChoices,
});
final String header;
final String content;

View File

@@ -12,7 +12,11 @@ import 'widgets.dart';
/// On Android, this page sits at the top of your app. On iOS, this page is on
/// top of the songs tab's content but is below the tab bar itself.
class SongDetailTab extends StatelessWidget {
const SongDetailTab({this.id, this.song, this.color});
const SongDetailTab({
required this.id,
required this.song,
required this.color,
});
final int id;
final String song;

View File

@@ -15,9 +15,9 @@ class SongsTab extends StatefulWidget {
static const androidIcon = Icon(Icons.music_note);
static const iosIcon = Icon(CupertinoIcons.music_note);
const SongsTab({Key key, this.androidDrawer}) : super(key: key);
const SongsTab({Key? key, this.androidDrawer}) : super(key: key);
final Widget androidDrawer;
final Widget? androidDrawer;
@override
_SongsTabState createState() => _SongsTabState();
@@ -28,8 +28,8 @@ class _SongsTabState extends State<SongsTab> {
final _androidRefreshKey = GlobalKey<RefreshIndicatorState>();
List<MaterialColor> colors;
List<String> songNames;
late List<MaterialColor> colors;
late List<String> songNames;
@override
void initState() {
@@ -51,7 +51,7 @@ class _SongsTabState extends State<SongsTab> {
}
Widget _listBuilder(BuildContext context, int index) {
if (index >= _itemsLength) return null;
if (index >= _itemsLength) return Container();
// Show a slightly different color palette. Show poppy-ier colors on iOS
// due to lighter contrasting bars and tone it down on Android.
@@ -96,7 +96,7 @@ class _SongsTabState extends State<SongsTab> {
// done in a real app but it's done here since this app
// unrealistically toggles the current platform for demonstration
// purposes.
WidgetsBinding.instance.reassembleApplication();
WidgetsBinding.instance!.reassembleApplication();
}
// ===========================================================================
@@ -117,7 +117,8 @@ class _SongsTabState extends State<SongsTab> {
actions: [
IconButton(
icon: Icon(Icons.refresh),
onPressed: () async => await _androidRefreshKey.currentState.show(),
onPressed: () async =>
await _androidRefreshKey.currentState!.show(),
),
IconButton(
icon: Icon(Icons.shuffle),
@@ -131,6 +132,7 @@ class _SongsTabState extends State<SongsTab> {
onRefresh: _refreshData,
child: ListView.builder(
padding: EdgeInsets.symmetric(vertical: 12),
itemCount: _itemsLength,
itemBuilder: _listBuilder,
),
),
@@ -155,7 +157,10 @@ class _SongsTabState extends State<SongsTab> {
sliver: SliverPadding(
padding: EdgeInsets.symmetric(vertical: 12),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(_listBuilder),
delegate: SliverChildBuilderDelegate(
_listBuilder,
childCount: _itemsLength,
),
),
),
),

View File

@@ -57,7 +57,7 @@ String generateRandomHeadline() {
}
assert(false, 'Failed to generate news headline');
return null;
return 'Failed to generate news headline';
}
List<MaterialColor> getRandomColors(int amount) {

View File

@@ -9,12 +9,10 @@ import 'package:flutter/material.dart';
/// A simple widget that builds different things on different platforms.
class PlatformWidget extends StatelessWidget {
const PlatformWidget({
Key key,
@required this.androidBuilder,
@required this.iosBuilder,
}) : assert(androidBuilder != null),
assert(iosBuilder != null),
super(key: key);
Key? key,
required this.androidBuilder,
required this.iosBuilder,
}) : super(key: key);
final WidgetBuilder androidBuilder;
final WidgetBuilder iosBuilder;
@@ -28,7 +26,7 @@ class PlatformWidget extends StatelessWidget {
return iosBuilder(context);
default:
assert(false, 'Unexpected platform $defaultTargetPlatform');
return null;
return SizedBox.shrink();
}
}
}
@@ -40,15 +38,15 @@ class PlatformWidget extends StatelessWidget {
class PressableCard extends StatefulWidget {
const PressableCard({
this.onPressed,
this.color,
this.flattenAnimation,
required this.color,
required this.flattenAnimation,
this.child,
});
final VoidCallback onPressed;
final VoidCallback? onPressed;
final Color color;
final Animation<double> flattenAnimation;
final Widget child;
final Widget? child;
@override
State<StatefulWidget> createState() => _PressableCardState();
@@ -57,8 +55,8 @@ class PressableCard extends StatefulWidget {
class _PressableCardState extends State<PressableCard>
with SingleTickerProviderStateMixin {
bool pressed = false;
AnimationController controller;
Animation<double> elevationAnimation;
late final AnimationController controller;
late final Animation<double> elevationAnimation;
@override
void initState() {
@@ -93,9 +91,7 @@ class _PressableCardState extends State<PressableCard>
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
if (widget.onPressed != null) {
widget.onPressed();
}
widget.onPressed?.call();
},
// This widget both internally drives an animation when pressed and
// responds to an external animation to flatten the card when in a
@@ -138,13 +134,17 @@ class _PressableCardState extends State<PressableCard>
/// This is an example of a custom widget that an app developer might create for
/// use on both iOS and Android as part of their brand's unique design.
class HeroAnimatingSongCard extends StatelessWidget {
HeroAnimatingSongCard(
{this.song, this.color, this.heroAnimation, this.onPressed});
HeroAnimatingSongCard({
required this.song,
required this.color,
required this.heroAnimation,
this.onPressed,
});
final String song;
final Color color;
final Animation<double> heroAnimation;
final VoidCallback onPressed;
final VoidCallback? onPressed;
double get playButtonSize => 50 + 50 * heroAnimation.value;
@@ -226,7 +226,7 @@ class SongPlaceholderTile extends StatelessWidget {
child: Row(
children: [
Container(
color: Theme.of(context).textTheme.bodyText2.color,
color: Theme.of(context).textTheme.bodyText2!.color,
width: 130,
),
Padding(
@@ -239,27 +239,27 @@ class SongPlaceholderTile extends StatelessWidget {
Container(
height: 9,
margin: EdgeInsets.only(right: 60),
color: Theme.of(context).textTheme.bodyText2.color,
color: Theme.of(context).textTheme.bodyText2!.color,
),
Container(
height: 9,
margin: EdgeInsets.only(right: 20, top: 8),
color: Theme.of(context).textTheme.bodyText2.color,
color: Theme.of(context).textTheme.bodyText2!.color,
),
Container(
height: 9,
margin: EdgeInsets.only(right: 40, top: 8),
color: Theme.of(context).textTheme.bodyText2.color,
color: Theme.of(context).textTheme.bodyText2!.color,
),
Container(
height: 9,
margin: EdgeInsets.only(right: 80, top: 8),
color: Theme.of(context).textTheme.bodyText2.color,
color: Theme.of(context).textTheme.bodyText2!.color,
),
Container(
height: 9,
margin: EdgeInsets.only(right: 50, top: 8),
color: Theme.of(context).textTheme.bodyText2.color,
color: Theme.of(context).textTheme.bodyText2!.color,
),
],
),
@@ -287,7 +287,7 @@ void showChoices(BuildContext context, List<String> choices) {
showDialog<void>(
context: context,
builder: (context) {
var selectedRadio = 1;
int? selectedRadio = 1;
return AlertDialog(
contentPadding: EdgeInsets.only(top: 12),
content: StatefulBuilder(
@@ -295,12 +295,11 @@ void showChoices(BuildContext context, List<String> choices) {
return Column(
mainAxisSize: MainAxisSize.min,
children: List<Widget>.generate(choices.length, (index) {
return RadioListTile(
return RadioListTile<int?>(
title: Text(choices[index]),
value: index,
groupValue: selectedRadio,
// ignore: avoid_types_on_closure_parameters
onChanged: (int value) {
onChanged: (value) {
setState(() => selectedRadio = value);
},
);