Lab3
This commit is contained in:
parent
d20378d17b
commit
4aa03f5187
144
lib/main.dart
144
lib/main.dart
@ -13,6 +13,7 @@ class MyApp extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange),
|
||||
useMaterial3: true,
|
||||
@ -32,15 +33,7 @@ class MyHomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
int _counter = 0;
|
||||
Color _color = Colors.orangeAccent;
|
||||
|
||||
void _incrementCounter() {
|
||||
setState(() {
|
||||
_counter++;
|
||||
_color = Color((Random().nextDouble() * 0xFFFFFF).toInt()).withOpacity(1.0);
|
||||
});
|
||||
}
|
||||
final Color _color = Colors.orangeAccent;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -49,30 +42,121 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
backgroundColor: _color,
|
||||
title: Text(widget.title),
|
||||
),
|
||||
body: Center(
|
||||
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,
|
||||
),
|
||||
if (_counter > 10)
|
||||
Text(
|
||||
'Wtf bro?',
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
body: const MyWidget(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyWidget extends StatelessWidget {
|
||||
const MyWidget({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final data = [
|
||||
_CartData(
|
||||
'FarCry 1',
|
||||
descriptionText: 'Читать описание',
|
||||
imageUrl:
|
||||
'https://avatars.mds.yandex.net/i?id=e8dbfc281bbeac76d49d5f83b9b872d9_l-5246113-images-thumbs&n=13',
|
||||
),
|
||||
_CartData(
|
||||
'FarCry 2',
|
||||
descriptionText: 'Читать описание',
|
||||
imageUrl:
|
||||
'https://avatars.mds.yandex.net/get-entity_search/2102351/931749212/S600xU_2x'),
|
||||
_CartData(
|
||||
'FarCry 3',
|
||||
descriptionText: 'Читать описание',
|
||||
imageUrl: 'https://i.pinimg.com/736x/ab/32/cc/ab32cc12f75b5c304ec88af78c5c0dc3.jpg'
|
||||
)
|
||||
];
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: data.map((e) => _Card.fromData(e)).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _CartData {
|
||||
final String text;
|
||||
final String descriptionText;
|
||||
|
||||
final String? imageUrl;
|
||||
|
||||
_CartData(
|
||||
this.text, {
|
||||
required this.descriptionText,
|
||||
this.imageUrl,
|
||||
});
|
||||
}
|
||||
|
||||
class _Card extends StatelessWidget {
|
||||
final String text;
|
||||
final String descriptionText;
|
||||
|
||||
final String? imageUrl;
|
||||
|
||||
const _Card(
|
||||
this.text, {
|
||||
required this.descriptionText,
|
||||
this.imageUrl,
|
||||
});
|
||||
|
||||
factory _Card.fromData(_CartData data) => _Card(
|
||||
data.text,
|
||||
descriptionText: data.descriptionText,
|
||||
imageUrl: data.imageUrl,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(top: 16),
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orangeAccent,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: Colors.grey, width: 2)),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: SizedBox(
|
||||
height: 150,
|
||||
width: 150,
|
||||
child: Image.network(
|
||||
imageUrl ?? '',
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) => const Placeholder(),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
text,
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
Text(
|
||||
descriptionText,
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _incrementCounter,
|
||||
backgroundColor: _color,
|
||||
tooltip: 'Increment',
|
||||
child: const Icon(Icons.add),
|
||||
), );
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user