третья labs

This commit is contained in:
Nastya_Kozlova 2024-10-06 21:18:07 +04:00
parent a28a6c9250
commit c42cbed29f

View File

@ -13,8 +13,7 @@ class MyApp extends StatelessWidget {
return MaterialApp( return MaterialApp(
title: 'Flutter Demo', title: 'Flutter Demo',
theme: ThemeData( theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.black),
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true, useMaterial3: true,
), ),
home: const MyHomePage(title: 'настя'), home: const MyHomePage(title: 'настя'),
@ -32,48 +31,167 @@ class MyHomePage extends StatefulWidget {
} }
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
int _counter = 0; final Color _color = Colors.black;
void _incrementCounter() {
setState(() {
_counter++;
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
backgroundColor: _color,
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title), title: Text(widget.title),
), ),
body: Center( body: const MyWidget(),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
); );
} }
} }
class _CardData {
final String text;
final String descriptionText;
final IconData icon;
final String? imageUrl;
_CardData(
this.text, {
required this.descriptionText,
required this.icon,
this.imageUrl,
});
}
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@override
Widget build(BuildContext context) {
final data = [
_CardData(
'bebebe',
descriptionText: 'sldmk',
icon: Icons.hail,
imageUrl: 'https://img.freepik.com/free-photo/smiley-woman-talking-phone-medium-shot_23-2149476757.jpg?t=st=1727894827~exp=1727898427~hmac=a14045ebfb7ed48343615c31db970b30b086a5ddadaa428601b7534e37540b4a&w=996',
),
_CardData(
'sdde',
descriptionText: 'ssdmk',
icon: Icons.hail,
imageUrl: 'https://img.freepik.com/free-photo/medium-shot-women-with-delicious-food_23-2150168102.jpg?t=st=1727895736~exp=1727899336~hmac=3260118fc2bd6fe946f54465e104629fe046384f621e8393e1f9f557392f7dad&w=996',
),
_CardData(
'aaae',
descriptionText: 'ssldmk',
icon: Icons.hail,
imageUrl: 'https://img.freepik.com/free-photo/high-angle-smiley-woman-sitting-table_23-2150168074.jpg?t=st=1727895785~exp=1727899385~hmac=880ec7fcf220143947d4f276490c4338c1828c7920540a1efc2503c4cc791aec&w=360',
),
];
return Center(
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: data.map((e) => _Card.fromData(e)).toList(),
),
),
);
}
}
class _Card extends StatefulWidget {
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
State<_Card> createState() => _CardState();
}
class _CardState extends State<_Card> {
bool isLiked = false;
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.all(20),
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white70,
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Colors.blueGrey,
),
),
child: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(20),
child: SizedBox(
height: 140,
width: 100,
child: Image.network(
widget.imageUrl ?? '',
fit: BoxFit.cover,
errorBuilder: (_, __, ___) => const Placeholder(),
),
),
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
widget.text,
style: Theme.of(context).textTheme.headlineLarge,
),
Text(
widget.descriptionText,
style: Theme.of(context).textTheme.headlineSmall,
),
],
),
),
),
Align(
alignment: Alignment.bottomRight,
child: Padding(
padding: const EdgeInsets.only(
left: 8.0,
right: 16,
bottom: 16
),
child: GestureDetector(
onTap: () {
setState(() {
isLiked = !isLiked;
});
},
child: Icon(
isLiked ? Icons.favorite : Icons.favorite_border
),
),
),
)
],
),
),
);
}
}