Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- void main() {
- runApp(const GradientApp());
- }
- class GradientApp extends StatelessWidget {
- const GradientApp({super.key});
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- title: 'Gradient App',
- home: const GradientScreen(),
- );
- }
- }
- class GradientScreen extends StatelessWidget {
- const GradientScreen({super.key});
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- body: Container(
- decoration: const BoxDecoration(
- gradient: LinearGradient(
- begin: Alignment.topLeft,
- end: Alignment.bottomRight,
- colors: [
- Color(0xFFE66465), // Example color 1 - you can change these
- Color(0xFF9198E5), // Example color 2
- // Add more colors for a more complex gradient
- // Color(0xFF673AB7),
- ],
- ),
- ),
- child: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- // Your Logo/Icon
- Image.asset( // Replace with your actual asset path
- 'assets/your_logo.png', // Make sure to add the asset in pubspec.yaml
- height: 100, // Adjust size as needed
- ),
- const SizedBox(height: 20), // Spacing
- ElevatedButton(
- onPressed: () {
- // Button 1 action
- print("Button 1 pressed");
- },
- style: ElevatedButton.styleFrom(
- backgroundColor: Colors.white, // Button color
- foregroundColor: Colors.black, // Text color
- ),
- child: const Text('Button 1'),
- ),
- const SizedBox(height: 10),
- ElevatedButton(
- onPressed: () {
- // Button 2 action
- print("Button 2 pressed");
- },
- style: ElevatedButton.styleFrom(
- backgroundColor: Colors.white,
- foregroundColor: Colors.black,
- ),
- child: const Text('Button 2'),
- ),
- const SizedBox(height: 10),
- OutlinedButton( // Example of an OutlinedButton
- onPressed: () {
- print("Outlined Button pressed");
- },
- style: OutlinedButton.styleFrom(
- foregroundColor: Colors.white, // Text color
- side: const BorderSide(color: Colors.white), // Border color
- ),
- child: const Text("Outlined Button"),
- ),
- ],
- ),
- ),
- ),
- );
- }
- }
- **Key improvements and explanations:**
- 1. **Gradient:** Uses `LinearGradient` within a `BoxDecoration` to create the gradient background. You can easily customize the `colors` array to achieve your desired gradient effect. I've provided two example colors, but you can add more for a more complex gradient. The `begin` and `end` properties control the direction of the gradient.
- 2. **Logo/Icon:** Includes an `Image.asset` widget as a placeholder for your logo. **Crucially,** you need to:
- - Place your logo image (e.g., `your_logo.png`) in your project's `assets` folder (create this folder if it doesn't exist).
- - Declare the asset in your `pubspec.yaml` file under the `flutter` section, like this:
- yaml:
- flutter:
- assets:
- - assets/your_logo.png # Path to your logo
- - assets/ # To include all files in the folder
- 3. **Buttons:** Uses `ElevatedButton` for the buttons. I've added some basic styling (background and foreground colors). You can customize the button styles further. I've also included an `OutlinedButton` example.
- 4. **Spacing:** Uses `SizedBox` widgets to add spacing between the logo and the buttons, making the layout cleaner.
- 5. **Centering:** The `Center` widget ensures that the content is centered on the screen. The `Column` arranges the widgets vertically.
- 6. **Comments:** Added comments to explain the code and guide you.
- **How to run this app:**
- 1. **Create a new Flutter project:** If you haven't already, create a new Flutter project using your IDE (Android Studio or VS Code) or the command line: `flutter create my_gradient_app`
- 2. **Replace code:** Replace the contents of `lib/main.dart` with the code provided above.
- 3. **Add your logo:** Place your logo image in the `assets` folder and update the `pubspec.yaml` file as explained above.
- 4. **Run the app:** Run the app using `flutter run`.
- Remember to adjust the colors, button styles, logo path, and button actions to fit your specific design and functionality. This example provides a solid foundation for building your gradient app.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement