scaler 1.1.0+1 scaler: ^1.1.0+1 copied to clipboard
Set your width height on the basis of percentage of the screen. Its value will be between ( 0 -1 ) set the value between 0 to 1 for 0 to 100% scale to width/height of screen.
import 'package:flutter/material.dart';
import 'package:scaler/scaler.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Scaler Responsive UI Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Set width/height in percentage'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool isVisible = false;
@override
void initState() {
// TODO: implement initState
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
height: Scaler.height(0.25, context),
width: Scaler.width(0.25, context),
child:
Container()), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}