Rocio  O'Keefe

Rocio O'Keefe

1657384860

Flutter_sizer: Responsive Sizer Helps Implement Are Responsive Layout

Flutter Sizer

Flutter Sizer helps implement a responsive layout by providing helper widgets and extensions

Responsive Image

Responsive Image

Installation

Add flutter_sizer to pubspec.yaml

dependencies:
  flutter_sizer: ^1.0.4

Parameters

  • Adaptive.h() - Returns a calculated height based on the device
  • Adaptive.w() - Returns a calculated width based on the device
  • Adaptive.sp() - Returns a calculated sp based on the device (deprecated)
  • Adaptive.dp() - Returns a calculated dp based on the device
  • .h - Returns a calculated height based on the device
  • .w - Returns a calculated width based on the device
  • .sp - Returns a calculated sp based on the device (deprecated)
  • .dp - Returns a calculated dp based on the device
  • Device.boxConstraints - Returns the Device's BoxConstraints
  • Device.orientation - Returns the Screen Orientation (portrait or landscape)
  • Device.screenType - Returns the Screen Type (mobile or tablet)
  • Device.devicePixelRatio - Returns the devicePixel Ratio or (1.0)

Usage

Import the Package

import 'package:flutter_sizer/flutter_sizer.dart';

Wrap MaterialApp with FlutterSizer widget

 FlutterSizer(
      builder: (context, orientation, screenType) {
        return MaterialApp();
      }
 )

Widget Size

Container(
  width: Adaptive.w(20),    // This will take 20% of the screen's width
  height: 30.5.h     // This will take 30.5% of the screen's height
)

Font size

Text(
  'Flutter Sizer', 
  style: TextStyle(fontSize: 15.dp),
)

Orientation

If you want to support both portrait and landscape orientations

Device.orientation == Orientation.portrait
  ? Container(   // Widget for Portrait
      width: 100.w,
      height: 20.5.h,
   )
  : Container(   // Widget for Landscape
      width: 100.w,
      height: 12.5.h,
   )

DeviceType

If you want the same layout to look different in tablet and mobile, use the Device.screenType method:

Device.screenType == ScreenType.tablet
  ? Container(   // Widget for Tablet
      width: 100.w,
      height: 20.5.h,
   )
  : Container(   // Widget for Mobile
      width: 100.w,
      height: 12.5.h,
   )

Take Note

You need to import flutter_sizer package in order to access number.h, number.w, and number.dp

Auto import in VSCode and Android Studio doesn't work for dart extension methods. Typing 10.h would not bring up auto import suggestion for this package

One workaround is to type Device so that the auto import suggestion would show up:

import 'package:flutter_sizer/flutter_sizer.dart';

Installing

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add flutter_sizer

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  flutter_sizer: ^1.0.5

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:flutter_sizer/flutter_sizer.dart';

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FlutterSizer(
      builder: (context, orientation, screenType) {
        return MaterialApp(
            title: 'Flutter Sizer Example',
            theme: ThemeData(
              primarySwatch: Colors.blue,
            ),
            home: Home());
      },
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
          child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Container(
            height: Adaptive.h(12.5), // or 12.5.h
            width: 50.w, // or Adaptive.w(50)
            color: Colors.black,
          ),
          Text(
            "Resolution is -> ${100.0.w}x${100.0.h}",
          ),
          Text(
            "This text is responsive 12dp -> ${12.0.dp}",
            style: TextStyle(fontSize: 12.0.dp), // or Adaptive.sp(12)
          ),
          Text(
            "This text is responsive 24dp -> ${24.0.dp}",
            style: TextStyle(fontSize: 24.0.dp), // or Adaptive.sp(12)
          ),
          Device.orientation == Orientation.portrait
              ? Text("My Orientation is Portrait")
              : Text("My Orientation is Landscape"),
          Device.screenType == ScreenType.tablet
              ? Text("My Screen's Type is a Tablet")
              : Text("My Screen's Type is a Phone")
        ],
      )),
    );
  }
}

Community Support

If you have any suggestions or issues, feel free to open an issue

If you would like to contribute, feel free to create a PR

Author: Radvansky-tomas
Source Code: https://github.com/radvansky-tomas/flutter_sizer 
License: MIT license

#flutter #dart #size 

What is GEEK

Buddha Community

Flutter_sizer: Responsive Sizer Helps Implement Are Responsive Layout

Wiyada Yawai

1607523900

How To Create Tabs in Less Than 12 Minutes Using HTML CSS

In this video, We have created a Tab design in HTML and CSS without using JavaScript. I have also provided HTML and CSS code on my website, you can visit my website by clicking given link. 

Subscribe: https://www.youtube.com/@CodingLabYT/featured 

Source Code :

HTML :

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="UTF-8">
    <!--<title> CSS Vertical Tabs </title>-->
    <link rel="stylesheet" href="style.css">
    <!-- Fontawesome CDN Link -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.2/css/all.min.css"/>
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
   </head>
<body>
  <div class="container">
    <div class="topic">CSS Vertical Tabs.</div>
    <div class="content">
      <input type="radio" name="slider" checked id="home">
      <input type="radio" name="slider" id="blog">
      <input type="radio" name="slider" id="help">
      <input type="radio" name="slider" id="code">
      <input type="radio" name="slider" id="about">
      <div class="list">
        <label for="home" class="home">
        <i class="fas fa-home"></i>
        <span class="title">Home</span>
      </label>
      <label for="blog" class="blog">
        <span class="icon"><i class="fas fa-blog"></i></span>
        <span class="title">Blog</span>
      </label>
      <label for="help" class="help">
        <span class="icon"><i class="far fa-envelope"></i></span>
        <span class="title">Help</span>
      </label>
      <label for="code" class="code">
        <span class="icon"><i class="fas fa-code"></i></span>
        <span class="title">Code</span>
      </label>
      <label for="about" class="about">
        <span class="icon"><i class="far fa-user"></i></span>
        <span class="title">About</span>
      </label>
      <div class="slider"></div>
    </div>
      <div class="text-content">
        <div class="home text">
          <div class="title">Home Content</div>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quasi excepturi ducimus sequi dignissimos expedita tempore omnis quos cum, possimus, aspernatur esse nihil commodi est maiores dolorum rem iusto atque, beatae voluptas sit eligendi architecto dolorem temporibus. Non magnam ipsam, voluptas quasi nam dicta ut. Ad corrupti aliquid obcaecati alias, nemo veritatis porro nisi eius sequi dignissimos ea repellendus quibusdam minima ipsum animi quae, libero quisquam a! Laudantium iste est sapiente, ullam itaque odio iure laborum voluptatem quaerat tempore doloremque quam modi, atque minima enim saepe! Dolorem rerum minima incidunt, officia!</p>
        </div>
        <div class="blog text">
          <div class="title">Blog Content</div>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Alias tempora, unde reprehenderit incidunt excepturi blanditiis ullam dignissimos provident quam? Fugit, enim! Architecto ad officiis dignissimos ex quae iusto amet pariatur, ea eius aut velit, tempora magnam hic autem maiores unde corrupti tenetur delectus! Voluptatum praesentium labore consectetur ea qui illum illo distinctio, sunt, ipsam rerum optio quibusdam cum a? Aut facilis non fuga molestiae voluptatem omnis reprehenderit, dignissimos commodi repellat sapiente natus ipsam, ipsa distinctio. Ducimus repudiandae fuga aliquid, numquam.</p>
        </div>
        <div class="help text">
          <div class="title">Help Content</div>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Maiores error neque, officia excepturi dolores quis dolor, architecto iusto deleniti a soluta nostrum. Fuga reiciendis beatae, dicta voluptatem, vitae eligendi maxime accusamus. Amet totam aut odio velit cumque autem neque sequi provident mollitia, nisi sunt maiores facilis debitis in officiis asperiores saepe quo soluta laudantium ad non quisquam! Repellendus culpa necessitatibus aliquam quod mollitia perspiciatis ducimus doloribus perferendis autem, omnis, impedit, veniam qui dolorem? Ipsam nihil assumenda, sit ratione blanditiis eius aliquam libero iusto, dolorum aut perferendis modi laboriosam sint dolor.</p>
        </div>
        <div class="code text">
          <div class="title">Code Content</div>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Tempore magnam vitae inventore blanditiis nam tenetur voluptates doloribus error atque reprehenderit, necessitatibus minima incidunt a eius corrupti placeat, quasi similique deserunt, harum? Quia ut impedit ab earum expedita soluta repellat perferendis hic tempora inventore, accusantium porro consequuntur quisquam et assumenda distinctio dignissimos doloremque enim nemo delectus deserunt! Ullam perspiciatis quae aliquid animi quam amet deleniti, at dolorum tenetur, tempore laborum.</p>
        </div>
        <div class="about text">
          <div class="title">About Content</div>
          <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Necessitatibus incidunt possimus quas ad, sit nam veniam illo ullam sapiente, aspernatur fugiat atque. Laboriosam libero voluptatum molestiae veniam earum quisquam, laudantium aperiam, eligendi dicta animi maxime sunt non nisi, ex, ipsa! Soluta ex, quibusdam voluptatem distinctio asperiores recusandae veritatis optio dolorem illo nesciunt quos ullam, dicta numquam ipsam cumque sed. Blanditiis omnis placeat, enim sit dicta eligendi voluptatibus laborum consectetur repudiandae tempora numquam molestiae rerum mollitia nemo. Velit perspiciatis, nesciunt, quo illo quas error debitis molestiae et sapiente neque tempore natus?</p>
        </div>
      </div>
    </div>
  </div>

</body>
</html>

CSS :

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;300;400;500;600;700&display=swap');
*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Poppins', sans-serif;
}
body{
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #dad3f8;
}
::selection{
  background: #6d50e2;
  color: #fff;
}
.container{
  max-width: 950px;
  width: 100%;
  padding: 40px 50px  40px  40px;
  background: #fff;
  margin: 0 20px;
  border-radius: 12px;
  box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}
.container .topic{
  font-size: 30px;
  font-weight: 500;
  margin-bottom: 20px;
}
.content{
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.content .list{
  display: flex;
  flex-direction: column;
  width: 20%;
  margin-right: 50px;
  position: relative;
}
.content .list label{
  height: 60px;
  font-size: 22px;
  font-weight: 500;
  line-height: 60px;
  cursor: pointer;
  padding-left: 25px;
  transition: all 0.5s ease;
  color: #333;
  z-index: 12;
}
#home:checked ~ .list label.home,
#blog:checked ~ .list label.blog,
#help:checked ~ .list label.help,
#code:checked ~ .list label.code,
#about:checked ~ .list label.about{
  color: #fff;
}
.content .list label:hover{
  color: #6d50e2;
}
.content .slider{
  position: absolute;
  left: 0;
  top: 0;
  height: 60px;
  width: 100%;
  border-radius: 12px;
  background: #6d50e2;
  transition: all 0.4s ease;
}
#home:checked ~ .list .slider{
  top: 0;
}
#blog:checked ~ .list .slider{
  top: 60px;
}
#help:checked ~ .list .slider{
  top: 120px;
}
#code:checked ~ .list .slider{
  top: 180px;
}
#about:checked ~ .list .slider{
  top: 240px;
}
.content .text-content{
  width: 80%;
  height: 100%;
}
.content .text{
  display: none;
}
.content .text .title{
  font-size: 25px;
  margin-bottom: 10px;
  font-weight: 500;
}
.content .text p{
  text-align: justify;
}
.content .text-content .home{
  display: block;
}
#home:checked ~ .text-content .home,
#blog:checked ~ .text-content .blog,
#help:checked ~ .text-content .help,
#code:checked ~ .text-content .code,
#about:checked ~ .text-content .about{
  display: block;
}
#blog:checked ~ .text-content .home,
#help:checked ~ .text-content .home,
#code:checked ~ .text-content .home,
#about:checked ~ .text-content .home{
  display: none;
}
.content input{
  display: none;
}

Download Code Files

#javascript #html #css

Rocio  O'Keefe

Rocio O'Keefe

1653475260

Responsive Sizer Helps Implement A Responsive Layout

Responsive Sizer

Responsive Sizer helps implement a responsive layout by providing helper widgets and extensions.

Responsive Image

Responsive Image

Installation

Add responsive_sizer to pubspec.yaml

dependencies:
  responsive_sizer: ^3.0.8

Usage

Import the Package

import 'package:responsive_sizer/responsive_sizer.dart';

Wrap MaterialApp with ResponsiveSizer widget

ResponsiveSizer( 
  builder: (context, orientation, screenType) {
    return MaterialApp(
      home: HomePage(),
    );
  },
);

Widget Size

Container(
  width: Adaptive.w(20),    // This will take 20% of the screen's width
  height: 30.5.h     // This will take 30.5% of the screen's height
)

Font size

Text(
  'Responsive Sizer', 
  style: TextStyle(fontSize: 15.dp), 
  // 15.sp can also be used instead of .dp
  // To know their differences, check #FAQ
)

Orientation

If you want to support both portrait and landscape orientations

Device.orientation == Orientation.portrait
  ? Container(   // Widget for Portrait
      width: 100.w,
      height: 20.5.h,
   )
  : Container(   // Widget for Landscape
      width: 100.w,
      height: 12.5.h,
   )

ScreenType

If you want the same layout to look different in tablet and mobile, use the Device.screenType method:

Device.screenType == ScreenType.tablet
  ? Container(   // Widget for Tablet
      width: 100.w,
      height: 20.5.h,
   )
  : Container(   // Widget for Mobile
      width: 100.w,
      height: 12.5.h,
   )

Parameters

ResponsiveSizer

  • maxMobileWidth - Maximum width of a mobile device (If the device's width is larger than this, it will be categorized as a tablet) - Default value: 599

Extensions

  • Adaptive.h() or .h - Calculated percentage of the device's height (40.h -> 40% of device's height)
  • Adaptive.w() or .w - Calculated percentage of the device's width (40.w -> 40% of device's width)
  • Adaptive.sp() or .sp - Calculated sp based on the device's pixel density and aspect ratio (See FAQ)
  • Adaptive.dp() or .dp - Calculated dp based on the device's pixel density (See FAQ)
     
  • Device.boxConstraints - BoxConstraints of the device
  • Device.orientation - Screen Orientation of the device (portrait or landscape)
  • Device.screenType - Screen type of the device (mobile or tablet)
  • Device.aspectRatio - Aspect ratio of the device
  • Device.pixelRatio - Pixel density ratio of the device

 

  • Adaptive.cm() or .cm - The respective value in value in centimeters
  • Adaptive.mm() or .mm - The respective value in value in millimeters
  • Adaptive.Q() or .Q - The respective value in quarter-millimeters
  • Adaptive.inches() or .inches - The respective value in inches
  • Adaptive.pc() or .pc - The respective value in picas (1/6th of 1 inch)
  • Adaptive.pt() or .pt - The respective value in points (1/72th of 1 inch)
  • Adaptive.px() or .px - The respective value in pixels

Take Note

You need to import responsive_sizer package in order to access number.h, number.w, number.dp, and number.sp

Auto import in VSCode and Android Studio doesn't work for dart extension methods. Typing 10.h would not bring up auto import suggestion for this package

One workaround is to type Device so that the auto import suggestion would show up:

import 'package:responsive_sizer/responsive_sizer.dart';

FAQ

What is the difference between .sp and .dp?

.dp is calculated based on Material Design's dp calculation while.sp is calculated based on the device's pixel density and aspect ratio

Community Support

If you have any suggestions or issues, feel free to open an issue

If you would like to contribute, feel free to create a PR

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add responsive_sizer

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  responsive_sizer: ^3.0.8

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:responsive_sizer/responsive_sizer.dart';

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ResponsiveSizer(
      builder: (context, orientation, screenType) {
        return MaterialApp(
          title: 'Responsive Sizer Example',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: Home(),
        );
      },
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          Container(
            height: Adaptive.h(12.5), // or 12.5.h
            width: 50.w, // or Adaptive.w(50)
            color: Colors.black,
          ),
          Text(
            "This text is responsive",
            style: TextStyle(fontSize: 18.sp), // or Adaptive.sp(12)
          ),
          Text(
            "w=${100.w} h=${100.h}",
            style: TextStyle(fontSize: 12.sp),
          ),
          Device.orientation == Orientation.portrait
              ? Text("My orientation is Portrait")
              : Text("My orientation is Landscape"),
          Device.screenType == ScreenType.tablet
              ? Text("My screen's type is a Tablet")
              : Text("My screen's type is a Phone"),
        ],
      ),
    );
  }
}

Author: CoderUni
Source Code: https://github.com/CoderUni/responsive_sizer
License: MIT license

#flutter #dart #responsive 

Max Willor

Max Willor

1596170547

Is My Assignment Help Legit?

Yes, the assignment help is quite legitimate. If you are struggling to complete the assignment then you can take the support of My Assignment Help Sydney. We are discussing certain features that will help to get good grades in the assignment.

Timely delivery- My assignment help will help to submit the assignment on time. The writers will ensure that orders are completed before deadline. They also proofread the content and look for errors before the final submission.

24 by 7 help- The experts work 24 by 7 according to the convenience. Also, the experts are available round the clock. You can contact assignment writing services or assignment help Sydney through email, phone and live chat.

Experienced professionals- Creativity, knowledge and experience are three attributes that must be considered while hiring the writer. All the professionals from my assignment help Sydney are master and PHD from reputed universities.

Original content- You will get the original and genuine content from the experts. You will get plag free work and experts will do proofreading and editing of content. They use trustworthy plagiarism detection software. The experts follow strict policies against duplicate content. The experts provide personalized assignments of all types.

Services of subjects- The experts provide the assignment writing services of all subjects.

Original content report on demand- The assignment is checked through the reliable software. Also, the experts can share the report if requested.

High-quality work- The experts do the high-quality work. They look for errors and take the reference from reliable content.

Unlimited revisions- The experts will do unlimited revisions. We understand that eve after the final submission the professor can ask for adding or deleting some content. So, you can take the support of my assignment help.

Best guarantee of price- you will get the personalized services at the best price. Assignment help Sydney assure you to provide best quote in market.

So, my assignment help is a reliable and legitimate service. You can take the support of Assignment Help Sydney. They have a team of experts that will help to write the original content. The proofreaders proofread the content and look for errors. They look for spelling, vocabulary and sentence formation errors.

Hence, you can take the support of assignment help. You have to subscribe at the website. The experts will get in touch with you. So, you can take the help of assignment help services.

Are you seeking online assignment help? Are you not able to select the best professionals?
myassignmenthelpau is one of the renowned online assignment help service providers in the world. Your assignments will be written by those experts who have thorough knowledge of the subject. Our company serve the needs of all the students who need assignment help. The term assignment means everything from simple essays to complicated dissertations. One of the reasons why this is the best assignment writing service you could have at your side is because we cover everything you require.

• A+ quality assignments
• 50+ subjects assignment
• On-time delivery
• 100% confidential
• 3000+ experts

#assignment help #my assignment help #buy assignment online #online assignment help #online assignment help #assignment help melbourne

Max Willor

Max Willor

1595933099

How To Identify The Right Finance Assignment Help Service – Know The 5 Tips!

Are you looking for the Finance Assignment Help service? If yes, then don’t worry because we are here to help you out in that. When you will look out in search of finance writing help service, you will find plethora of options available over online and offline platform. If you want to identify the right assignment help service, stay tuned with the mentioned details right below. Here the top 5 tips are mentioned for the identification.

Know what finance assignment help is:

Finance assignments are like the nightmares for the students. Making a finance assignment requires lots of research, analysis, observation, playing with numbers, and much more. The most important thing to know about finance assignment is that, it should be present in perfect manner. Hiring the finance assignment help service is perfect to make an appropriate assignment.

Calculate the experience of finance assignment help service

When you are going to hire the assignment help service, you must calculate the experience of the assignment writing service. Experience means perfection. If the company is well experienced, that means the company had dealt with different types of finance assignment also. So the more company is experienced, the better they will make the assignment.

What about recommendations?

If you want to hire the finance assignment help service, make sure to know what the rrcommendations are. Ask from your friends, classmates and even from the seniors to take recommendations for the right service. Obviously, you are not the one, who is thinking to hire the assignment help service. Your fellows will tell you about different writing companies, from where you can take help for your assignment.

What about cost of the assignment?

One should also consider the cost of the assignment help service. Different companies asks for different costs for making the assignments, so better is to select the one, who is better at making the assignment, plus ask for affordable price also. If you will research in a proper manner, then you will definitely find the one, who will charge affordable amount from you for making the finance assignment.
What is the delivery status?

One should ask for the delivery time of the assignment by the expert writers. Check out the status of delivery of the assignment helps service, so that you can find the reliable one.

Hope that now you will find the suitable finance and marketing Assignment Help service to get the best assignment done with perfection.

If you need online assignment Help, then we are the right place for you. When you look for assignment help services online, you will find a good reputation of us in the market. Have a look at the testimonials and reviews given our users, you’ll find that they are using our services repeatedly. We deliver excellent quality on any subject and that also before deadlines. Some of the benefits we offer are listed below:

• Affordable prices
• Attractive discounts
• Timely submissions
• Quick response

#finance assignment help #finance assignment help online #business finance assignment help #mba finance assignment help #assignment help

Rocio  O'Keefe

Rocio O'Keefe

1657384860

Flutter_sizer: Responsive Sizer Helps Implement Are Responsive Layout

Flutter Sizer

Flutter Sizer helps implement a responsive layout by providing helper widgets and extensions

Responsive Image

Responsive Image

Installation

Add flutter_sizer to pubspec.yaml

dependencies:
  flutter_sizer: ^1.0.4

Parameters

  • Adaptive.h() - Returns a calculated height based on the device
  • Adaptive.w() - Returns a calculated width based on the device
  • Adaptive.sp() - Returns a calculated sp based on the device (deprecated)
  • Adaptive.dp() - Returns a calculated dp based on the device
  • .h - Returns a calculated height based on the device
  • .w - Returns a calculated width based on the device
  • .sp - Returns a calculated sp based on the device (deprecated)
  • .dp - Returns a calculated dp based on the device
  • Device.boxConstraints - Returns the Device's BoxConstraints
  • Device.orientation - Returns the Screen Orientation (portrait or landscape)
  • Device.screenType - Returns the Screen Type (mobile or tablet)
  • Device.devicePixelRatio - Returns the devicePixel Ratio or (1.0)

Usage

Import the Package

import 'package:flutter_sizer/flutter_sizer.dart';

Wrap MaterialApp with FlutterSizer widget

 FlutterSizer(
      builder: (context, orientation, screenType) {
        return MaterialApp();
      }
 )

Widget Size

Container(
  width: Adaptive.w(20),    // This will take 20% of the screen's width
  height: 30.5.h     // This will take 30.5% of the screen's height
)

Font size

Text(
  'Flutter Sizer', 
  style: TextStyle(fontSize: 15.dp),
)

Orientation

If you want to support both portrait and landscape orientations

Device.orientation == Orientation.portrait
  ? Container(   // Widget for Portrait
      width: 100.w,
      height: 20.5.h,
   )
  : Container(   // Widget for Landscape
      width: 100.w,
      height: 12.5.h,
   )

DeviceType

If you want the same layout to look different in tablet and mobile, use the Device.screenType method:

Device.screenType == ScreenType.tablet
  ? Container(   // Widget for Tablet
      width: 100.w,
      height: 20.5.h,
   )
  : Container(   // Widget for Mobile
      width: 100.w,
      height: 12.5.h,
   )

Take Note

You need to import flutter_sizer package in order to access number.h, number.w, and number.dp

Auto import in VSCode and Android Studio doesn't work for dart extension methods. Typing 10.h would not bring up auto import suggestion for this package

One workaround is to type Device so that the auto import suggestion would show up:

import 'package:flutter_sizer/flutter_sizer.dart';

Installing

Use this package as a library

Depend on it

Run this command:

With Flutter:

 $ flutter pub add flutter_sizer

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

dependencies:
  flutter_sizer: ^1.0.5

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:flutter_sizer/flutter_sizer.dart';

example/lib/main.dart

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

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FlutterSizer(
      builder: (context, orientation, screenType) {
        return MaterialApp(
            title: 'Flutter Sizer Example',
            theme: ThemeData(
              primarySwatch: Colors.blue,
            ),
            home: Home());
      },
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
          child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Container(
            height: Adaptive.h(12.5), // or 12.5.h
            width: 50.w, // or Adaptive.w(50)
            color: Colors.black,
          ),
          Text(
            "Resolution is -> ${100.0.w}x${100.0.h}",
          ),
          Text(
            "This text is responsive 12dp -> ${12.0.dp}",
            style: TextStyle(fontSize: 12.0.dp), // or Adaptive.sp(12)
          ),
          Text(
            "This text is responsive 24dp -> ${24.0.dp}",
            style: TextStyle(fontSize: 24.0.dp), // or Adaptive.sp(12)
          ),
          Device.orientation == Orientation.portrait
              ? Text("My Orientation is Portrait")
              : Text("My Orientation is Landscape"),
          Device.screenType == ScreenType.tablet
              ? Text("My Screen's Type is a Tablet")
              : Text("My Screen's Type is a Phone")
        ],
      )),
    );
  }
}

Community Support

If you have any suggestions or issues, feel free to open an issue

If you would like to contribute, feel free to create a PR

Author: Radvansky-tomas
Source Code: https://github.com/radvansky-tomas/flutter_sizer 
License: MIT license

#flutter #dart #size