Certainly! Let's walk through each part of your Flutter application to understand its structure, functionality, and purpose. This app appears to be designed for users to select their city and various academic subjects, inputting scores for each selected subject, and then viewing their selections on a results page.
Table of Contents
- Main Function
- Model Class: City
- Custom Input Formatter: MaxValueInputFormatter
- UnixApp Widget
- WelcomePage Widget
- SelectionPage Widget
- CityBottomSheet Widget
- SubjectBlock Widget
- DevelopmentPage Widget
Main Function
Code:
void main() {
runApp(UnixApp());
}
Explanation:
- Purpose: The entry point of the Flutter application.
- Functionality:
runApp(UnixApp()): Initializes the app by running the UnixApp widget, which sets up the entire application's structure.
Model Class: City
Code:
class City {
final int id;
final String name;
City({required this.id, required this.name});
}
Explanation:
- Purpose: Represents a city with a unique identifier and a name.
- Attributes:
id: A unique integer identifier for each city.
name: The name of the city as a String.
- Usage: Instances of this class are used to populate the list of selectable cities in the
SelectionPage.
Custom Input Formatter: MaxValueInputFormatter
Code:
class MaxValueInputFormatter extends TextInputFormatter {
final int max;
MaxValueInputFormatter({required this.max});
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue, TextEditingValue newValue) {
if (newValue.text.isEmpty) {
return newValue;
}
final int? value = int.tryParse(newValue.text);
if (value == null || value > max) {
return oldValue;
}
return newValue;
}
}
Explanation:
- Purpose: Limits the numerical input in text fields to a specified maximum value.
- Attributes:
max: The maximum allowable integer value.
- Functionality:
- Overrides the
formatEditUpdate method to validate user input.
- If the new input exceeds
max or isn't a valid integer, it reverts to the previous valid value (oldValue).
- Ensures that only numbers up to the specified
max can be entered.
UnixApp Widget
Code:
class UnixApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'UNIX App',
debugShowCheckedModeBanner: false,
initialRoute: '/',
routes: {
'/': (context) => WelcomePage(),
'/selection': (context) => SelectionPage(),
// Added secret page route
},
onGenerateRoute: (settings) {
if (settings.name == '/development') {
final args = settings.arguments as Map<String, dynamic>;
return MaterialPageRoute(
builder: (context) {
return DevelopmentPage(
selectedSubjects: args['selectedSubjects'],
selectedCity: args['selectedCity'],
);
},
);
}
assert(false, 'Need to implement ${settings.name}');
return null;
},
theme: ThemeData(
fontFamily: 'Involve', // Set the default font family here
textTheme: TextTheme(
bodyLarge: TextStyle(color: Colors.black),
bodyMedium: TextStyle(color: Colors.black),
// Define other text styles if needed
),
),
);
}
}
Explanation:
- Purpose: Serves as the root of the Flutter application, configuring routes, themes, and other global settings.
- Attributes:
title: The title of the application.
debugShowCheckedModeBanner: Hides the debug banner in the app.
initialRoute: Sets the initial route to '/', which corresponds to WelcomePage.
routes: Defines named routes:
'/': WelcomePage.
'/selection': SelectionPage.
onGenerateRoute: Handles dynamic routing, particularly for the '/development' route, which requires passing arguments (selectedSubjects and selectedCity).
theme: Sets the global theme for the app:
fontFamily: Sets the default font to 'Involve'.
textTheme: Defines text styles with black color for bodyLarge and bodyMedium.
WelcomePage Widget
Code:
class WelcomePage extends StatelessWidget {
final Color darkAccent = Color.fromARGB(255, 0, 0, 0); // Dark blue
// Define the secret phrase
final String secretPhrase = "matrassex";
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor:
Color.fromARGB(255, 255, 255, 240), // Fully opaque light color
body: Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Добро',
style: TextStyle(
fontSize: 32,
color: darkAccent,
fontWeight: FontWeight.bold),
),
Text(
'пожаловать',
style: TextStyle(
fontSize: 32,
color: darkAccent,
fontWeight: FontWeight.bold),
),
Text(
'в',
style: TextStyle(
fontSize: 32,
color: darkAccent,
fontWeight: FontWeight.bold),
),
Text(
'UNIX',
style: TextStyle(
fontSize: 32,
color: darkAccent,
fontWeight: FontWeight.bold),
),
SizedBox(height: 16), // Added spacing for better layout
Text(
'Давай выберем твои предметы',
style: TextStyle(
fontSize: 17,
color: darkAccent,
height: 1.5,
),
textAlign: TextAlign.center, // Center the text
),
SizedBox(height: 30),
ElevatedButton(
onPressed: () {
Navigator.pushNamed(context, '/selection');
},
child: Text(
'Начать',
style: TextStyle(
fontSize: 18, color: Color.fromARGB(255, 255, 255, 240)),
),
style: ElevatedButton.styleFrom(
backgroundColor: darkAccent, // Button background color
padding:
EdgeInsets.symmetric(horizontal: 50.0, vertical: 15.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
),
),
],
),
),
),
);
}
// Method to show the secret phrase dialog
}
Explanation:
- Purpose: Serves as the welcome screen of the app, greeting the user and providing a button to proceed to the subject selection page.
- Attributes:
darkAccent: A color used for text and button backgrounds (set to black in this case).
secretPhrase: A string containing a secret phrase ("matrassex"). Note: While the comment mentions a method to show a dialog for this phrase, the method is not implemented in the provided code.
- Structure:
- Scaffold: Provides the basic visual layout structure.
backgroundColor: Sets a light, opaque background color.
body: Centers its child content.
- Padding: Adds padding around the content.
- Column: Arranges its children vertically, centered on the main axis.
- Text Widgets: Display the welcome message in Russian, each word styled uniformly.
- SizedBox: Adds vertical spacing.
- ElevatedButton: A button labeled
'Начать' ('Start') that, when pressed, navigates to the SelectionPage.
- Styling:
backgroundColor: Uses darkAccent for the button's background.
padding: Adds horizontal and vertical padding for better button size.
shape: Rounds the button's corners.
SelectionPage Widget
Code:
class SelectionPage extends StatefulWidget {
@override
_SelectionPageState createState() => _SelectionPageState();
}
class _SelectionPageState extends State<SelectionPage> {
final Color darkAccent = Color.fromARGB(255, 0, 0, 0); // Simple dark
final Color darkPrimary = Color.fromARGB(
255, 52, 49, 49); // Fully opaque dark green for inactive elements
// State variables for switches
bool russianSelected = false;
bool mathSelected = false;
bool informaticsSelected = false;
bool physicsSelected = false;
bool obshestvoSelected = false;
bool englishSelected = false;
bool chemistrySelected = false;
bool literatureSelected = false;
bool historySelected = false;
bool biologySelected = false;
// Controllers for text fields
TextEditingController russianController = TextEditingController(text: '50');
TextEditingController mathController = TextEditingController(text: '50');
TextEditingController informaticsController =
TextEditingController(text: '50');
TextEditingController physicsController = TextEditingController(text: '50');
TextEditingController obshestvoController = TextEditingController(text: '50');
TextEditingController englishController = TextEditingController(text: '50');
TextEditingController chemistryController = TextEditingController(text: '50');
TextEditingController literatureController =
TextEditingController(text: '50');
TextEditingController historyController = TextEditingController(text: '50');
TextEditingController biologyController = TextEditingController(text: '50');
// State for selected city
City? selectedCity;
@override
void dispose() {
russianController.dispose();
mathController.dispose();
informaticsController.dispose();
physicsController.dispose();
obshestvoController.dispose();
englishController.dispose();
chemistryController.dispose();
literatureController.dispose();
historyController.dispose();
biologyController.dispose();
super.dispose();
}
// Method to collect selected subjects and their scores
Map<String, double> _getSelectedSubjects() {
Map<String, double> selected = {};
if (russianSelected) {
double value = double.tryParse(russianController.text) ?? 0;
selected['Русский'] = value;
}
if (mathSelected) {
double value = double.tryParse(mathController.text) ?? 0;
selected['Математика'] = value;
}
if (informaticsSelected) {
double value = double.tryParse(informaticsController.text) ?? 0;
selected['Информатика'] = value;
}
if (physicsSelected) {
double value = double.tryParse(physicsController.text) ?? 0;
selected['Физика'] = value;
}
if (obshestvoSelected) {
double value = double.tryParse(obshestvoController.text) ?? 0;
selected['Обществознание'] = value;
}
if (englishSelected) {
double value = double.tryParse(englishController.text) ?? 0;
selected['Английский'] = value;
}
if (chemistrySelected) {
double value = double.tryParse(chemistryController.text) ?? 0;
selected['Химия'] = value;
}
if (literatureSelected) {
double value = double.tryParse(literatureController.text) ?? 0;
selected['Литература'] = value;
}
if (historySelected) {
double value = double.tryParse(historyController.text) ?? 0;
selected['История'] = value;
}
if (biologySelected) {
double value = double.tryParse(biologyController.text) ?? 0;
selected['Биология'] = value;
}
return selected;
}
// List of cities in Russia
final List<City> cities = [
City(id: 1, name: 'Москва'),
City(id: 2, name: 'Санкт-Петербург'),
City(id: 3, name: 'Новосибирск'),
City(id: 4, name: 'Екатеринбург'),
City(id: 5, name: 'Нижний Новгород'),
City(id: 6, name: 'Казань'),
City(id: 7, name: 'Красноярск'),
City(id: 8, name: 'Омск'),
City(id: 9, name: 'Самара'),
City(id: 10, name: 'Ростов-на-Дону'),
// Add more cities as needed
];
// Method to show the Bottom Sheet
void _showCityBottomSheet() {
showModalBottomSheet(
context: context,
builder: (context) {
return CityBottomSheet(
cities: cities,
onCitySelected: (City city) {
setState(() {
selectedCity = city;
});
Navigator.pop(context);
},
);
},
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color.fromARGB(255, 255, 255, 240),
appBar: AppBar(
title: Text(
'Выбор предметов',
style: TextStyle(color: darkAccent),
),
backgroundColor: Color.fromARGB(255, 255, 255, 240),
elevation: 0,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: darkAccent),
onPressed: () {
Navigator.pop(context);
},
),
),
body: Column(
children: [
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
Expanded(
child: Text(
selectedCity != null
? 'Город: ${selectedCity!.name}'
: 'Выберите город',
style: TextStyle(fontSize: 18, color: darkAccent),
),
),
ElevatedButton(
onPressed: _showCityBottomSheet,
child: Text(
'Выбрать город',
style: TextStyle(fontSize: 16, color: Colors.white),
),
style: ElevatedButton.styleFrom(
backgroundColor: darkAccent,
padding:
EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
),
),
],
),
),
// Divider
Divider(),
// Expanded to contain the subjects list
Expanded(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
SubjectBlock(
title: 'Русский',
isSelected: russianSelected,
onToggle: (value) {
setState(() {
russianSelected = value;
});
},
controller: russianController,
darkAccent: darkAccent,
darkPrimary: darkPrimary,
icon: Icons.verified, // Added icon
),
SizedBox(height: 20),
SubjectBlock(
title: 'Математика',
isSelected: mathSelected,
onToggle: (value) {
setState(() {
mathSelected = value;
});
},
controller: mathController,
darkAccent: darkAccent,
darkPrimary: darkPrimary,
icon: Icons.functions, // Added icon
),
SizedBox(height: 20),
SubjectBlock(
title: 'Информатика',
isSelected: informaticsSelected,
onToggle: (value) {
setState(() {
informaticsSelected = value;
});
},
controller: informaticsController,
darkAccent: darkAccent,
darkPrimary: darkPrimary,
icon: Icons.dvr, // Added icon
),
SizedBox(height: 20),
SubjectBlock(
title: 'Физика',
isSelected: physicsSelected,
onToggle: (value) {
setState(() {
physicsSelected = value;
});
},
controller: physicsController,
darkAccent: darkAccent,
darkPrimary: darkPrimary,
icon: Icons.rocket_launch, // Added icon
// If not available, use FontAwesomeIcons.rocket,
),
SizedBox(height: 20),
SubjectBlock(
title: 'Обществознание',
isSelected: obshestvoSelected,
onToggle: (value) {
setState(() {
obshestvoSelected = value;
});
},
controller: obshestvoController,
darkAccent: darkAccent,
darkPrimary: darkPrimary,
icon: Icons.local_police, // Added icon
),
SizedBox(height: 20),
SubjectBlock(
title: 'Английский',
isSelected: englishSelected,
onToggle: (value) {
setState(() {
englishSelected = value;
});
},
controller: englishController,
darkAccent: darkAccent,
darkPrimary: darkPrimary,
icon: Icons.translate, // Added icon
),
SizedBox(height: 20),
SubjectBlock(
title: 'Химия',
isSelected: chemistrySelected,
onToggle: (value) {
setState(() {
chemistrySelected = value;
});
},
controller: chemistryController,
darkAccent: darkAccent,
darkPrimary: darkPrimary,
icon: Icons.science, // Added icon
),
SizedBox(height: 20),
SubjectBlock(
title: 'Литература',
isSelected: literatureSelected,
onToggle: (value) {
setState(() {
literatureSelected = value;
});
},
controller: literatureController,
darkAccent: darkAccent,
darkPrimary: darkPrimary,
icon: Icons.book, // Added icon
),
SizedBox(height: 20),
SubjectBlock(
title: 'История',
isSelected: historySelected,
onToggle: (value) {
setState(() {
historySelected = value;
});
},
controller: historyController,
darkAccent: darkAccent,
darkPrimary: darkPrimary,
icon: Icons.public, // Added icon
),
SizedBox(height: 20),
SubjectBlock(
title: 'Биология',
isSelected: biologySelected,
onToggle: (value) {
setState(() {
biologySelected = value;
});
},
controller: biologyController,
darkAccent: darkAccent,
darkPrimary: darkPrimary,
icon: Icons.biotech, // Added icon
),
SizedBox(height: 40),
ElevatedButton(
onPressed: () {
if (selectedCity == null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Пожалуйста, выберите город.'),
backgroundColor: Color.fromARGB(255, 210, 16, 6),
),
);
return;
}
Map<String, double> selectedSubjects =
_getSelectedSubjects();
Navigator.pushNamed(
context,
'/development',
arguments: {
'selectedSubjects': selectedSubjects,
'selectedCity': selectedCity,
},
);
},
child: Text(
'Продолжить',
style: TextStyle(
fontSize: 18,
color: const Color.fromARGB(255, 255, 255, 255)),
),
style: ElevatedButton.styleFrom(
backgroundColor: darkAccent, // Button background color
padding: EdgeInsets.symmetric(
horizontal: 50.0, vertical: 15.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
),
),
],
),
),
),
),
],
),
);
}
}
Explanation:
- Purpose: Allows users to select their city and choose academic subjects they're interested in, along with inputting scores for each selected subject.
- Stateful Widget: Maintains the state of selected subjects, input scores, and the selected city.
Attributes:
-
Colors:
darkAccent: Used for active elements like selected text and buttons.
darkPrimary: Used for inactive elements like unselected switches.
-
State Variables:
- Boolean variables (
russianSelected, mathSelected, etc.) to track whether each subject is selected.
TextEditingController instances for each subject to manage input scores, initialized with a default value of '50'.
selectedCity: Holds the currently selected City object.
-
Cities List:
- A predefined list of
City instances representing various cities in Russia.
Methods:
Build Method:
- Scaffold: Provides the basic visual layout structure.
- AppBar:
- Title:
'Выбор предметов' ('Subject Selection').
- Styled with
darkAccent color and no elevation (flat design).
leading: A back arrow icon that navigates back when pressed.
- Body:
- Column: Arranges its children vertically.
- City Selection Row:
- Displays the selected city or prompts the user to select one.
- An
ElevatedButton labeled 'Выбрать город' ('Choose City') to open the CityBottomSheet.
- Divider: A horizontal line to separate sections.
- Expanded:
- SingleChildScrollView: Makes the content scrollable if it exceeds screen height.
- Padding: Adds padding around the content.
- Column:
- Contains multiple
SubjectBlock widgets, each representing a subject with a title, toggle switch, and optional input field for scores.
- Each
SubjectBlock is separated by SizedBox widgets for spacing.
- ElevatedButton labeled
'Продолжить' ('Continue'):
- Functionality:
- Checks if a city is selected. If not, shows a
SnackBar prompting the user to select a city.
- Collects selected subjects and their scores.
- Navigates to the
DevelopmentPage, passing the selected subjects and city as arguments.
- Styling: Uses
darkAccent for the background with padding and rounded corners.
CityBottomSheet Widget
Code:
class CityBottomSheet extends StatelessWidget {
final List<City> cities;
final Function(City) onCitySelected;
CityBottomSheet({required this.cities, required this.onCitySelected});
@override
Widget build(BuildContext context) {
return Container(
// Adjust height as needed
height: 400,
child: Column(
children: [
SizedBox(height: 10),
Text(
'Выберите город',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
Divider(),
Expanded(
child: ListView.builder(
itemCount: cities.length,
itemBuilder: (context, index) {
City city = cities[index];
return ListTile(
leading: CircleAvatar(
child: Text(city.id.toString()),
backgroundColor: Colors.blueAccent,
foregroundColor: Colors.white,
),
title: Text(city.name),
onTap: () {
onCitySelected(city);
},
);
},
),
),
],
),
);
}
}
Explanation:
- Purpose: Displays a modal bottom sheet containing a list of cities for the user to select from.
- Stateless Widget: Does not maintain its own state; instead, it relies on the parent widget (
SelectionPage) to handle state changes.
Attributes:
cities: A list of City objects to display.
onCitySelected: A callback function that gets triggered when a user selects a city.
Build Method:
- Container:
- Height: Set to
400 pixels (adjustable as needed).
- Column: Arranges its children vertically.
- SizedBox: Adds vertical spacing.
- Text: Displays the title
'Выберите город' ('Choose City') with bold styling.
- Divider: A horizontal line to separate the title from the list.
- Expanded:
- ListView.builder: Dynamically builds a scrollable list of cities.
- ListTile for each city:
- leading: A
CircleAvatar displaying the city's id.
- title: The name of the city.
- onTap: When tapped, calls
onCitySelected with the selected City object and closes the bottom sheet.
SubjectBlock Widget
Code:
class SubjectBlock extends StatelessWidget {
final String title;
final bool isSelected;
final Function(bool) onToggle;
final TextEditingController controller;
final Color darkAccent;
final Color darkPrimary;
final IconData? icon; // Added icon parameter
SubjectBlock({
required this.title,
required this.isSelected,
required this.onToggle,
required this.controller,
required this.darkAccent,
required this.darkPrimary,
this.icon, // Initialize icon
});
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
if (icon != null) ...[
Icon(
icon,
color: darkAccent,
),
SizedBox(width: 8),
],
Expanded(
child: Text(
title,
style: TextStyle(fontSize: 20, color: darkAccent),
),
),
Switch(
value: isSelected,
onChanged: onToggle,
activeColor: darkAccent,
activeTrackColor: darkAccent.withOpacity(0.5),
inactiveThumbColor: darkAccent,
inactiveTrackColor: darkPrimary.withOpacity(0.5),
),
],
),
if (isSelected)
Padding(
padding: const EdgeInsets.only(top: 10.0),
child: TextField(
controller: controller,
keyboardType: TextInputType.number,
inputFormatters: [
FilteringTextInputFormatter.digitsOnly, // Allow only digits
MaxValueInputFormatter(max: 100), // Limit value to 100
],
decoration: InputDecoration(
labelText: 'Баллы (0-100)',
border: OutlineInputBorder(),
// Optional: Add error text or validation
),
onChanged: (value) {
// Optional: Add any additional logic or validation here
},
),
),
],
);
}
}
Explanation:
- Purpose: Represents a single subject block within the
SelectionPage, allowing users to select a subject and input their score if the subject is selected.
- Stateless Widget: Receives all necessary data and callbacks through its constructor without maintaining its own state.
Attributes:
title: The name of the subject (e.g., 'Русский').
isSelected: A boolean indicating whether the subject is selected.
onToggle: A callback function triggered when the switch is toggled.
controller: Controls the text input field for the subject's score.
darkAccent: Color used for active elements like text and switches.
darkPrimary: Color used for inactive elements like the switch track.
icon: An optional IconData to display alongside the subject title.
Build Method:
- Column:
-
Row:
- Icon (if provided): Displays the subject-specific icon with
darkAccent color.
- SizedBox: Adds horizontal spacing between the icon and the text.
- Expanded Text: Displays the subject's title with a font size of
20 and darkAccent color.
- Switch:
- Reflects the
isSelected state.
- When toggled, calls the
onToggle callback to update the state in the parent widget (SelectionPage).
- Styling:
activeColor: Uses darkAccent for the switch's thumb when active.
activeTrackColor: A semi-transparent version of darkAccent for the track when active.
inactiveThumbColor: Uses darkAccent for the thumb when inactive.
inactiveTrackColor: A semi-transparent version of darkPrimary for the track when inactive.
-
Conditional Rendering:
- If
isSelected is true, displays a TextField for users to input their score.
- TextField:
controller: Manages the input text.
keyboardType: Set to number to bring up the numeric keypad.
inputFormatters:
FilteringTextInputFormatter.digitsOnly: Ensures only digits are input.
MaxValueInputFormatter(max: 100): Limits the input value to 100.
- Decoration:
labelText: 'Баллы (0-100)' ('Points (0-100)').
border: Adds an outline border to the text field.
- onChanged: Placeholder for additional logic or validation when the input changes (currently unused).
DevelopmentPage Widget
Code:
class DevelopmentPage extends StatelessWidget {
final Map<String, double> selectedSubjects;
final City? selectedCity;
final Color customTextColor =
Color.fromARGB(255, 255, 253, 253); // Fully white color
DevelopmentPage({required this.selectedSubjects, required this.selectedCity});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color.fromARGB(255, 255, 255, 240),
appBar: AppBar(
title: Text(
'Ваши результаты',
style: TextStyle(color: Color.fromARGB(255, 0, 0, 0)),
),
backgroundColor:
Color.fromARGB(255, 255, 255, 240), // Fully opaque white background
elevation: 0, // Remove shadow
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Color.fromARGB(255, 0, 0, 0)),
onPressed: () {
Navigator.pop(context);
},
),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: selectedSubjects.isNotEmpty
? AnimationLimiter(
child: ListView(
children: [
// Display selected city
if (selectedCity != null)
Card(
color: Colors.blueAccent,
margin: EdgeInsets.symmetric(vertical: 8.0),
child: ListTile(
leading: Icon(
Icons.location_city,
color: Colors.white,
),
title: Text(
'Город: ${selectedCity!.name}',
style: TextStyle(
fontSize: 20,
color: customTextColor,
fontWeight: FontWeight.bold,
),
),
),
),
Divider(),
...selectedSubjects.entries.map((entry) {
return AnimationConfiguration.staggeredList(
position:
selectedSubjects.keys.toList().indexOf(entry.key),
duration: const Duration(milliseconds: 375),
child: SlideAnimation(
verticalOffset: 50.0,
child: FadeInAnimation(
child: Card(
color: Color.fromARGB(255, 31, 31, 31),
margin: EdgeInsets.symmetric(vertical: 8.0),
child: ListTile(
title: Text(
entry.key,
style: TextStyle(
fontSize: 20,
color: customTextColor,
fontWeight: FontWeight.bold,
),
),
subtitle: Text(
'Баллы: ${entry.value.toInt()}',
style: TextStyle(
fontSize: 16,
color: customTextColor,
),
),
),
),
),
),
);
}).toList(),
],
),
)
: Center(
child: Text(
'Нет выбранных предметов.',
style: TextStyle(
fontSize: 20,
color: customTextColor,
),
),
),
),
);
}
}
Explanation:
- Purpose: Displays the user's selected city and subjects along with their inputted scores, using animations for enhanced visual presentation.
- Stateless Widget: Receives data through its constructor and does not maintain its own state.
Attributes:
selectedSubjects: A Map<String, double> containing the selected subjects and their corresponding scores.
selectedCity: The City object representing the user's selected city.
customTextColor: A color set to fully white (Color.fromARGB(255, 255, 253, 253)) used for text within the cards.
Build Method:
- Scaffold:
-
AppBar:
- Title:
'Ваши результаты' ('Your Results'), styled with black color.
backgroundColor: Light background matching the body.
elevation: Set to 0 to remove the shadow.
leading: A back arrow icon that navigates back when pressed.
-
Body:
- Padding: Adds padding around the content.
- Conditional Rendering:
- If
selectedSubjects is not empty:
- AnimationLimiter: Part of the
flutter_staggered_animations package to coordinate animations.
- ListView: Displays a list of widgets.
- Selected City:
- If
selectedCity is not null, displays a Card with the city name.
- Card:
color: Blue accent background.
margin: Vertical spacing.
- ListTile:
leading: A city location icon in white.
title: Text displaying the selected city's name, styled in customTextColor.
- Divider: A horizontal line separating the city from the subjects.
- Subjects List:
- Iterates over
selectedSubjects entries.
- For each subject:
- AnimationConfiguration:
staggeredList: Positions each animation based on the index of the subject.
duration: Sets the animation duration.
- SlideAnimation & FadeInAnimation:
- Creates a sliding and fading effect for each
Card.
- Card:
color: Dark gray background.
margin: Vertical spacing.
- :
Summary
Your Flutter application is thoughtfully structured to guide users through selecting their city and academic subjects, inputting scores for each selected subject, and then viewing the results in an animated summary page. Here's a high-level overview of the workflow:
- WelcomePage: Greets the user and provides a button to start the selection process.
- SelectionPage:
- City Selection: Users select their city from a list presented in a bottom sheet.
- Subject Selection: Users toggle switches for various subjects. When a subject is selected, an input field appears for entering a score between 0 and 100.
- Continue Button: Validates the selection and navigates to the results page, passing the selected data.
- DevelopmentPage: Displays the selected city and subjects with their scores, enhanced with sliding and fading animations for a polished user experience.
Additional Notes:
- Styling: The app maintains a consistent color scheme with
darkAccent and darkPrimary colors used across various widgets for texts, buttons, and backgrounds.
- Animations: Utilizes the
flutter_staggered_animations package to animate the presentation of results, making the UI more engaging.
- Input Validation: Ensures that users can only input valid numerical scores within the specified range (0-100) for each subject.
- Responsiveness: The use of
Expanded, SingleChildScrollView, and responsive padding ensures that the UI adapts well to different screen sizes and orientations.
- Code Organization: Separates concerns by modularizing widgets like
CityBottomSheet and SubjectBlock, enhancing code readability and maintainability.
This structure makes the app user-friendly, efficient, and visually appealing, providing a seamless experience from selection to result display.