Skip to content

Refactor/issue 33 #41

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

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions lib/ui/component/container_with_loading.dart

This file was deleted.

34 changes: 0 additions & 34 deletions lib/ui/component/dialog.dart

This file was deleted.

16 changes: 11 additions & 5 deletions lib/ui/component/down_icon_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import 'package:flutter/cupertino.dart';
import '../../gen/assets.gen.dart';

class DownIconWidget extends StatelessWidget {
final double _size;
final Color _color;
final double size;
final Color color;

DownIconWidget(this._size, this._color);
DownIconWidget({
required this.size,
required this.color,
});

@override
Widget build(BuildContext context) {
return Assets.svgs.vectorDown
.svg(width: _size, height: _size, color: _color);
return Assets.svgs.vectorDown.svg(
width: size,
height: size,
color: color,
);
}
}
71 changes: 36 additions & 35 deletions lib/ui/component/input_text_dialog.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';

mixin InputTextDialog {
Expand All @@ -10,43 +9,45 @@ mixin InputTextDialog {
/// [dialogTitle] ダイアログのタイトル
/// [hintText] 入力フィールドのヒント
/// [message] L10n
Future<void> displayTextInputDialog(
{required BuildContext context,
required String defaultValue,
required ValueChanged<String> onTapOk,
required String dialogTitle,
required String hintText,
required L10n message}) async {
Future<void> displayTextInputDialog({
required BuildContext context,
required String defaultValue,
required ValueChanged<String> onTapOk,
required String dialogTitle,
required String hintText,
required L10n message,
}) async {
var valueText = "";
return showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: Text(dialogTitle),
content: TextField(
controller: TextEditingController(text: defaultValue),
onChanged: (value) {
valueText = value;
context: context,
builder: (context) {
return AlertDialog(
title: Text(dialogTitle),
content: TextField(
controller: TextEditingController(text: defaultValue),
onChanged: (value) {
valueText = value;
},
decoration: InputDecoration(hintText: hintText),
),
actions: <Widget>[
TextButton(
child: Text(message.cancel),
onPressed: () {
Navigator.pop(context);
},
decoration: InputDecoration(hintText: hintText),
),
actions: <Widget>[
TextButton(
child: Text(message.cancel),
onPressed: () {
Navigator.pop(context);
},
),
TextButton(
child: Text(message.ok),
onPressed: () {
print(valueText);
onTapOk(valueText);
Navigator.pop(context);
},
),
],
);
});
TextButton(
child: Text(message.ok),
onPressed: () {
print(valueText);
onTapOk(valueText);
Navigator.pop(context);
},
),
],
);
},
);
}
}
13 changes: 0 additions & 13 deletions lib/ui/component/loading.dart

This file was deleted.

15 changes: 11 additions & 4 deletions lib/ui/component/up_icon_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ import 'package:flutter/cupertino.dart';
import '../../gen/assets.gen.dart';

class UpIconWidget extends StatelessWidget {
final double _size;
final Color _color;
final double size;
final Color color;

UpIconWidget(this._size, this._color);
UpIconWidget({
required this.size,
required this.color,
});

@override
Widget build(BuildContext context) {
return Assets.svgs.vectorUp.svg(width: _size, height: _size, color: _color);
return Assets.svgs.vectorUp.svg(
width: size,
height: size,
color: color,
);
}
}
10 changes: 5 additions & 5 deletions lib/ui/setting/setting_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class SettingPage extends HookConsumerWidget with InputTextDialog {
final controller = ref.read(settingPageControllerProvider.notifier);
controller.onBuildStart();

var message = L10n.of(context)!;
final message = L10n.of(context)!;

return Scaffold(
appBar: PreferredSize(
Expand Down Expand Up @@ -68,7 +68,7 @@ class _DeviceId extends HookConsumerWidget with InputTextDialog {
Widget build(BuildContext context, WidgetRef ref) {
final message = L10n.of(context)!;
final controller = ref.read(settingPageControllerProvider.notifier);
final deviceId = ref.read(settingPageControllerProvider
final deviceId = ref.watch(settingPageControllerProvider
.select((value) => value.deviceId?.value ?? ""));
return ListTile(
title: Text(
Expand Down Expand Up @@ -100,7 +100,7 @@ class _AccessToken extends HookConsumerWidget with InputTextDialog {
Widget build(BuildContext context, WidgetRef ref) {
final message = L10n.of(context)!;
final controller = ref.read(settingPageControllerProvider.notifier);
final accessToken = ref.read(settingPageControllerProvider
final accessToken = ref.watch(settingPageControllerProvider
.select((value) => value.accessToken?.value ?? ""));
return ListTile(
title: Text(
Expand Down Expand Up @@ -132,7 +132,7 @@ class _ZipCode extends HookConsumerWidget with InputTextDialog {
Widget build(BuildContext context, WidgetRef ref) {
final message = L10n.of(context)!;
final controller = ref.read(settingPageControllerProvider.notifier);
final zipCode = ref.read(settingPageControllerProvider
final zipCode = ref.watch(settingPageControllerProvider
.select((value) => value.zipCode?.value ?? ""));
return ListTile(
title: Text(
Expand Down Expand Up @@ -164,7 +164,7 @@ class _OpenWeatherId extends HookConsumerWidget with InputTextDialog {
Widget build(BuildContext context, WidgetRef ref) {
final message = L10n.of(context)!;
final controller = ref.read(settingPageControllerProvider.notifier);
final appId = ref.read(settingPageControllerProvider
final appId = ref.watch(settingPageControllerProvider
.select((value) => value.appId?.value ?? ""));

return ListTile(
Expand Down
37 changes: 21 additions & 16 deletions lib/ui/setting/setting_page_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,37 @@ import 'setting_page_state.dart';

final settingPageControllerProvider =
StateNotifierProvider<SettingPageController, SettingPageState>(
(ref) => SettingPageController(ref.read(appSettingTopUsecaseProvider)));
(ref) => SettingPageController(
settingTopUseCase: ref.read(appSettingTopUsecaseProvider),
),
);

class SettingPageController extends StateNotifier<SettingPageState> {
SettingPageController(this._settingTopUseCase)
: super(SettingPageState.init());
SettingPageController({
required this.settingTopUseCase,
}) : super(SettingPageState.init());

final AppSettingTopUseCase _settingTopUseCase;
final AppSettingTopUseCase settingTopUseCase;

void onBuildStart() async {
final meterDeviceId = await _settingTopUseCase.loadMeterDeviceId();
final accessToken = await _settingTopUseCase.loadSwitchBotAccessToken();
final weatherAppId = await _settingTopUseCase.loadOpenWeatherAppId();
final zipCode = await _settingTopUseCase.loadZipCode();
final meterDeviceId = await settingTopUseCase.loadMeterDeviceId();
final accessToken = await settingTopUseCase.loadSwitchBotAccessToken();
final weatherAppId = await settingTopUseCase.loadOpenWeatherAppId();
final zipCode = await settingTopUseCase.loadZipCode();

state = state.copyWith.call(
deviceId: meterDeviceId,
accessToken: accessToken,
appId: weatherAppId,
zipCode: zipCode);
deviceId: meterDeviceId,
accessToken: accessToken,
appId: weatherAppId,
zipCode: zipCode,
);
}

Future<void> saveMeterDeviceId(String deviceId) async {
final meterDeviceId = MeterDeviceId(
value: deviceId,
);
await _settingTopUseCase.saveMeterDeviceId(
await settingTopUseCase.saveMeterDeviceId(
deviceId: meterDeviceId,
);
state = state.copyWith.call(
Expand All @@ -47,7 +52,7 @@ class SettingPageController extends StateNotifier<SettingPageState> {
final switchBotAccessToken = SwitchBotAccessToken(
value: accessToken,
);
await _settingTopUseCase.saveSwitchBotAccessToken(
await settingTopUseCase.saveSwitchBotAccessToken(
accessToken: switchBotAccessToken,
);
state = state.copyWith.call(
Expand All @@ -59,7 +64,7 @@ class SettingPageController extends StateNotifier<SettingPageState> {
final weatherAppId = OpenWeatherAppId(
value: appId,
);
await _settingTopUseCase.saveOpenWeatherAppId(
await settingTopUseCase.saveOpenWeatherAppId(
appId: weatherAppId,
);
state = state.copyWith.call(
Expand All @@ -71,7 +76,7 @@ class SettingPageController extends StateNotifier<SettingPageState> {
final zipCodeVO = ZipCode(
value: zipCode,
);
await _settingTopUseCase.saveZipCode(
await settingTopUseCase.saveZipCode(
zipCode: zipCodeVO,
);
state = state.copyWith.call(
Expand Down
11 changes: 6 additions & 5 deletions lib/ui/setting/setting_page_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ part "setting_page_state.freezed.dart";

@freezed
class SettingPageState with _$SettingPageState {
const factory SettingPageState(
{MeterDeviceId? deviceId,
SwitchBotAccessToken? accessToken,
OpenWeatherAppId? appId,
ZipCode? zipCode}) = _SettingPageState;
const factory SettingPageState({
MeterDeviceId? deviceId,
SwitchBotAccessToken? accessToken,
OpenWeatherAppId? appId,
ZipCode? zipCode,
}) = _SettingPageState;

factory SettingPageState.init() => const _SettingPageState();
}
10 changes: 8 additions & 2 deletions lib/ui/station/widget/todays_temperature_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class TodaysTemperatureWidget extends StatelessWidget {

Widget _buildMaxTemperature(L10n message) {
var children = <Widget>[];
children.add(UpIconWidget(20, ColorName.textRed));
children.add(UpIconWidget(
size: 20,
color: ColorName.textRed,
));
var text = Container(
margin: const EdgeInsets.only(left: 8),
child: Text(
Expand All @@ -30,7 +33,10 @@ class TodaysTemperatureWidget extends StatelessWidget {

Widget _buildMinTemperature(L10n message) {
var children = <Widget>[];
children.add(DownIconWidget(20, ColorName.textBlue));
children.add(DownIconWidget(
size: 20,
color: ColorName.textBlue,
));
var text = Container(
margin: const EdgeInsets.only(left: 8),
child: Text(
Expand Down
10 changes: 8 additions & 2 deletions lib/ui/station/widget/weather_item_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ class WeatherItemWidget extends StatelessWidget {

Widget _buildMaxTemperature(L10n message) {
var children = <Widget>[];
children.add(UpIconWidget(10, ColorName.textRed));
children.add(UpIconWidget(
size: 10,
color: ColorName.textRed,
));
var text = Container(
margin: const EdgeInsets.only(left: 4),
child: Text(
Expand All @@ -48,7 +51,10 @@ class WeatherItemWidget extends StatelessWidget {

Widget _buildMinTemperature(L10n message) {
var children = <Widget>[];
children.add(DownIconWidget(10, ColorName.textBlue));
children.add(DownIconWidget(
size: 10,
color: ColorName.textBlue,
));
var text = Container(
margin: const EdgeInsets.only(left: 4),
child: Text(
Expand Down