Почему крашится flutter приложение?
Хочу сделать такой же макет, как на картинке, но при добавлении HorizontalSlider всё крашится, ошибку не могу загуглить, поэтому пишу сюда. Без HorizontlSlider вс1 работает.Вот код:
[![введите сюда описание изображения][1]][1]
import 'package:flutter/material.dart';
void main() => runApp(WeatherApp());
class WeatherApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
color: Colors.red,
home: WeatherForecast(),
);
}
}
Widget WeatherForecast() {
return Scaffold(
backgroundColor: Colors.red,
appBar: AppBar(
centerTitle: true,
backgroundColor: Colors.red,
title: Text(
'Weather Forecast',
textAlign: TextAlign.center,
),
),
body: MainFrame(),
);
}
class HorizontalSlider extends StatefulWidget {
@override
State<StatefulWidget> createState() => new _HorizontalSlider();
}
Widget MainFrame() {
return Column(
children: [
SearchBar(),
Divider(),
MyLocation(),
Divider(),
CurrentWeather(),
Divider(),
Characteristics(),
Divider(),
Divider(),
Text(
'7-DAY WEATHER FORECASST',
style: TextStyle(
fontSize: 20,
color: Colors.white,
),
),
HorizontalSlider(),
],
);
}
Widget SearchBar() {
return Row(
children: [
IconButton(
onPressed: () {},
icon: Icon(
Icons.search,
),
color: Colors.white,
),
Text(
'Enter City Name',
style: TextStyle(fontSize: 17, color: Colors.white),
),
],
);
}
Widget MyLocation() {
return Padding(
padding: EdgeInsets.all(12),
child: Column(
children: [
Text(
'Ryazan Oblast, Ru',
style: TextStyle(
color: Colors.white,
fontSize: 30,
),
),
Text(
'Saturday, May 3, 2022',
style: TextStyle(
color: Colors.white,
fontSize: 18,
),
),
],
),
);
}
Widget CurrentWeather() {
return Padding(
padding: EdgeInsets.fromLTRB(
100,
20,
100,
20,
),
child: Row(
children: [
Icon(
Icons.wb_sunny,
color: Colors.white,
size: 80,
),
SizedBox(
width: 10,
),
Column(
children: <Widget>[
Text(
'14 °F',
style: TextStyle(
fontSize: 30,
color: Colors.white,
),
),
Text(
'Light Snow',
style: TextStyle(
fontSize: 18,
color: Colors.white,
),
),
],
)
],
),
);
}
Widget Characteristics() {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
CharacteristicsDetail('5', 'km/hr'),
CharacteristicsDetail('3', '%'),
CharacteristicsDetail('20', '%'),
],
);
}
Widget CharacteristicsDetail(String text1, String text2) {
return Column(
children: [
Icon(
Icons.snowing,
size: 60,
color: Colors.white,
),
Text(
text1,
style: TextStyle(
fontSize: 28,
color: Colors.white,
),
),
Text(
text2,
style: TextStyle(
fontSize: 16,
color: Colors.white,
),
)
],
);
}
class _HorizontalSlider extends State<HorizontalSlider> {
@override
Widget build(BuildContext context) {
return ListView(
scrollDirection: Axis.horizontal,
itemExtent: 100,
children: [
CustomCard(
'Friday',
'6°F',
),
CustomCard(
'Saturday',
'5°F',
),
CustomCard(
'Saturday',
'5°F',
),
CustomCard(
'Sunday',
'7°F',
),
CustomCard(
'Monday',
'8°F',
),
CustomCard(
'Tuesday',
'4°F',
),
CustomCard(
'Wednesday',
'6°F',
),
CustomCard(
'Thursday',
'9°F',
),
],
);
}
}
Widget CustomCard(String dayOfWeek, String temperature) {
return Card(
margin: EdgeInsets.all(30),
color: Colors.redAccent,
child: Column(
children: <Widget>[
Text(
'$dayOfWeek',
style: TextStyle(
fontSize: 24,
color: Colors.white,
),
),
Row(
children: [
Text(
'$temperature',
style: TextStyle(
fontSize: 24,
color: Colors.white,
),
),
Icon(
Icons.wb_sunny,
color: Colors.white,
)
],
)
],
),
);
}```
[1]: https://i.stack.imgur.com/dJlV2.png