-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: moved detail screen to device widget
- Loading branch information
Suraj Adhikari
committed
Dec 6, 2021
1 parent
91a9a0b
commit 522bdef
Showing
3 changed files
with
209 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:yonomi_device_widgets/providers/trait_based_device_notifier.dart'; | ||
import 'package:yonomi_platform_sdk/yonomi-sdk.dart'; | ||
import 'package:yonomi_platform_sdk/yonomi-sdk.dart' as yoSdk; | ||
|
||
class DetailScreen extends StatelessWidget { | ||
final Request request; | ||
final String deviceId; | ||
|
||
const DetailScreen({Key? key, required this.request, required this.deviceId}) | ||
: super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return ChangeNotifierProvider( | ||
create: (_) => TraitBasedDeviceNotifier(request, deviceId), | ||
child: Consumer<TraitBasedDeviceNotifier>( | ||
builder: (_, traitBasedDeviceNotifier, child) { | ||
if (traitBasedDeviceNotifier.deviceDetail == null) { | ||
return CircularProgressIndicator(); | ||
} else { | ||
return Column( | ||
children: | ||
traitBasedDeviceNotifier.deviceDetail!.traits.map((element) { | ||
return Row( | ||
children: [Text(element.name)], | ||
); | ||
}).toList()); | ||
} | ||
}), | ||
); | ||
} | ||
} | ||
|
||
// class isPowered extends yoSdk.State<bool> { | ||
// isPowered(bool isOn) : super("Power", isOn); | ||
// } | ||
|
||
// class PowerTrait extends Trait { | ||
// PowerTrait(String name, yoSdk.State state) : super(name, state); | ||
// } | ||
|
||
// class TraitWidgetsBuilder { | ||
// static Widget build(Device deviceDetail) { | ||
// List<Trait> dummyTraits = [ | ||
// LockTrait("whenLocked", IsLocked(true)), | ||
// LockTrait("whenUnlocked", IsLocked(false)), | ||
// PowerTrait("PowerTrait", isPowered(true)), | ||
// UnknownTrait(), | ||
// ]; | ||
|
||
// // TODO: L41: use deviceDetail.traits, not dummyTraits; | ||
// return Column( | ||
// children: [ | ||
// buildDeviceTitleRow(deviceDetail.displayName), | ||
// ...buildTraitRows(dummyTraits), | ||
// ], | ||
// ); | ||
// } | ||
|
||
// static Widget buildDeviceTitleRow(String deviceName) { | ||
// return Row( | ||
// children: [Text(deviceName)], | ||
// ); | ||
// } | ||
|
||
// static List<Row> buildTraitRows(List<Trait> traits) { | ||
// List<Row> traitRows = []; | ||
// for (var trait in traits) { | ||
// traitRows.add( | ||
// Row( | ||
// children: [traitFactory(trait)], | ||
// ), | ||
// ); | ||
// } | ||
// return traitRows; | ||
// } | ||
|
||
// static Widget traitFactory(Trait trait) { | ||
// switch (trait.runtimeType) { | ||
// case LockTrait: | ||
// return LockTraitWidget(trait); | ||
// case PowerTrait: | ||
// return PowerTraitWidget(trait); | ||
// default: | ||
// return UnknownTraitWidget(trait); | ||
// } | ||
// } | ||
// } | ||
|
||
// class LockTraitWidget extends StatelessWidget { | ||
// Trait trait; | ||
|
||
// LockTraitWidget(this.trait); | ||
|
||
// @override | ||
// Widget build(BuildContext context) { | ||
// return Text("Lock-based: ${this.trait.name}"); | ||
// } | ||
// } | ||
|
||
// class PowerTraitWidget extends StatelessWidget { | ||
// Trait trait; | ||
|
||
// PowerTraitWidget(this.trait); | ||
|
||
// @override | ||
// Widget build(BuildContext context) { | ||
// return Text("Power Trait: ${this.trait.name}"); | ||
// // return Switch( | ||
// // value: false, | ||
// // onChanged: (bool newValue) { | ||
// // print("Switched ${newValue}"); | ||
// // }, | ||
// // ); | ||
// } | ||
// } | ||
|
||
// class UnknownTraitWidget extends StatelessWidget { | ||
// Trait trait; | ||
|
||
// UnknownTraitWidget(this.trait); | ||
|
||
// @override | ||
// Widget build(BuildContext context) { | ||
// return Text("Unknown Trait: ${this.trait.name}"); | ||
// } | ||
// } |
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,77 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:provider/provider.dart'; | ||
import 'package:yonomi_device_widgets/assets/traits/device_item_icon.dart'; | ||
import 'package:yonomi_device_widgets/components/arc.dart'; | ||
import 'package:yonomi_device_widgets/providers/lock_provider.dart'; | ||
import 'package:yonomi_device_widgets/ui/widget_style_constants.dart'; | ||
|
||
class LockWidget extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
final lockProvider = Provider.of<LockProvider>(context, listen: true); | ||
|
||
return lockProvider.loadingDetail | ||
? Center(child: CircularProgressIndicator()) | ||
: Scaffold( | ||
body: Column( | ||
mainAxisAlignment: MainAxisAlignment.start, | ||
children: [ | ||
Row( | ||
children: <Widget>[ | ||
Text( | ||
lockProvider.deviceDetail.displayName, | ||
style: Theme.of(context).textTheme.headline6, | ||
), | ||
], | ||
), | ||
SizedBox( | ||
height: 80, | ||
), | ||
Center( | ||
child: Arc( | ||
showThumb: false, | ||
centerWidget: SizedBox( | ||
width: 175, | ||
height: 175, | ||
child: GestureDetector( | ||
child: getLockStateIcon(lockProvider), | ||
onTap: () => _lockTap(lockProvider), | ||
)), | ||
color: lockProvider.isLocked | ||
? WidgetStyleConstants.deviceDetailIconColorActive | ||
: WidgetStyleConstants.deviceDetailIconColorInactive, | ||
initialValue: 0.0, | ||
maxValue: 1.0, | ||
onFinalSetPoint: (double value) {}, | ||
), | ||
), | ||
SizedBox( | ||
height: 80, | ||
), | ||
CupertinoSwitch( | ||
onChanged: (bool value) { | ||
_lockTap(lockProvider); | ||
}, | ||
value: lockProvider.isLocked, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
|
||
Widget getLockStateIcon(LockProvider lockProvider) { | ||
return (lockProvider.loadingDetail || lockProvider.loadingAction) | ||
? Center(child: CircularProgressIndicator()) | ||
: (lockProvider.isLocked) | ||
? DeviceItemIcon.buildLockIcon( | ||
175, WidgetStyleConstants.deviceDetailIconColorActive) | ||
: DeviceItemIcon.buildUnlockIcon( | ||
175, WidgetStyleConstants.deviceDetailIconColorInactive); | ||
} | ||
|
||
void _lockTap(LockProvider provider) { | ||
bool setLock = !provider.isLocked; | ||
provider.setLockUnlockAction(provider.deviceDetail.id, setLock); | ||
} | ||
} |