-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 调整 IOT 和博客页面显示 * 提交日期时使用 UTC 时间 * 仅在手机客户端上注册 Shortcut * 物品属性新增添加时间 * 更新物品管理主页展示 * 添加登录提示 * 获取一年内要过期的物品 * 添加位置指示 close #15
- Loading branch information
Showing
62 changed files
with
2,305 additions
and
1,222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export './authentication/authentication_bloc.dart'; | ||
export './storage/search_bloc.dart'; | ||
export './storage/storage_bloc.dart'; | ||
export './snack_bar/snack_bar_bloc.dart'; | ||
export './tab/tab_bloc.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:bloc/bloc.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:smart_home/models/models.dart'; | ||
|
||
part 'snack_bar_event.dart'; | ||
part 'snack_bar_state.dart'; | ||
|
||
class SnackBarBloc extends Bloc<SnackBarEvent, SnackBarState> { | ||
@override | ||
SnackBarState get initialState => SnackBarInitial(); | ||
|
||
@override | ||
Stream<SnackBarState> mapEventToState( | ||
SnackBarEvent event, | ||
) async* { | ||
if (event is SnackBarChanged) { | ||
yield SnackBarSuccess( | ||
position: event.position, | ||
message: event.message, | ||
type: event.type, | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
part of 'snack_bar_bloc.dart'; | ||
|
||
@immutable | ||
abstract class SnackBarEvent {} | ||
|
||
class SnackBarChanged extends SnackBarEvent { | ||
final SnackBarPosition position; | ||
final String message; | ||
final MessageType type; | ||
|
||
SnackBarChanged({ | ||
@required this.position, | ||
@required this.message, | ||
@required this.type, | ||
}); | ||
|
||
@override | ||
String toString() => | ||
'SnackBarChanged { message: $message }'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
part of 'snack_bar_bloc.dart'; | ||
|
||
@immutable | ||
abstract class SnackBarState {} | ||
|
||
class SnackBarInitial extends SnackBarState {} | ||
|
||
class SnackBarSuccess extends SnackBarState { | ||
final SnackBarPosition position; | ||
final String message; | ||
final MessageType type; | ||
|
||
SnackBarSuccess({ | ||
@required this.position, | ||
@required this.message, | ||
@required this.type, | ||
}); | ||
|
||
@override | ||
String toString() => | ||
'SnackBarSuccess { position: $position, messageType: $type }'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import 'package:bloc/bloc.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:smart_home/blocs/blocs.dart'; | ||
import 'package:smart_home/models/models.dart'; | ||
import 'package:smart_home/repositories/storage_repository.dart'; | ||
|
||
part 'item_detail_event.dart'; | ||
part 'item_detail_state.dart'; | ||
|
||
class ItemDetailBloc extends Bloc<ItemDetailEvent, ItemDetailState> { | ||
final SnackBarBloc snackBarBloc; | ||
|
||
ItemDetailBloc({@required this.snackBarBloc}); | ||
|
||
@override | ||
ItemDetailState get initialState => ItemDetailInProgress(); | ||
|
||
@override | ||
Stream<ItemDetailState> mapEventToState( | ||
ItemDetailEvent event, | ||
) async* { | ||
if (event is ItemDetailChanged) { | ||
yield ItemDetailInProgress(); | ||
try { | ||
Item results = await storageRepository.item(id: event.itemId); | ||
yield ItemDetailSuccess(item: results); | ||
} catch (e) { | ||
yield ItemDetailError(message: e.message); | ||
} | ||
} | ||
if (event is ItemDetailRefreshed) { | ||
yield ItemDetailInProgress(); | ||
try { | ||
Item results = await storageRepository.item( | ||
id: event.itemId, | ||
cache: false, | ||
); | ||
yield ItemDetailSuccess(item: results); | ||
} catch (e) { | ||
yield ItemDetailError(message: e.message); | ||
} | ||
} | ||
|
||
if (event is ItemEditStarted) { | ||
yield ItemDetailInProgress(); | ||
try { | ||
Item results = await storageRepository.item(id: event.itemId); | ||
yield ItemEditInitial(item: results); | ||
} catch (e) { | ||
yield ItemDetailError(message: e.message); | ||
} | ||
} | ||
if (event is ItemAddStarted) { | ||
yield ItemDetailInProgress(); | ||
try { | ||
yield ItemAddInitial(storageId: event.storageId); | ||
} catch (e) { | ||
yield ItemDetailError(message: e.message); | ||
} | ||
} | ||
|
||
if (event is ItemUpdated) { | ||
try { | ||
Item item = await storageRepository.updateItem( | ||
id: event.id, | ||
name: event.name, | ||
number: event.number, | ||
storageId: event.storageId, | ||
description: event.description, | ||
price: event.price, | ||
expirationDate: event.expirationDate, | ||
); | ||
yield ItemDetailSuccess(item: item); | ||
snackBarBloc.add( | ||
SnackBarChanged( | ||
position: SnackBarPosition.item, | ||
message: '修改成功', | ||
type: MessageType.info, | ||
), | ||
); | ||
await storageRepository.storage(id: event.storageId, cache: false); | ||
await storageRepository.storage(id: event.oldStorageId, cache: false); | ||
} catch (e) { | ||
snackBarBloc.add( | ||
SnackBarChanged( | ||
position: SnackBarPosition.item, | ||
message: e.message, | ||
type: MessageType.error, | ||
), | ||
); | ||
} | ||
} | ||
|
||
if (event is ItemAdded) { | ||
try { | ||
Item item = await storageRepository.addItem( | ||
name: event.name, | ||
number: event.number, | ||
storageId: event.storageId, | ||
description: event.description, | ||
price: event.price, | ||
expirationDate: event.expirationDate, | ||
); | ||
yield ItemAddSuccess(item: item); | ||
snackBarBloc.add( | ||
SnackBarChanged( | ||
position: SnackBarPosition.storage, | ||
message: '${item.name} 添加成功', | ||
type: MessageType.info, | ||
), | ||
); | ||
} catch (e) { | ||
snackBarBloc.add( | ||
SnackBarChanged( | ||
position: SnackBarPosition.item, | ||
message: e.message, | ||
type: MessageType.error, | ||
), | ||
); | ||
} | ||
} | ||
|
||
if (event is ItemDeleted) { | ||
try { | ||
await storageRepository.deleteItem(id: event.item.id); | ||
yield ItemDeleteSuccess(item: event.item); | ||
snackBarBloc.add( | ||
SnackBarChanged( | ||
position: SnackBarPosition.storage, | ||
message: '${event.item.name} 删除成功', | ||
type: MessageType.info, | ||
), | ||
); | ||
} catch (e) { | ||
snackBarBloc.add( | ||
SnackBarChanged( | ||
position: SnackBarPosition.item, | ||
message: e.message, | ||
type: MessageType.error, | ||
), | ||
); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
part of 'item_detail_bloc.dart'; | ||
|
||
abstract class ItemDetailEvent extends Equatable { | ||
const ItemDetailEvent(); | ||
|
||
@override | ||
List<Object> get props => []; | ||
} | ||
|
||
class ItemDetailChanged extends ItemDetailEvent { | ||
final String itemId; | ||
|
||
const ItemDetailChanged({@required this.itemId}); | ||
|
||
@override | ||
List<Object> get props => [itemId]; | ||
|
||
@override | ||
String toString() => 'ItemChanged { itemId: $itemId }'; | ||
} | ||
|
||
class ItemDetailRefreshed extends ItemDetailEvent { | ||
final String itemId; | ||
|
||
const ItemDetailRefreshed({@required this.itemId}); | ||
|
||
@override | ||
List<Object> get props => [itemId]; | ||
|
||
@override | ||
String toString() => 'ItemRefreshed { itemId: $itemId }'; | ||
} | ||
|
||
class ItemEditStarted extends ItemDetailEvent { | ||
final String itemId; | ||
|
||
const ItemEditStarted({@required this.itemId}); | ||
|
||
@override | ||
List<Object> get props => [itemId]; | ||
|
||
@override | ||
String toString() => 'ItemEditStarted { itemId: $itemId }'; | ||
} | ||
|
||
class ItemAddStarted extends ItemDetailEvent { | ||
final String storageId; | ||
|
||
const ItemAddStarted({@required this.storageId}); | ||
|
||
@override | ||
List<Object> get props => [storageId]; | ||
|
||
@override | ||
String toString() => 'ItemAddStarted { storageId: $storageId }'; | ||
} | ||
|
||
class ItemUpdated extends ItemDetailEvent { | ||
final String id; | ||
final String name; | ||
final int number; | ||
final String storageId; | ||
final String oldStorageId; | ||
final String description; | ||
final double price; | ||
final DateTime expirationDate; | ||
|
||
const ItemUpdated({ | ||
@required this.id, | ||
this.name, | ||
this.number, | ||
this.storageId, | ||
this.oldStorageId, | ||
this.description, | ||
this.price, | ||
this.expirationDate, | ||
}); | ||
|
||
@override | ||
List<Object> get props => [ | ||
id, | ||
name, | ||
number, | ||
storageId, | ||
oldStorageId, | ||
description, | ||
price, | ||
expirationDate | ||
]; | ||
|
||
@override | ||
String toString() => 'ItemUpdated { name: $name }'; | ||
} | ||
|
||
class ItemAdded extends ItemDetailEvent { | ||
final String name; | ||
final int number; | ||
final String storageId; | ||
final String description; | ||
final double price; | ||
final DateTime expirationDate; | ||
|
||
const ItemAdded({ | ||
@required this.name, | ||
@required this.number, | ||
@required this.storageId, | ||
this.description, | ||
this.price, | ||
this.expirationDate, | ||
}); | ||
|
||
@override | ||
List<Object> get props => | ||
[name, number, storageId, description, price, expirationDate]; | ||
|
||
@override | ||
String toString() => 'ItemAdded { name: $name }'; | ||
} | ||
|
||
class ItemDeleted extends ItemDetailEvent { | ||
final Item item; | ||
|
||
const ItemDeleted({@required this.item}); | ||
|
||
@override | ||
List<Object> get props => [item]; | ||
|
||
@override | ||
String toString() => 'DeleteItem { name: ${item.name} }'; | ||
} |
Oops, something went wrong.