Create a Image View in Flutter – SwiftUI and Compose

mobile academy

Flutter:


import 'package:flutter/material.dart';

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

  @override
  Widget build(BuildContext context) {
    return Image.asset(
      "assets/image1.jpg",
      fit: BoxFit.fill,
    );
  }
}

SwiftUI:

import SwiftUI

struct ImageView: View {
    var body: some View {
        Image("Image1")
            .resizable()
            .aspectRatio(contentMode: ContentMode.fit)
    }
}

struct ImageView_Previews: PreviewProvider {
    static var previews: some View {
        ImageView()
    }
}

Compose:

@Composable
fun CustomImageView() {
    Image(
        painter = painterResource(id = R.drawable.image1),
        contentDescription = "Image 1",
        modifier = Modifier.fillMaxWidth()
    )
}
Select your currency
USD United States (US) dollar