Last active
April 4, 2021 01:43
-
-
Save yeoupooh/04be802ff93f1665840d291886071db8 to your computer and use it in GitHub Desktop.
Card widget sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Card widget sample | |
// https://material.io/components/cards/flutter#theming-a-card | |
// | |
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, | |
theme: _buildShrineTheme(), | |
home: MyHomePage(title: 'Flutter Demo Home Page'), | |
); | |
} | |
} | |
class MyHomePage extends StatefulWidget { | |
MyHomePage({Key key, this.title}) : super(key: key); | |
final String title; | |
@override | |
_MyHomePageState createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: ListView( | |
children: [ | |
Card( | |
clipBehavior: Clip.antiAlias, | |
child: Column( | |
children: [ | |
ListTile( | |
leading: Icon(Icons.arrow_drop_down_circle), | |
title: const Text('Card title 1'), | |
subtitle: Text( | |
'Secondary Text', | |
style: TextStyle(color: Colors.black.withOpacity(0.6)), | |
), | |
), | |
Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Text( | |
'Greyhound divisively hello coldly wonderfully marginally far upon excluding.', | |
style: TextStyle(color: Colors.black.withOpacity(0.6)), | |
), | |
), | |
ButtonBar( | |
alignment: MainAxisAlignment.start, | |
children: [ | |
TextButton( | |
onPressed: () { | |
// Perform some action | |
}, | |
child: const Text('ACTION 1'), | |
), | |
TextButton( | |
onPressed: () { | |
// Perform some action | |
}, | |
child: const Text('ACTION 2'), | |
), | |
], | |
), | |
// Image.asset('assets/card-sample-image.jpg'), | |
Image.network('https://picsum.photos/250?image=9'), | |
], | |
), | |
), | |
Card( | |
clipBehavior: Clip.antiAlias, | |
child: Column( | |
children: [ | |
ListTile( | |
leading: Icon(Icons.arrow_drop_down_circle), | |
title: const Text('Card title 1'), | |
subtitle: Text( | |
'Secondary Text', | |
style: TextStyle(color: Colors.black.withOpacity(0.6)), | |
), | |
), | |
Padding( | |
padding: const EdgeInsets.all(16.0), | |
child: Text( | |
'Greyhound divisively hello coldly wonderfully marginally far upon excluding.', | |
style: TextStyle(color: Colors.black.withOpacity(0.6)), | |
), | |
), | |
ButtonBar( | |
alignment: MainAxisAlignment.start, | |
children: [ | |
TextButton( | |
onPressed: () { | |
// Perform some action | |
}, | |
child: const Text('ACTION 1'), | |
), | |
TextButton( | |
onPressed: () { | |
// Perform some action | |
}, | |
child: const Text('ACTION 2'), | |
), | |
], | |
), | |
// Image.asset('assets/card-sample-image-2.jpg'), | |
Image.network('https://picsum.photos/250?image=10'), | |
], | |
), | |
), | |
], | |
), | |
); | |
} | |
} | |
IconThemeData _customIconTheme(IconThemeData original) { | |
return original.copyWith(color: shrineBrown900); | |
} | |
ThemeData _buildShrineTheme() { | |
final ThemeData base = ThemeData.light(); | |
return base.copyWith( | |
colorScheme: _shrineColorScheme, | |
accentColor: shrineBrown900, | |
primaryColor: shrinePink100, | |
buttonColor: shrinePink100, | |
scaffoldBackgroundColor: shrineBackgroundWhite, | |
cardColor: shrineBackgroundWhite, | |
textSelectionColor: 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), | |
); | |
} | |
TextTheme _buildShrineTextTheme(TextTheme base) { | |
return base | |
.copyWith( | |
headline: base.headline?.copyWith( | |
fontWeight: FontWeight.w500, | |
letterSpacing: defaultLetterSpacing, | |
), | |
title: base.title?.copyWith( | |
fontSize: 18, | |
letterSpacing: defaultLetterSpacing, | |
), | |
caption: base.caption?.copyWith( | |
fontWeight: FontWeight.w400, | |
fontSize: 14, | |
letterSpacing: defaultLetterSpacing, | |
), | |
body2: base.body2?.copyWith( | |
fontWeight: FontWeight.w500, | |
fontSize: 16, | |
letterSpacing: defaultLetterSpacing, | |
), | |
body1: base.body1?.copyWith( | |
letterSpacing: defaultLetterSpacing, | |
), | |
subhead: base.subhead?.copyWith( | |
letterSpacing: defaultLetterSpacing, | |
), | |
display1: base.display1?.copyWith( | |
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: shrinePink50, | |
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment