Home > Software design >  flutter with add svg to a specific part
flutter with add svg to a specific part

Time:09-17

I currently have a page with an image like this, but I want to add an svg image to the button section at the bottom as in the second image. How can I do it?

İmages

enter image description here

enter image description here

My Code :

import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'URL Shortener',
      theme: ThemeData(
        primarySwatch: Colors.purple,
      ),
      home: StartPage(),
    );
  }
}

class StartPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.grey[300],
        body: Center(
          child: ListView(
            children: [
              Center(
                child: Text(
                  "Shortly",
                  style: TextStyle(
                      fontSize: 40,
                      height: 2.0,
                      color: Color.fromRGBO(53, 50, 62, 10),
                      fontWeight: FontWeight.bold),
                ),
              ),
              SvgPicture.asset(
                'assets/illustration.svg',
              ),
              Center(
                child: Text(
                  "Let's get started!",
                  style: TextStyle(
                      fontSize: 20,
                      color: Color.fromRGBO(53, 50, 62, 10),
                      fontWeight: FontWeight.bold),
                ),
              ),
              Center(
                child: SizedBox(
                  width: 200,
                  height: 60,
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Text(
                        "Paste your first link into the field to shorten it",
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            fontSize: 15,
                            color: Color.fromRGBO(76, 74, 85, 10),
                            fontWeight: FontWeight.bold)),
                  ),
                ),
              ),
              Center(
                child: SizedBox(
                  width: 300,
                  height: 40,
                  child: TextField(
                    textAlign: TextAlign.center,
                    decoration: InputDecoration(
                        contentPadding: EdgeInsets.all(10.0),
                        border: OutlineInputBorder(
                          borderRadius: const BorderRadius.all(
                            const Radius.circular(10.0),
                          ),
                          borderSide: BorderSide(
                            width: 0,
                            style: BorderStyle.none,
                          ),
                        ),
                        fillColor: Colors.white,
                        filled: true,
                        hintText: 'Shorten a link here ...'),
                  ),
                ),
              ),
              Center(
                child: SizedBox(
                  width: 300,
                  child: ElevatedButton(
                    onPressed: () {
                      print("Button Click");
                    },
                    style: ElevatedButton.styleFrom(
                      primary: Colors.blue,
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(10.0)),
                      minimumSize: Size(60, 40),
                    ),
                    child: Text('SHORTEN IT!'),
                  ),
                ),
              )
            ],
          ),
        ));
  }
}

Hello, I currently have a page with an image like this, but I want to add an svg image to the button section at the bottom as in the second image. How can I do it?

CodePudding user response:

Demo Widget

class StartPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[300],
      body: ListView(
        children: [
          Center(
            child: Text(
              "Shortly",
              style: TextStyle(
                  fontSize: 40,
                  height: 2.0,
                  color: Color.fromRGBO(53, 50, 62, 10),
                  fontWeight: FontWeight.bold),
            ),
          ),
          // SvgPicture.asset(
          //   'assets/illustration.svg',
          // ),

          Container(
            height: 200,
            color: Colors.deepPurple.withOpacity(.3),
            child: Text("SVG assets here"),
          ),
          Center(
            child: Text(
              "Let's get started!",
              style: TextStyle(
                  fontSize: 20,
                  color: Color.fromRGBO(53, 50, 62, 10),
                  fontWeight: FontWeight.bold),
            ),
          ),
          Center(
            child: SizedBox(
              width: 200,
              height: 60,
              child: Padding(
                padding: const EdgeInsets.all(8.0),
                child: Text(
                    "Paste your first link into the field to shorten it",
                    textAlign: TextAlign.center,
                    style: TextStyle(
                        fontSize: 15,
                        color: Color.fromRGBO(76, 74, 85, 10),
                        fontWeight: FontWeight.bold)),
              ),
            ),
          ),

          SizedBox(
            /// bottombackground height
            height: 220,
            child: Stack(
              alignment: Alignment.center,
              children: [
                /// background svg asset
                Container(
                  color: Colors.deepOrange.withOpacity(.4),
                ),
                Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    SizedBox(
                      width: 300,
                      height: 40,
                      child: TextField(
                        textAlign: TextAlign.center,
                        decoration: InputDecoration(
                            contentPadding: EdgeInsets.all(10.0),
                            border: OutlineInputBorder(
                              borderRadius: const BorderRadius.all(
                                const Radius.circular(10.0),
                              ),
                              borderSide: BorderSide(
                                width: 0,
                                style: BorderStyle.none,
                              ),
                            ),
                            fillColor: Colors.white,
                            filled: true,
                            hintText: 'Shorten a link here ...'),
                      ),
                    ),

                    /// a little space between buttons
                    SizedBox(
                      height: 10,
                    ),
                    SizedBox(
                      width: 300,
                      child: ElevatedButton(
                        onPressed: () {
                          print("Button Click");
                        },
                        style: ElevatedButton.styleFrom(
                          primary: Colors.blue,
                          shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(10.0)),
                          minimumSize: Size(60, 40),
                        ),
                        child: Text('SHORTEN IT!'),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

CodePudding user response:

  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.grey[300],
        body: Center(
          child: Container(
            height:MediaQuery.of(context).size.height,
            width:MediaQuery.of(context).size.width,
            child: Stack(
              children: [
                SvgPicture.asset(
                  "assets/a.svg",
                  fit: BoxFit.fill,
                ),
                Column(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween ,
                  children: [
                    Center(
                      child: Container(
                        margin: EdgeInsets.only(top:20.0),
                        child: Text(
                          "Shortly",
                          style: TextStyle(
                              fontSize: 40,
                              height: 2.0,
                              color: Color.fromRGBO(53, 50, 62, 10),
                              fontWeight: FontWeight.bold),
                        ),
                      ),
                    ),
                    Column(
                      children: [
                        Center(
                          child: Container(
                            margin: EdgeInsets.only(top:200.0),
                            child: Text(
                              "Let's get started!",
                              style: TextStyle(
                                  fontSize: 20,
                                  color: Color.fromRGBO(53, 50, 62, 10),
                                  fontWeight: FontWeight.bold),
                            ),
                          ),
                        ),
                        Center(
                          child: SizedBox(
                            width: 200,
                            height: 60,
                            child: Padding(
                              padding: const EdgeInsets.all(8.0),
                              child: Text(
                                  "Paste your first link into the field to shorten it",
                                  textAlign: TextAlign.center,
                                  style: TextStyle(
                                      fontSize: 15,
                                      color: Color.fromRGBO(76, 74, 85, 10),
                                      fontWeight: FontWeight.bold)),
                            ),
                          ),
                        ),
                      ],
                    ),
                    Container(
                      height: 150.0,
                      color: Colors.purple,

                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Center(
                            child: Container(
                              width: 300,
                              height: 40,
                              child: TextField(
                                textAlign: TextAlign.center,
                                decoration: InputDecoration(
                                    contentPadding: EdgeInsets.all(10.0),
                                    border: OutlineInputBorder(
                                      borderRadius: const BorderRadius.all(
                                        const Radius.circular(10.0),
                                      ),
                                      borderSide: BorderSide(
                                        width: 0,
                                        style: BorderStyle.none,
                                      ),
                                    ),
                                    fillColor: Colors.white,
                                    filled: true,
                                    hintText: 'Shorten a link here ...'),
                              ),
                            ),
                          ),
                          Center(
                            child: SizedBox(
                              width: 300,
                              child: ElevatedButton(
                                onPressed: () {
                                  print("Button Click");
                                },
                                style: ElevatedButton.styleFrom(
                                  primary: Colors.blue,
                                  shape: RoundedRectangleBorder(
                                      borderRadius: BorderRadius.circular(10.0)),
                                  minimumSize: Size(60, 40),
                                ),
                                child: Text('SHORTEN IT!'),
                              ),
                            ),
                          ),
                        ],
                      ),
                    )
                  ],
                ),
              ],
            ),
          ),
        ));
  }

  • Related