flutter_screenutil
flutter_screenutil copied to clipboard
横竖屏切换BUG
flutter_screenutil: ^5.2.0
操作步骤:
- 先置为横屏
- 横屏状态下跳转到下一个页面
- 在第二个页面切为竖屏
期待的结果: 布局尺寸不会有问题
实际结果: 布局尺寸被放大了
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return ScreenUtilInit(
designSize: const Size(375, 812),
builder: () {
ScreenUtil.setContext(context);
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
},
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(height: 20.w, color: Colors.red),
const Text(
'You have pushed the button this many times:',
),
Container(height: 20.w, color: Colors.blue),
Text(
'0',
style: Theme.of(context).textTheme.headline4,
),
Container(height: 20.w, color: Colors.yellow),
Icon(Icons.abc_outlined, size: 50.w),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push<void>(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) => const NextPage(),
),
);
},
tooltip: 'Increment',
child: const Icon(Icons.add),
),
);
}
}
class NextPage extends StatelessWidget {
const NextPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('NextPage'),
),
body: Column(
children: [
Container(height: 20.w, color: Colors.red),
const Text('NextPage'),
Container(height: 20.w, color: Colors.blue),
Text(
'0',
style: Theme.of(context).textTheme.headline4,
),
Container(height: 20.w, color: Colors.yellow),
Icon(Icons.abc_outlined, size: 50.w),
],
),
);
}
}
Please use latest version.
This issue is stale because it has been open for 30 days with no activity.
version 5.3.0就可以了
``> flutter_screenutil: ^5.2.0
操作步骤:
- 先置为横屏
- 横屏状态下跳转到下一个页面
- 在第二个页面切为竖屏
期待的结果: 布局尺寸不会有问题
实际结果: 布局尺寸被放大了
import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); // This widget is the root of your application. @override Widget build(BuildContext context) { return ScreenUtilInit( designSize: const Size(375, 812), builder: () { ScreenUtil.setContext(context); return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); }, ); } } class MyHomePage extends StatefulWidget { const MyHomePage({Key? key, required this.title}) : super(key: key); final String title; @override State<MyHomePage> createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Container(height: 20.w, color: Colors.red), const Text( 'You have pushed the button this many times:', ), Container(height: 20.w, color: Colors.blue), Text( '0', style: Theme.of(context).textTheme.headline4, ), Container(height: 20.w, color: Colors.yellow), Icon(Icons.abc_outlined, size: 50.w), ], ), ), floatingActionButton: FloatingActionButton( onPressed: () { Navigator.push<void>( context, MaterialPageRoute<void>( builder: (BuildContext context) => const NextPage(), ), ); }, tooltip: 'Increment', child: const Icon(Icons.add), ), ); } } class NextPage extends StatelessWidget { const NextPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('NextPage'), ), body: Column( children: [ Container(height: 20.w, color: Colors.red), const Text('NextPage'), Container(height: 20.w, color: Colors.blue), Text( '0', style: Theme.of(context).textTheme.headline4, ), Container(height: 20.w, color: Colors.yellow), Icon(Icons.abc_outlined, size: 50.w), ], ), ); } }
version 5.3.0就可以了
一样的问题,升级上去也没用,example就可以看。调试看貌似是scaleWidth和scaleHeight计算有问题。 尝试判断是竖屏还是横屏设置designSize依然没用
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
// In first method you only need to wrap [MaterialApp] with [ScreenUtilInit] and that's it
return OrientationBuilder(
builder: (context, orientation) {
return ScreenUtilInit(
designSize: getDesignSize(orientation),
builder: (_, child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'First Method',
// You can use the library anywhere in the app even in theme
theme: ThemeData(
primarySwatch: Colors.blue,
textTheme: Typography.englishLike2018.apply(fontSizeFactor: 1.sp),
),
home: child,
);
},
child: const HomePage(title: 'First Method'),
);
},
);
}
Size getDesignSize(Orientation orientation){
print('init Screen orientation:$orientation');
var bool = orientation == Orientation.portrait;
return bool? Size(360, 780): Size(780, 360);
}
}
flutter_screenutil: ^5.2.0
操作步骤:
- 先置为横屏
- 横屏状态下跳转到下一个页面
- 在第二个页面切为竖屏
期待的结果: 布局尺寸不会有问题
实际结果: 布局尺寸被放大了
import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); // This widget is the root of your application. @override Widget build(BuildContext context) { return ScreenUtilInit( designSize: const Size(375, 812), builder: () { ScreenUtil.setContext(context); return MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.blue, ), home: const MyHomePage(title: 'Flutter Demo Home Page'), ); }, ); } } class MyHomePage extends StatefulWidget { const MyHomePage({Key? key, required this.title}) : super(key: key); final String title; @override State<MyHomePage> createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text(widget.title), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Container(height: 20.w, color: Colors.red), const Text( 'You have pushed the button this many times:', ), Container(height: 20.w, color: Colors.blue), Text( '0', style: Theme.of(context).textTheme.headline4, ), Container(height: 20.w, color: Colors.yellow), Icon(Icons.abc_outlined, size: 50.w), ], ), ), floatingActionButton: FloatingActionButton( onPressed: () { Navigator.push<void>( context, MaterialPageRoute<void>( builder: (BuildContext context) => const NextPage(), ), ); }, tooltip: 'Increment', child: const Icon(Icons.add), ), ); } } class NextPage extends StatelessWidget { const NextPage({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('NextPage'), ), body: Column( children: [ Container(height: 20.w, color: Colors.red), const Text('NextPage'), Container(height: 20.w, color: Colors.blue), Text( '0', style: Theme.of(context).textTheme.headline4, ), Container(height: 20.w, color: Colors.yellow), Icon(Icons.abc_outlined, size: 50.w), ], ), ); } }
高版本也没有解决,这边改了下库里面代码处理好了,亲测有效
@GreenPepperForPotato What version you are using ?
This issue is stale because it has been open for 30 days with no activity.
@GreenPepperForPotato What version you are using ? I'm waiting for the flutter_screenutil team to update the fixed version. Before that, I used the fork library and fixed the problem myself in the library
目前的最新版本, 我跑了一下, 看起来正常的 , 先试一下新版, 如果还有问题 可以弄一个动图来看看吗? @yueyang8389 @GreenPepperForPotato
这个横竖屏切换问题还没弄好吗?
这个横竖屏切换问题还没弄好吗?
切换横竖屏之后,需要自己把握时机 是否 刷新界面状态
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.