How to responsive oriantaion layout
Can you added responsive oriantaion layout
Sorry, I did not understand what you mean. Can you elaborate
Previously we use to use this plugin inside an OrientationBuilder widget, so that we can change the design size on orientation change but now i think it will not be possible since you are wrapping the whole material app inside the ScreenUtilInit init
Previously we use to use this plugin inside an
OrientationBuilderwidget, so that we can change the design size on orientation change but now i think it will not be possible since you are wrapping the whole material app inside theScreenUtilInitinit
In fact, OrientationBuilder is used internally. like this:
OrientationBuilder(
builder:MaterialApp)
Oh okay then can you expose the orientation so that we can know current orientation of the device?
Can you send the example how to orientation
Can you send the example how to orientation
@ashishoffice Sorry i will send an updated sample tomorrow. I am using older version of the lib so i will update it to current version and send you the sample code.
@ashishoffice you can use the below code
base_stateful_widget.dart
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
abstract class BaseStatefulWidget extends StatefulWidget {
BaseStatefulWidget({Key key}) : super(key: key);
}
abstract class BaseState<Page extends BaseStatefulWidget> extends State<Page> {}
mixin BasicPage<Page extends BaseStatefulWidget> on BaseState<Page> {
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () async {
return onBackPress();
},
child: GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
},
child: getBody(
context,
ScreenUtil().orientation,
),
),
);
}
Widget getBody(BuildContext context, Orientation orientation);
bool onBackPress();
}
main.dart
import 'package:demo_app/base_stateful_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: Size(375, 812),
builder: () {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
},
);
}
}
class MyHomePage extends BaseStatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends BaseState<MyHomePage> with BasicPage {
@override
Widget getBody(BuildContext context, Orientation orientation) {
return Scaffold(
appBar: AppBar(
title: Text('Test'),
),
body: _getContainer(orientation),
);
}
@override
bool onBackPress() {
return true;
}
_getContainer(Orientation orientation) {
if (orientation == Orientation.portrait) {
return Center(
child: Container(
height: 200.h,
width: 200.h,
color: Colors.green,
child: Center(
child: Text(
'I am Portrait Container on screenSize ${MediaQuery.of(context).size.height} x ${MediaQuery.of(context).size.width}',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
),
),
),
),
);
} else {
return Center(
child: Container(
height: 200.h,
width: 200.h,
color: Colors.red,
child: Center(
child: Text(
'I am Landscape Container on screenSize ${MediaQuery.of(context).size.height} x ${MediaQuery.of(context).size.width}',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
),
),
),
),
);
}
}
}
I think your problem should be resolved, if anyone has a problem, you can reopen it
Yes it has been thank you for your contribution
Hello @lizhuoyuan , i'm using version 5.0.0+2 and this is not working anymore; How can i change the designSize based on orientation?
Hi @RicardoLimaDev you can orientationbuilder widget. The design size will just interchange you can't have two different designsize.
Hello @lizhuoyuan , i'm using version 5.0.0+2 and this is not working anymore; How can i change the designSize based on orientation?
You only need to set the vertical