-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Closed
Labels
f: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.found in release: 2.5Found to occur in 2.5Found to occur in 2.5found in release: 2.6Found to occur in 2.6Found to occur in 2.6frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work on
Description
Dear flutter develop team.
Recently, I ran into a strange phenomenon while writing Flutter code.
The following is the code.
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
colorScheme: ColorScheme.fromSwatch(primarySwatch: Colors.white)), // The argument type 'Color' can't be assigned to the parameter type 'MaterialColor'.
home: Scaffold(
appBar: AppBar(
title: const Text('Test App'),
),
body: Container(),
),
);
}
}
Oddly enough, this error only occurs for Colors.white
and not for Colors.red
or Colors.blue
.
I wondered and checked the source code for colors.dart
.
Then, Colors.white
was defined as the Color
type, but Colors.red
and Colors.blue
were defined as the MaterialColor
type.
[colors.dart]
// Code defining "white"
static const Color white = Color(0xFFFFFFFF);
// Code defining "red"
static const MaterialColor red = MaterialColor(
_redPrimaryValue,
<int, Color>{
50: Color(0xFFFFEBEE),
100: Color(0xFFFFCDD2),
200: Color(0xFFEF9A9A),
300: Color(0xFFE57373),
400: Color(0xFFEF5350),
500: Color(_redPrimaryValue),
600: Color(0xFFE53935),
700: Color(0xFFD32F2F),
800: Color(0xFFC62828),
900: Color(0xFFB71C1C),
},
);
The mixture of Color
type and MaterialColor
type member variables in a class named Colors
is confusing.
Therefore, I suggest to create a new class named MaterialColors
into colors.dart
and move the member variables of the MaterialColor
type into it.
Thanks you for reading.
The following is my flutter version.
Flutter 2.5.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision ffb2ecea52 (5 days ago) • 2021-09-17 15:26:33 -0400
Engine • revision b3af521a05
Tools • Dart 2.14.2
Metadata
Metadata
Assignees
Labels
f: material designflutter/packages/flutter/material repository.flutter/packages/flutter/material repository.found in release: 2.5Found to occur in 2.5Found to occur in 2.5found in release: 2.6Found to occur in 2.6Found to occur in 2.6frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work on