skip to Main Content

I am using dhiwise to convert my figma prototype into flutter but the header is not appearing and is somehow above the screen. I tried moving it elsewhere but it just puts it outside the header.

current look
what it is supposed to look like

return SafeArea(
 child: Scaffold(
 backgroundColor: ColorConstant.whiteA700,
 body: Container(
 height: size.height,
 width: size.width,
 child: Stack(
 children: [
 Align(
 alignment: Alignment.center,
 child: SingleChildScrollView(
 child: Container(
 height: size.height,
 width: size.width,
 child: Stack(
 alignment: Alignment.topRight,
 children: [
 Align(
 alignment: Alignment.center,
 child: Container(
 height: size.height,
 width: size.width,
 decoration: BoxDecoration(
 color: ColorConstant.whiteA700,
 ),
 child: Stack(
 alignment: Alignment.bottomCenter,
 children: [
 Align(
 alignment: Alignment.topCenter,
 child: Container(
 width: size.width,
 padding: getPadding(
 left: 11,
 top: 7,
 right: 11,
 bottom: 7,
 ),
 decoration: BoxDecoration(
 color: ColorConstant.blue200,
 ),
 child: Column(
 mainAxisSize: MainAxisSize.min,
 crossAxisAlignment:
 CrossAxisAlignment.start,
 mainAxisAlignment:
 MainAxisAlignment.start,
 children: [
 CustomIconButton(
 height: 53,
 width: 53,
 margin: getMargin(
 bottom: 276,
 ),
 child: CustomImageView(
 svgPath: ImageConstant.imgUser,

the custom image view code, this code was directly from the website itself and I have no idea what any of the code means to do

// ignore_for_file: must_be_immutable

import 'dart:io';

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

class CustomImageView extends StatelessWidget {
  ///[url] is required parameter for fetching network image
  String? url;

  ///[imagePath] is required parameter for showing png,jpg,etc image
  String? imagePath;

  ///[svgPath] is required parameter for showing svg image
  String? svgPath;

  ///[file] is required parameter for fetching image file
  File? file;

  double? height;
  double? width;
  Color? color;
  BoxFit? fit;
  final String placeHolder;
  Alignment? alignment;
  VoidCallback? onTap;
  EdgeInsetsGeometry? margin;
  BorderRadius? radius;
  BoxBorder? border;

  ///a [CustomImageView] it can be used for showing any type of images
  /// it will shows the placeholder image if image is not found on network image
  CustomImageView({
    this.url,
    this.imagePath,
    this.svgPath,
    this.file,
    this.height,
    this.width,
    this.color,
    this.fit,
    this.alignment,
    this.onTap,
    this.radius,
    this.margin,
    this.border,
    this.placeHolder = 'assets/images/image_not_found.png',
  });

  @override
  Widget build(BuildContext context) {
    return alignment != null
        ? Align(
      alignment: alignment!,
      child: _buildWidget(),
    )
        : _buildWidget();
  }

  Widget _buildWidget() {
    return Padding(
      padding: margin ?? EdgeInsets.zero,
      child: InkWell(
        onTap: onTap,
        child: _buildCircleImage(),
      ),
    );
  }

  ///build the image with border radius
  _buildCircleImage() {
    if(radius!=null) {
      return ClipRRect(
        borderRadius: radius,
        child: _buildImageWithBorder(),
      );
    }
    else{
      return _buildImageWithBorder();
    }
  }

  ///build the image with border and border radius style
  _buildImageWithBorder(){
    if(border!=null) {
      return Container(
        decoration: BoxDecoration(
          border: border,
          borderRadius: radius,
        ),
        child: _buildImageView(),
      );
    }else{
      return _buildImageView();
    }
  }

  Widget _buildImageView() {
    if (svgPath != null && svgPath!.isNotEmpty) {
      return Container(
        height: height,
        width: width,
        child: SvgPicture.asset(
          svgPath!,
          height: height,
          width: width,
          fit: fit ?? BoxFit.contain,
          color: color,
        ),
      );
    } else if (file != null && file!.path.isNotEmpty) {
      return Image.file(
        file!,
        height: height,
        width: width,
        fit: fit ?? BoxFit.cover,
        color: color,
      );
    } else if (url != null && url!.isNotEmpty) {
      return CachedNetworkImage(
        height: height,
        width: width,
        fit: fit,
        imageUrl: url!,
        color: color,
        placeholder: (context, url) => Container(
          height: 30,
          width: 30,
          child: LinearProgressIndicator(
            color: Colors.grey.shade200,
            backgroundColor: Colors.grey.shade100,
          ),
        ),
        errorWidget: (context, url, error) => Image.asset(
          placeHolder,
          height: height,
          width: width,
          fit: fit ?? BoxFit.cover,
        ),
      );
    } else if (imagePath != null && imagePath!.isNotEmpty) {
      return Image.asset(
        imagePath!,
        height: height,
        width: width,
        fit: fit ?? BoxFit.cover,
        color: color,
      );
    }
    return SizedBox();
  }
}

3

Answers


  1. 1- flutter clean

    2- flutter pub get

    And if it doesn’t work with these instructions, I suggest you look at the link below
    enter link description here

    Login or Signup to reply.
  2. I hope you specified that image as an asset in the pubspec.yaml.

    I mean…

    Flutter uses the pubspec.yaml file, located at the root of your project, to identify assets required by an app.

    flutter:
      assets:
        - assets/my_icon.png
        - assets/background.png
    

    To include all assets under a directory, specify the directory name with the / character at the end:

    flutter:
      assets:
        - directory/
        - directory/subdirectory/
    
    Login or Signup to reply.
  3. If you already specify path of your image (sometimes you need to hot restart if you add new asset)

    please check that svg image was fine by opening it via web. I face the same issues before with svg using SvgPicture I can open svg file on web but not readble in mobile apps. As I remember my error was not valid svg.

    This library only supports <defs> and xlink:href references that are defined ahead of their references.
    

    If do so, maybe you can try this one.

    • save image as PNG from Figma
    • Import image to Adobe XD
    • Export to SVG.
    • Replace current asset with this Adobe XD svg format.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search