TOP(About this memo)) > 一覧(Flutter) > マテリアルデザイン
Material Design is a design system built and supported by Google designers and developers. Material.io includes in-depth UX guidance and UI component implementations for Android, Flutter, and the Web.The latest version, Material 3, enables personal, adaptive, and expressive experiences – from dynamic color and enhanced accessibility, to foundations for large screen layouts and design tokens.
uses-material-design: true
useMaterial3: true
import 'package:flutter/material.dart';
A set of 30 colors based on the Material spec that can be used to configure the color properties of most components.
import 'package:flutter/material.dart';
const seedColor = Color.fromARGB(255, 164, 206, 255);
final theme = ThemeData(
useMaterial3: true,
colorScheme:
ColorScheme.fromSeed(seedColor: seedColor, brightness: Brightness.light),
);
main() => runApp(MaterialApp(
theme: theme,
home: Scaffold(
body: Column(
children: [
Row(
children: [
const Text("seed color:"),
Container(
decoration: const BoxDecoration(
color: seedColor,
borderRadius: BorderRadius.all(Radius.circular(10)),
),
child: const SizedBox(
width: 10,
height: 10,
),
)
],
),
for (final (Color, Color, String, String) c in [
(
theme.colorScheme.primary,
theme.colorScheme.onPrimary,
"primary",
"onPrimary",
),
(
theme.colorScheme.secondary,
theme.colorScheme.onSecondary,
"secondary",
"onSecondary",
),
(
theme.colorScheme.tertiary,
theme.colorScheme.onTertiary,
"tertiary",
"onTertiary",
),
(
theme.colorScheme.primaryContainer,
theme.colorScheme.onPrimaryContainer,
"primaryContainer",
"onPrimaryContainer",
),
(
theme.colorScheme.secondaryContainer,
theme.colorScheme.onSecondaryContainer,
"secondaryContainer",
"onSecondaryContainer",
),
(
theme.colorScheme.tertiaryContainer,
theme.colorScheme.onTertiaryContainer,
"tertiaryContainer",
"onTertiaryContainer",
),
(
theme.colorScheme.background,
theme.colorScheme.onBackground,
"background",
"onBackground",
),
(
theme.colorScheme.error,
theme.colorScheme.onError,
"error",
"onError",
),
(
theme.colorScheme.errorContainer,
theme.colorScheme.onErrorContainer,
"errorContainer",
"onErrorContainer",
),
(
theme.colorScheme.inversePrimary,
theme.colorScheme.primary,
"inversePrimary",
"primary",
),
(
theme.colorScheme.inverseSurface,
theme.colorScheme.onInverseSurface,
"inversePrimary",
"onInverseSurface",
),
])
Container(
decoration: BoxDecoration(
color: c.$1,
borderRadius: const BorderRadius.all(Radius.circular(10)),
),
child: Text(
"backgrond color: ${c.$3}, text color: ${c.$4}",
style: TextStyle(color: c.$2),
),
)
],
),
)));
testWidgets("", (widgetTester) async {
await widgetTester.pumpWidget(MaterialApp(
// home: ListTile(),// assert error
home: Material(child: ListTile(),),
));
});
// lib/src/material/list_tile.dart
class ListTile extends StatelessWidget {
// ...
@override
Widget build(BuildContext context) {
assert(debugCheckHasMaterial(context)); // 先祖のMaterialウィジェットが無い場合にassert error
// ...
}
// ...
}
// 下記から抜粋
// https://stackoverflow.com/a/63777364/22090329
Theme(
data: Theme.of(context).copyWith(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
child: bottomNavigationBar(/* ... */)
)