Created
July 1, 2021 09:38
-
-
Save bobagold/5c2162e3cc0190048db1c7224e0da9df to your computer and use it in GitHub Desktop.
Flutter cards example using Stack
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
import 'package:flutter/material.dart'; | |
void main() { | |
runApp( | |
MaterialApp( | |
home: HomeScreen(), | |
), | |
); | |
} | |
class HomeScreen extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) => Scaffold( | |
body: GridView.count( | |
padding: const EdgeInsets.all(20), | |
crossAxisSpacing: 10, | |
mainAxisSpacing: 10, | |
crossAxisCount: 2, | |
childAspectRatio: 2.2, | |
children: [ | |
MyCard(), | |
MyCard(), | |
MyCard(), | |
], | |
), | |
); | |
} | |
class MyCard extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) => Container( | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.all(Radius.circular(20)), | |
color: Color(0xFFCCCCCC), | |
), | |
padding: EdgeInsets.all(16), | |
child: Stack( | |
children: [ | |
Positioned( | |
left: 0, | |
top: 0, | |
width: 200, | |
height: 200, | |
child: Text.rich( | |
TextSpan( | |
text: '8 (499) 110-2010\n', | |
style: Theme.of(context) | |
.textTheme | |
.headline6! | |
.copyWith(height: 1), | |
children: [ | |
TextSpan( | |
text: 'Временный', | |
style: Theme.of(context).textTheme.caption), | |
], | |
), | |
), | |
), | |
Positioned( | |
right: 0, | |
top: 0, | |
width: 100, | |
height: 30, | |
child: Text( | |
'18.05.2020', | |
textAlign: TextAlign.right, | |
style: Theme.of(context).textTheme.caption, | |
), | |
), | |
Positioned( | |
left: 0, | |
bottom: 0, | |
right: 0, | |
height: 30, | |
child: Container( | |
alignment: Alignment.bottomLeft, | |
child: Wrap( | |
spacing: 10, | |
children: [ | |
'Продажа квартиры,', | |
// 'Жепь', | |
// 'Ебрило', | |
'Ольги Жилиной', | |
] | |
.map( | |
(t) => InkWell( | |
onTap: () => print('todo'), | |
child: Text( | |
t, | |
style: | |
Theme.of(context).textTheme.caption!.copyWith( | |
decoration: TextDecoration.underline, | |
), | |
), | |
), | |
) | |
.toList(), | |
), | |
), | |
), | |
], | |
), | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment