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:collection/collection.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@ -6,10 +8,12 @@ class MountConfig {
|
|||||||
String _path = "";
|
String _path = "";
|
||||||
Map<String, dynamic> _settings = {};
|
Map<String, dynamic> _settings = {};
|
||||||
IconData _state = Icons.toggle_off;
|
IconData _state = Icons.toggle_off;
|
||||||
|
Map<String, dynamic> _status = {};
|
||||||
final String _type;
|
final String _type;
|
||||||
MountConfig({required name, required type}) : _name = name, _type = type;
|
MountConfig({required name, required type}) : _name = name, _type = type;
|
||||||
|
|
||||||
UnmodifiableMapView get settings => UnmodifiableMapView(_settings);
|
UnmodifiableMapView get settings => UnmodifiableMapView(_settings);
|
||||||
|
UnmodifiableMapView get status => UnmodifiableMapView(_status);
|
||||||
|
|
||||||
String get name => _name;
|
String get name => _name;
|
||||||
String get path => _path;
|
String get path => _path;
|
||||||
@ -25,7 +29,8 @@ class MountConfig {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void updateStatus(Map<String, dynamic> status) {
|
void updateStatus(Map<String, dynamic> status) {
|
||||||
_path = status["Location"] as String;
|
_status = status;
|
||||||
_state = status["Active"] as bool ? Icons.toggle_on : Icons.toggle_off;
|
_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:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:repertory/helpers.dart';
|
|
||||||
import 'package:repertory/models/mount.dart';
|
import 'package:repertory/models/mount.dart';
|
||||||
|
|
||||||
class MountWidget extends StatefulWidget {
|
class MountWidget extends StatelessWidget {
|
||||||
const MountWidget({super.key});
|
const MountWidget({super.key});
|
||||||
|
|
||||||
@override
|
|
||||||
State<MountWidget> createState() => _MountWidgetState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _MountWidgetState extends State<MountWidget> {
|
|
||||||
Timer? _timer;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Card(
|
return Card(
|
||||||
child: Consumer<Mount>(
|
child: Consumer<Mount>(
|
||||||
builder: (context, mount, widget) {
|
builder: (context, mount, widget) {
|
||||||
final isThreeLine = mount.state == Icons.toggle_on;
|
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
isThreeLine: isThreeLine,
|
isThreeLine: true,
|
||||||
leading: const Icon(Icons.settings),
|
leading: const Icon(Icons.settings),
|
||||||
subtitle:
|
subtitle: Column(
|
||||||
isThreeLine
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
? Column(
|
children: [Text(mount.name), Text(mount.path)],
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
),
|
||||||
children: [
|
title: Text(mount.type),
|
||||||
Text(formatMountName(mount.type, mount.name)),
|
|
||||||
Text(mount.path),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
: Text(formatMountName(mount.type, mount.name)),
|
|
||||||
title: Text(initialCaps(mount.type)),
|
|
||||||
trailing: Icon(mount.state),
|
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