171 lines
4.3 KiB
Dart
171 lines
4.3 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
|
||
|
void main() {
|
||
|
runApp(const MyApp());
|
||
|
}
|
||
|
|
||
|
class MyApp extends StatelessWidget {
|
||
|
const MyApp({super.key});
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return MaterialApp(
|
||
|
title: 'My Test App',
|
||
|
debugShowCheckedModeBanner: false,
|
||
|
theme: ThemeData(
|
||
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||
|
useMaterial3: true,
|
||
|
),
|
||
|
home: const MyHomePage(title: 'My Test App'),
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class MyHomePage extends StatefulWidget {
|
||
|
const MyHomePage({super.key, required this.title});
|
||
|
|
||
|
final String title;
|
||
|
|
||
|
@override
|
||
|
State<MyHomePage> createState() => _MyHomePageState();
|
||
|
}
|
||
|
|
||
|
class _MyHomePageState extends State<MyHomePage> {
|
||
|
final Color _color = Colors.orangeAccent;
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Scaffold(
|
||
|
appBar: AppBar(
|
||
|
backgroundColor: _color,
|
||
|
title: Text(widget.title),
|
||
|
),
|
||
|
body: const MyWidget(),
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class MyWidget extends StatelessWidget {
|
||
|
const MyWidget({super.key});
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
final data = [
|
||
|
_CardData('Hello',
|
||
|
descriptionText: 'Hello text',
|
||
|
imageUrl:
|
||
|
'https://unsplash.com/photos/6GMq7AGxNbE/download?ixid=M3wxMjA3fDB8MXxzZWFyY2h8Mnx8cmFjY29vbnxlbnwwfHx8fDE3Mjc5MTExNTl8MA&force=true&w=640'),
|
||
|
_CardData('Hello 2',
|
||
|
descriptionText: 'Hello 2 text',
|
||
|
icon: Icons.add,
|
||
|
imageUrl:
|
||
|
'https://unsplash.com/photos/UopR2NUBYek/download?ixid=M3wxMjA3fDB8MXxzZWFyY2h8MTF8fHJhY2Nvb258ZW58MHx8fHwxNzI3OTExMTU5fDA&force=true&w=640'),
|
||
|
];
|
||
|
|
||
|
return Center(
|
||
|
child: SingleChildScrollView(
|
||
|
padding: const EdgeInsets.only(left: 16, right: 16, top: 8, bottom: 8),
|
||
|
child: Column(
|
||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
children: data.map((e) => _Card.fromData(e)).toList(),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class _CardData {
|
||
|
final String text;
|
||
|
final String descriptionText;
|
||
|
final IconData icon;
|
||
|
final String? imageUrl;
|
||
|
|
||
|
_CardData(
|
||
|
this.text, {
|
||
|
required this.descriptionText,
|
||
|
this.icon = Icons.ac_unit_outlined,
|
||
|
this.imageUrl,
|
||
|
});
|
||
|
}
|
||
|
|
||
|
class _Card extends StatelessWidget {
|
||
|
final String text;
|
||
|
final String descriptionText;
|
||
|
final IconData icon;
|
||
|
final String? imageUrl;
|
||
|
|
||
|
const _Card(
|
||
|
this.text, {
|
||
|
this.icon = Icons.ac_unit_outlined,
|
||
|
required this.descriptionText,
|
||
|
this.imageUrl,
|
||
|
});
|
||
|
|
||
|
factory _Card.fromData(_CardData data) => _Card(
|
||
|
data.text,
|
||
|
descriptionText: data.descriptionText,
|
||
|
icon: data.icon,
|
||
|
imageUrl: data.imageUrl,
|
||
|
);
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Container(
|
||
|
margin: const EdgeInsets.only(top: 8, bottom: 8),
|
||
|
padding: const EdgeInsets.all(16),
|
||
|
decoration: BoxDecoration(
|
||
|
color: Colors.white70,
|
||
|
borderRadius: BorderRadius.circular(20),
|
||
|
border: Border.all(color: Colors.grey),
|
||
|
boxShadow: [
|
||
|
BoxShadow(
|
||
|
color: Colors.grey.withOpacity(.5),
|
||
|
spreadRadius: 4,
|
||
|
offset: const Offset(0, 5),
|
||
|
blurRadius: 8,
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
child: Row(
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
ClipRRect(
|
||
|
borderRadius: BorderRadius.circular(20),
|
||
|
child: SizedBox(
|
||
|
height: 140,
|
||
|
width: 100,
|
||
|
child: Image.network(
|
||
|
imageUrl ?? '',
|
||
|
fit: BoxFit.cover,
|
||
|
errorBuilder: (_, __, ___) => const Placeholder(),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
Expanded(
|
||
|
child: Padding(
|
||
|
padding: const EdgeInsets.only(left: 8.0),
|
||
|
child: Column(
|
||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||
|
children: [
|
||
|
Text(
|
||
|
text,
|
||
|
style: Theme.of(context).textTheme.headlineLarge,
|
||
|
),
|
||
|
Text(
|
||
|
descriptionText,
|
||
|
style: Theme.of(context).textTheme.bodyLarge,
|
||
|
)
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
Padding(
|
||
|
padding: const EdgeInsets.only(left: 8.0),
|
||
|
child: Icon(icon),
|
||
|
)
|
||
|
],
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|