Compare commits
No commits in common. "96df3168fcb59dfcf69bd47247314ace35277fc5" and "968633a5b9d8631446181b0f065029d3d49ba808" have entirely different histories.
96df3168fc
...
968633a5b9
@ -1,18 +0,0 @@
|
||||
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,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@ -6,10 +8,12 @@ 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;
|
||||
@ -25,7 +29,8 @@ class MountConfig {
|
||||
}
|
||||
|
||||
void updateStatus(Map<String, dynamic> status) {
|
||||
_path = status["Location"] as String;
|
||||
_state = status["Active"] as bool ? Icons.toggle_on : Icons.toggle_off;
|
||||
_status = status;
|
||||
_state = _status["Active"] as bool ? Icons.toggle_on : Icons.toggle_off;
|
||||
_path = _status["Location"] as String;
|
||||
}
|
||||
}
|
||||
|
@ -1,61 +1,27 @@
|
||||
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 StatefulWidget {
|
||||
class MountWidget extends StatelessWidget {
|
||||
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: isThreeLine,
|
||||
isThreeLine: true,
|
||||
leading: const Icon(Icons.settings),
|
||||
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)),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [Text(mount.name), Text(mount.path)],
|
||||
),
|
||||
title: Text(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