flutter_screenutil icon indicating copy to clipboard operation
flutter_screenutil copied to clipboard

横竖屏切换BUG

Open yixiu1043 opened this issue 2 years ago • 6 comments

flutter_screenutil: ^5.2.0

操作步骤:

  1. 先置为横屏
  2. 横屏状态下跳转到下一个页面
  3. 在第二个页面切为竖屏

期待的结果: 布局尺寸不会有问题

实际结果: 布局尺寸被放大了

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),
        ],
      ),
    );
  }
}

yixiu1043 avatar Jun 28 '22 04:06 yixiu1043

Please use latest version.

Mounir-Bouaiche avatar Jul 08 '22 12:07 Mounir-Bouaiche

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Aug 08 '22 02:08 github-actions[bot]

version 5.3.0就可以了

yjt1216 avatar Aug 10 '22 01:08 yjt1216

``> flutter_screenutil: ^5.2.0

操作步骤:

  1. 先置为横屏
  2. 横屏状态下跳转到下一个页面
  3. 在第二个页面切为竖屏

期待的结果: 布局尺寸不会有问题

实际结果: 布局尺寸被放大了

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);
  }
}

GreenPepperForPotato avatar Aug 22 '22 09:08 GreenPepperForPotato

flutter_screenutil: ^5.2.0

操作步骤:

  1. 先置为横屏
  2. 横屏状态下跳转到下一个页面
  3. 在第二个页面切为竖屏

期待的结果: 布局尺寸不会有问题

实际结果: 布局尺寸被放大了

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),
        ],
      ),
    );
  }
}

高版本也没有解决,这边改了下库里面代码处理好了,亲测有效 image

GreenPepperForPotato avatar Aug 23 '22 02:08 GreenPepperForPotato

@GreenPepperForPotato What version you are using ?

Mounir-Bouaiche avatar Aug 23 '22 10:08 Mounir-Bouaiche

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Oct 07 '22 02:10 github-actions[bot]

@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

GreenPepperForPotato avatar Oct 16 '22 02:10 GreenPepperForPotato

目前的最新版本, 我跑了一下, 看起来正常的 , 先试一下新版, 如果还有问题 可以弄一个动图来看看吗? @yueyang8389 @GreenPepperForPotato

lizhuoyuan avatar Oct 27 '22 10:10 lizhuoyuan

这个横竖屏切换问题还没弄好吗?

longsirhero avatar Nov 18 '22 08:11 longsirhero

这个横竖屏切换问题还没弄好吗?

切换横竖屏之后,需要自己把握时机 是否 刷新界面状态

yjt1216 avatar Dec 06 '22 02:12 yjt1216

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jan 06 '23 02:01 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jan 20 '23 02:01 github-actions[bot]