Building A Sample Static Automobiles App in Flutter - 2
Building A Sample Static Automobiles App in Flutter - 2
cd vinay_automobiles
dependencies:
flutter:
sdk: flutter
google_fonts: ^5.1.0
3. Save the file and run flutter pub get in the terminal.
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
void main() {
runApp(const ScaffoldBasics());
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
primaryColor: Colors.blue[100],
scaffoldBackgroundColor: Colors.blueGrey[50],
fontFamily: GoogleFonts.montserrat().fontFamily,
),
home: Scaffold(
// We'll add the Scaffold contents in the next steps
),
);
}
}
Explanation:
appBar: AppBar(
foregroundColor: Colors.white,
title: Text(
'Vinay Automobiles',
style: TextStyle(fontFamily: GoogleFonts.montserrat().fontFamily),
),
backgroundColor: Colors.blue[900],
centerTitle: true,
),
Explanation:
body: SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// We'll add the body contents in the next steps
],
),
),
Explanation:
• SingleChildScrollView: This makes the body scrollable if its content is taller than the screen.
• padding: This adds padding around all sides of the content.
• Column: This widget displays its children in a vertical array.
• crossAxisAlignment: CrossAxisAlignment.stretch: This makes the children of the Column
stretch to fill the available horizontal space.
Widget _buildStoreDescription() {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.blue[200],
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(
colors: [Colors.blue[200]!, Colors.blueAccent],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Text(
'Welcome to Vinay Automobiles',
textAlign: TextAlign.center,
style: GoogleFonts.montserrat(
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
const SizedBox(height: 10),
Text(
'Explore our collection of luxurious and reliable automobiles. We provide
top-notch customer service and customization options to suit your needs.',
style: GoogleFonts.montserrat(
fontSize: 16,
color: Colors.white,
),
),
],
),
);
}
children: [
_buildStoreDescription(),
const SizedBox(height: 20),
// More widgets will be added here
],
Explanation:
• Container: This widget lets you customize its child widget with decorations and padding.
• BoxDecoration: This is used to decorate the Container with a gradient background and rounded
corners.
• LinearGradient: This creates a smooth color transition from one color to another.
• Column: This is used to arrange the text widgets vertically.
• Text: These widgets display the store description text.
• GoogleFonts.montserrat(): This applies the Montserrat font to the text.
Widget _buildServices() {
return Card(
elevation: 5,
margin: const EdgeInsets.symmetric(vertical: 10),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Our Services',
style: GoogleFonts.montserrat(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.black,
),
),
const SizedBox(height: 10),
Text(
'1. Car Sales\n'
'2. Maintenance Services\n'
'3. Customization Options\n'
'4. 24/7 Customer Support',
style: GoogleFonts.montserrat(
fontSize: 16,
color: Colors.black,
),
),
],
),
),
);
}
children: [
_buildStoreDescription(),
const SizedBox(height: 20),
_buildServices(),
const SizedBox(height: 20),
// More widgets will be added here
],
Explanation:
• Card: This widget creates a material design card with a slight elevation and rounded corners.
• elevation: This property adds a shadow to the card, making it appear raised.
• Padding: This widget adds padding inside the card.
Widget _buildProductCard(
String title, String subtitle, String imagePath, BuildContext context) {
return Card(
elevation: 5,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
child: SizedBox(
width: 300,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ClipRRect(
borderRadius:
const BorderRadius.vertical(top: Radius.circular(10)),
child: Image.asset(
imagePath,
height: 175,
width: double.infinity,
fit: BoxFit.cover,
),
),
Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Text(
title,
style: GoogleFonts.montserrat(
fontSize: 16,
fontWeight: FontWeight.bold,
color: Colors.black,
),
)
),
const SizedBox(height: 4),
Center(
child: Text(
subtitle,
style: GoogleFonts.montserrat(
fontSize: 14,
fontWeight: FontWeight.w300,
color: Colors.black,
),
)
),
const SizedBox(height: 8),
Center(
child: ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue[200],
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
),
),
child: Text(
'View Details',
style: GoogleFonts.montserrat(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
),
),
],
),
),
],
),
),
);
}
Explanation:
children: [
_buildStoreDescription(),
const SizedBox(height: 20),
_buildServices(),
const SizedBox(height: 20),
_buildSectionTitle('New Arrivals'),
_buildHorizontalProductList([
_buildProductCard(
'Tesla Model S',
'Electric Sedan',
'assets/tesla_model_s.jpg',
context,
),
_buildProductCard(
'Ford Mustang',
'Sports Car',
'assets/ford_mustang.jpg',
context,
),
_buildProductCard(
'Audi Q5',
'Luxury SUV',
'assets/audi_q5.jpg',
context,
),
]),
const SizedBox(height: 20),
_buildSectionTitle('Top Products'),
_buildHorizontalProductList([
_buildProductCard(
'BMW X5',
'Luxury SUV',
'assets/bmw_x5.jpg',
context,
),
_buildProductCard(
'Toyota Camry',
'Sedan',
'assets/toyota_camry.jpg',
context,
),
_buildProductCard(
'Honda Civic',
'Compact Car',
'assets/honda_civic.jpg',
context,
),
]),
const SizedBox(height: 20),
_buildSectionTitle('For You'),
_buildHorizontalProductList([
_buildProductCard(
'Mercedes-Benz C-Class',
'Luxury Sedan',
'assets/mercedes_c_class.jpg',
context,
),
_buildProductCard(
'Volkswagen Golf GTI',
'Hot Hatch',
'assets/vw_golf_gti.jpg',
context,
),
_buildProductCard(
'Lamborghini Urus',
'Super SUV',
'assets/lamborghini_urus.jpg',
context,
),
]),
const SizedBox(height: 20),
],
Note: You'll need to add these images to your assets folder and declare them in your pubspec.yaml file.
Explanation:
• FloatingActionButton: This creates a circular button that floats above the content of the app.
• onPressed: This defines what happens when the button is pressed (currently empty).
• backgroundColor: This sets the background color of the button.
• child: This sets the icon displayed on the button.
drawer: Drawer(
child: ListView(
children: [
DrawerHeader(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.blue,
Colors.blueAccent,
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: Center(
child: Text(
'Vinay Automobiles',
style: GoogleFonts.montserrat(
fontSize: 24,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
),
_buildDrawerItem(context, icon: Icons.home, label: 'Home'),
_buildDrawerItem(context, icon: Icons.shop, label: 'Shop'),
_buildDrawerItem(context, icon: Icons.person, label: 'Profile'),
_buildDrawerItem(context, icon: Icons.info, label: 'About'),
],
),
),
Explanation:
• Drawer: This creates a side menu that can be opened by swiping from the left edge of the screen
or tapping the menu icon in the App