Compare commits
5 Commits
968633a5b9
...
96df3168fc
Author | SHA1 | Date | |
---|---|---|---|
96df3168fc | |||
45381c3d0c | |||
4c82b87b07 | |||
c29072d84d | |||
311a2688cb |
18
web/repertory/lib/helpers.dart
Normal file
18
web/repertory/lib/helpers.dart
Normal file
@ -0,0 +1,18 @@
|
||||
String formatMountName(String type, String name) {
|
||||
if (type == "remote") {
|
||||
return name.replaceAll("_", ":");
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
String initialCaps(String txt) {
|
||||
if (txt.isEmpty) {
|
||||
return txt;
|
||||
}
|
||||
|
||||
if (txt.length == 1) {
|
||||
return txt[0].toUpperCase();
|
||||
}
|
||||
|
||||
return txt[0].toUpperCase() + txt.substring(1).toLowerCase();
|
||||
}
|
@ -1,5 +1,3 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@ -8,12 +6,10 @@ class MountConfig {
|
||||
String _path = "";
|
||||
Map<String, dynamic> _settings = {};
|
||||
IconData _state = Icons.toggle_off;
|
||||
Map<String, dynamic> _status = {};
|
||||
final String _type;
|
||||
MountConfig({required name, required type}) : _name = name, _type = type;
|
||||
|
||||
UnmodifiableMapView get settings => UnmodifiableMapView(_settings);
|
||||
UnmodifiableMapView get status => UnmodifiableMapView(_status);
|
||||
|
||||
String get name => _name;
|
||||
String get path => _path;
|
||||
@ -29,8 +25,7 @@ class MountConfig {
|
||||
}
|
||||
|
||||
void updateStatus(Map<String, dynamic> status) {
|
||||
_status = status;
|
||||
_state = _status["Active"] as bool ? Icons.toggle_on : Icons.toggle_off;
|
||||
_path = _status["Location"] as String;
|
||||
_path = status["Location"] as String;
|
||||
_state = status["Active"] as bool ? Icons.toggle_on : Icons.toggle_off;
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +1,61 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:repertory/helpers.dart';
|
||||
import 'package:repertory/models/mount.dart';
|
||||
|
||||
class MountWidget extends StatelessWidget {
|
||||
class MountWidget extends StatefulWidget {
|
||||
const MountWidget({super.key});
|
||||
|
||||
@override
|
||||
State<MountWidget> createState() => _MountWidgetState();
|
||||
}
|
||||
|
||||
class _MountWidgetState extends State<MountWidget> {
|
||||
Timer? _timer;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
child: Consumer<Mount>(
|
||||
builder: (context, mount, widget) {
|
||||
final isThreeLine = mount.state == Icons.toggle_on;
|
||||
|
||||
return ListTile(
|
||||
isThreeLine: true,
|
||||
isThreeLine: isThreeLine,
|
||||
leading: const Icon(Icons.settings),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [Text(mount.name), Text(mount.path)],
|
||||
),
|
||||
title: Text(mount.type),
|
||||
subtitle:
|
||||
isThreeLine
|
||||
? Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(formatMountName(mount.type, mount.name)),
|
||||
Text(mount.path),
|
||||
],
|
||||
)
|
||||
: Text(formatMountName(mount.type, mount.name)),
|
||||
title: Text(initialCaps(mount.type)),
|
||||
trailing: Icon(mount.state),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timer?.cancel();
|
||||
_timer = null;
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_timer = Timer.periodic(const Duration(seconds: 5), (_) {
|
||||
var provider = Provider.of<Mount>(context, listen: false);
|
||||
provider.refresh();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user