responsive_builder package
This is my way of implementing responsive_builder package
References I have used: Article by the Author showing some ways to do this.
- first
home: Home() - return
ScreenTypeLayoutinsideHomefor making layout of the Widgets - use
ScreenTypeLayoutwith individual Widgets making changes required for mobile, tablet or desktop for each Widget OptionalIf very slight changes are for any Widget then make that change usingResponsiveBuilderWidget
home: Home(),
home: Home(),
return CupertinoApp(
debugShowCheckedModeBanner: false,
scrollBehavior: const MyCustomScrollBehavior(),
title: 'Flutter Web Responsive Website',
home: Home(),
);
return ScreenTypeLayout
ScreenTypeLayout for Layout of the different Widgets
This is only for Layout of Widgets, their Alignment, Positons, Scrolling and other Layout features.
- for individual
Widgetsand the changes we need to make in them based on screen, we again useScreenTypeLayoutinside the Widget itself as is shown in next section on this page
class Home extends StatelessWidget {
const Home({super.key});
Widget build(BuildContext context) {
return ScreenTypeLayout(
mobile: HomeMobile(),
tablet: HomeTablet(),
desktop: HomeWeb(),
// breakpoints: ScreenBreakpoints(tablet: >=600, desktop: >=950, watch: <300, mobile: required default),
);
}
}
Then make complete apps for all three screns
HomeWeb,HomeTablet&HomeMobilewith common Widgets with specific changes in thier own files
create separate Widgets for different screens inside Widget's file.
for individual Widgets and the changes we need to make in them based on screen we again use ScreenTypeLayout inside the Widget itself.
Its different from the the above section because it focuses on individual Widgets and the above section focuses on Layout basis
class NavBar extends StatelessWidget {
const NavBar({super.key});
Widget build(BuildContext context) {
return ScreenTypeLayout(
mobile: const NavBarMobile(),
desktop: const NavBarDesktop(),
tablet: const NavBarTablet(),
);
}
}
using ResponsiveBuilder Widget
ResponsiveBuilderis sued for changes insideoneWidget itself
Refer: https://www.filledstacks.com/post/building-a-responsive-website-using-flutter/#course-details
Extras
breakpoints
The default breakpoints are:
if any of these are to be declared then they will automatically get these breakpoints, So if only we want to make screen of these sizes we decalr them else don't declare the sizes.
- mobile:
>=300&<600required - tablet:
>=600&<950if tablet not declared it will take screen ofdesktop - desktop:
>=950not required butALWAYSdeclare it - watch:
<300NOT NEEDEDif watch not declared it will take screen of mobile
if any of these are not declared then they will get the screen of their next large size
Some Extra Sizing info in 'responsive_builder' prackage
/// Provides a builder function for refined screen sizes to be used with [ScreenTypeLayout]
///
/// Each builder will get built based on the current device width.
/// [breakpoints] define your own custom device resolutions
/// [extraLarge] will be built if width is greater than 2160 on Desktops, 1280 on Tablets, and 600 on Mobiles
/// [large] will be built when width is greater than 1440 on Desktops, 1024 on Tablets, and 414 on Mobiles
/// [normal] will be built when width is greater than 1080 on Desktops, 768 on Tablets, and 375 on Mobiles
/// [small] will be built if width is less than 720 on Desktops, 600 on Tablets, and 320 on Mobiles
const RefinedBreakpoints({
this.mobileSmall = 320,
this.mobileNormal = 375,
this.mobileLarge = 414,
this.mobileExtraLarge = 480,e
this.tabletSmall = 600,
this.tabletNormal = 768,
this.tabletLarge = 850,
this.tabletExtraLarge = 900,
this.desktopSmall = 950,
this.desktopNormal = 1920,
this.desktopLarge = 3840,
this.desktopExtraLarge = 4096,
});
/// Provides a builder function for refined screen sizes to be used with [ScreenTypeLayout]
///
/// Each builder will get built based on the current device width.
/// [breakpoints] define your own custom device resolutions
/// [extraLarge] will be built if width is greater than 2160 on Desktops, 1280 on Tablets, and 600 on Mobiles
/// [large] will be built when width is greater than 1440 on Desktops, 1024 on Tablets, and 414 on Mobiles
/// [normal] will be built when width is greater than 1080 on Desktops, 768 on Tablets, and 375 on Mobiles
/// [small] will be built if width is less than 720 on Desktops, 600 on Tablets, and 320 on Mobiles
const RefinedBreakpoints({
this.mobileSmall = 320,
this.mobileNormal = 375,
this.mobileLarge = 414,
this.mobileExtraLarge = 480,e
this.tabletSmall = 600,
this.tabletNormal = 768,
this.tabletLarge = 850,
this.tabletExtraLarge = 900,
this.desktopSmall = 950,
this.desktopNormal = 1920,
this.desktopLarge = 3840,
this.desktopExtraLarge = 4096,
});