Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

用了 screenutil, 想问一下要怎么用 widget test 确保 widgets 的高度和宽度在任何的屏幕 size 都不会造成 overflow? #115

Closed
alvindrakes opened this issue May 24, 2020 · 1 comment
Labels
good first issue Good for newcomers

Comments

@alvindrakes
Copy link

有木有用 screenutil 写 widget tests 的例子吗?

@joekendal
Copy link

如果有人有同样的问题,并看到此

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class _Wrapper extends StatelessWidget {
  final Widget child;
  _Wrapper(this.child);
  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(context, width: 1125, height: 2436, allowFontScaling: true);
    return child;
  }
}

Widget testableWidget({Widget child}) {
  return MediaQuery(
    data: MediaQueryData(),
    child: CupertinoApp(
      home: Scaffold(body: _Wrapper(child)),
    ),
  );
}

void main() {
  testWidgets('testingMyWidget', (WidgetTester tester) async {
        await tester.pumpWidget(testableWidget(child: MyWidget()));
  });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants