trm11tkr / flutter-training-yumemi

Apache License 2.0
1 stars 0 forks source link

Session1 #2

Closed github-actions[bot] closed 1 year ago

github-actions[bot] commented 1 year ago

天気予報アプリの画面レイアウトを構成する

課題

以下の条件の画面レイアウトを作ってみましょう。

ヒント

Flutter には iOS の NSLayoutConstraint や Android の ConstraintLayout のようなものはありません。

以下の Widget を利用するとさまざまな画面に対応することができます。

trm11tkr commented 1 year ago
weather_view.dart ```dart import 'package:flutter/material.dart'; class WeatherView extends StatelessWidget { const WeatherView({super.key}); @override Widget build(BuildContext context) { final deviceWidth = MediaQuery.of(context).size.width; return Scaffold( body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ SizedBox( width: deviceWidth / 2, child: Column( children: [ const AspectRatio( aspectRatio: 1, child: Placeholder(), ), Padding( padding: const EdgeInsets.symmetric(vertical: 16), child: Row( children: [ Expanded( child: Text( '** ℃', textAlign: TextAlign.center, style: Theme.of(context) .textTheme .labelLarge ?.copyWith( color: Colors.blue, ), ), ), Expanded( child: Text( '** ℃', textAlign: TextAlign.center, style: Theme.of(context) .textTheme .labelLarge ?.copyWith( color: Colors.red, ), ), ), ], ), ), ], ), ), const SizedBox( height: 80, ), SizedBox( width: deviceWidth / 2, child: Row( children: [ Expanded( child: TextButton( onPressed: () {}, child: const Text('Close'), ), ), Expanded( child: TextButton( onPressed: () {}, child: const Text('Reload'), ), ), ], ), ), ], ), ), ); } } ```dart