mirror of
https://github.com/material-components/material-components-flutter.git
synced 2026-01-21 12:43:07 +08:00
152 lines
4.1 KiB
Dart
152 lines
4.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
void main() => runApp(MyApp());
|
|
|
|
class MyApp extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
title: 'Flutter Demo',
|
|
debugShowCheckedModeBanner: false,
|
|
home: MyHomePage(),
|
|
theme: _buildShrineTheme(),
|
|
);
|
|
}
|
|
}
|
|
|
|
class MyHomePage extends StatelessWidget {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final AlertDialog dialog = AlertDialog(
|
|
title: Text('Title'),
|
|
contentPadding: EdgeInsets.zero,
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
for (int i = 1; i <= 3; i++)
|
|
ListTile(
|
|
title: Text(
|
|
'option $i',
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.subtitle1
|
|
.copyWith(color: shrineBrown900),
|
|
),
|
|
leading: Radio(
|
|
value: i,
|
|
groupValue: 1,
|
|
onChanged: (_) {},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
FlatButton(
|
|
textColor: shrineBrown900,
|
|
onPressed: () => Navigator.pop(context),
|
|
child: Text('ACTION 1'),
|
|
),
|
|
FlatButton(
|
|
textColor: shrineBrown900,
|
|
onPressed: () => Navigator.pop(context),
|
|
child: Text('ACTION 2'),
|
|
),
|
|
],
|
|
);
|
|
|
|
return Scaffold(
|
|
body: Center(
|
|
child: FlatButton(
|
|
onPressed: () {
|
|
showDialog<void>(context: context, builder: (context) => dialog);
|
|
},
|
|
child: Text("SHOW DIALOG"),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
ThemeData _buildShrineTheme() {
|
|
final ThemeData base = ThemeData.light();
|
|
return base.copyWith(
|
|
colorScheme: _shrineColorScheme,
|
|
toggleableActiveColor: shrinePink400,
|
|
accentColor: shrineBrown900,
|
|
primaryColor: shrinePink100,
|
|
buttonColor: shrinePink100,
|
|
scaffoldBackgroundColor: shrineBackgroundWhite,
|
|
cardColor: shrineBackgroundWhite,
|
|
textSelectionTheme: TextSelectionThemeData(selectionColor: shrinePink100),
|
|
errorColor: shrineErrorRed,
|
|
buttonTheme: const ButtonThemeData(
|
|
colorScheme: _shrineColorScheme,
|
|
textTheme: ButtonTextTheme.normal,
|
|
),
|
|
primaryIconTheme: _customIconTheme(base.iconTheme),
|
|
textTheme: _buildShrineTextTheme(base.textTheme),
|
|
primaryTextTheme: _buildShrineTextTheme(base.primaryTextTheme),
|
|
accentTextTheme: _buildShrineTextTheme(base.accentTextTheme),
|
|
iconTheme: _customIconTheme(base.iconTheme),
|
|
dialogTheme: DialogTheme(
|
|
backgroundColor: shrinePink100,
|
|
),
|
|
);
|
|
}
|
|
|
|
IconThemeData _customIconTheme(IconThemeData original) {
|
|
return original.copyWith(color: shrineBrown900);
|
|
}
|
|
|
|
TextTheme _buildShrineTextTheme(TextTheme base) {
|
|
return base
|
|
.copyWith(
|
|
caption: base.caption.copyWith(
|
|
fontWeight: FontWeight.w400,
|
|
fontSize: 14,
|
|
letterSpacing: defaultLetterSpacing,
|
|
),
|
|
button: base.button.copyWith(
|
|
fontWeight: FontWeight.w500,
|
|
fontSize: 14,
|
|
letterSpacing: defaultLetterSpacing,
|
|
),
|
|
)
|
|
.apply(
|
|
fontFamily: 'Rubik',
|
|
displayColor: shrineBrown900,
|
|
bodyColor: shrineBrown900,
|
|
);
|
|
}
|
|
|
|
const ColorScheme _shrineColorScheme = ColorScheme(
|
|
primary: shrinePink100,
|
|
primaryVariant: shrineBrown900,
|
|
secondary: shrineBrown900,
|
|
secondaryVariant: shrineBrown900,
|
|
surface: shrineSurfaceWhite,
|
|
background: shrineBackgroundWhite,
|
|
error: shrineErrorRed,
|
|
onPrimary: shrineBrown900,
|
|
onSecondary: shrineBrown900,
|
|
onSurface: shrineBrown900,
|
|
onBackground: shrineBrown900,
|
|
onError: shrineSurfaceWhite,
|
|
brightness: Brightness.light,
|
|
);
|
|
|
|
const Color shrinePink50 = Color(0xFFFEEAE6);
|
|
const Color shrinePink100 = Color(0xFFFEDBD0);
|
|
const Color shrinePink300 = Color(0xFFFBB8AC);
|
|
const Color shrinePink400 = Color(0xFFEAA4A4);
|
|
|
|
const Color shrineBrown900 = Color(0xFF442B2D);
|
|
const Color shrineBrown600 = Color(0xFF7D4F52);
|
|
|
|
const Color shrineErrorRed = Color(0xFFC5032B);
|
|
|
|
const Color shrineSurfaceWhite = Color(0xFFFFFBFA);
|
|
const Color shrineBackgroundWhite = Colors.white;
|
|
|
|
const defaultLetterSpacing = 0.03;
|