メイン
インポート'パッケージ:フラッター/ material.dart'; インポート'screen.dart'; メイン()=> runApp(MaterialApp( ホーム:MyAppを()、 )); クラスのMyAppはStatelessWidget {延び @Overrideの ウィジェットビルド(BuildContextコンテキスト){ SelfScreen画面= SelfScreen(750、1344、コンテキスト)。 (RootWidget返す :ホームページ()、子 画面:画面を、 ); } } クラスRootWidgetはInheritedWidget {延び スーパー:RootWidget({キーキー、@required this.child、this.screen})(キー:キー) 最終SelfScreen画面。 最後のウィジェットの子。 (BuildContextコンテキスト)の静的RootWidget { context.inheritFromWidgetOfExactType(RootWidget)を返します。 } @Override BOOL updateShouldNotify(InheritedWidget oldWidget){ trueを返します。 } } クラスホームページが延びるStatelessWidget { @Overrideの ウィジェットビルド(BuildContextコンテキスト){ VARのS = RootWidget.of(コンテキスト).screen。 足場(戻り アプリケーションバー(タイトル:テキスト( 'ABC')、)、アプリケーションバー 本体:GestureDetector( (DragDownDetails詳細){:onPanDown ;プリント( 'mmmmmmmmmmmmmmmmmmmmmm') ;プリント(詳細) プリント(s.getGlobalPosition(詳細)) ; プリント( '新しいトップ:$ {s.top}')。 プリント(MediaQuery.of(コンテキスト).padding.top)。 印刷( 'mmmmmmmmmmmmmmmmmmmmmmmm'); }、 子供:コンテナ( 幅:double.infinity、高さ:double.infinity、 色:Colors.grey、 子供:カラム( 子供:<ウィジェット> [ コンテナ( 色:Colors.red、 幅:s.setWidth(200)、 高さ:s.setHeight(200)、 ) ]、 )、 )、) 、 ); } }
画面:
インポート'パッケージ:フラッター/ material.dart'; クラスSelfScreen { 静的ダブル_width、_height。 静的ダブル_physicalWidth、_physicalHeight。 静的ダブル_top、_bottom。 静的ダブル_scaleWidth、_scaleHeight。 静的ダブル_textScale。 静的ダブル_pixelRatio。 SelfScreen(ダブルダブルH、W、BuildContextコンテキスト){ _physicalWidth = MediaQuery.of(コンテキスト).size.width。 _physicalHeight = MediaQuery.of(コンテキスト).size.height。 _top = MediaQuery.of(コンテキスト).padding.top。 _bottom = MediaQuery.of(コンテキスト).padding.bottom。 _textScale = MediaQuery.of(コンテキスト).textScaleFactor。 _width = W。 _height = H; _scaleWidth = _physicalWidth / W。 _scaleHeight = _physicalHeight / H。 _pixelRatio = MediaQuery.of(コンテキスト).devicePixelRatio。 } トップ=> _top / _scaleHeightを得ます。 => _bottom / _scaleHeight下取得します。 GET scaleWidth => _scaleWidth。 GET ScaleHeightの値=> _scaleHeight。 幅=> _widthを取得します。 高さ=> _heightを取得します。 GET pixelRatio => _pixelRatio。 GET physicalWidth => _physicalWidth。 GET physicalHeight => _physicalHeight。 setWidth(ダブルW){ Wリターン* _scaleWidth。 } setHeightメソッド(ダブルH){ 戻り時間*の_scaleHeight。 } setFontSize(ダブルF、[ブールallowScale = TRUE]){ allowScaleを返しますか?F * _scaleWidth / _textScale:F / _textScale。 } getGlobalPosition(DragDownDetails詳細){ ダブルのx = details.globalPosition.dx。 二重Y = details.globalPosition.dy。 リターン{ 'DX':X / _scaleWidth、 'DY':Y / _scaleHeight}。 } }