-
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.
- Loading branch information
1 parent
2f12349
commit 57ee9f6
Showing
7 changed files
with
173 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import 'package:all_in_one/styles/app_style.dart'; | ||
import 'package:auto_size_text/auto_size_text.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class ProcessItem extends StatelessWidget { | ||
const ProcessItem( | ||
{super.key, required this.name, required this.rate, required this.value}); | ||
final String name; | ||
final double rate; | ||
final String value; | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return SizedBox( | ||
height: 60, | ||
child: Row( | ||
children: [ | ||
SizedBox( | ||
width: 100, | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
AutoSizeText( | ||
name, | ||
maxLines: 1, | ||
style: const TextStyle(color: Colors.white), | ||
), | ||
Text( | ||
value, | ||
style: const TextStyle(color: AppStyle.appCheckColor), | ||
) | ||
], | ||
), | ||
), | ||
const SizedBox( | ||
width: 10, | ||
), | ||
Container( | ||
width: 270 * rate, | ||
height: 30, | ||
decoration: BoxDecoration( | ||
gradient: LinearGradient(colors: [ | ||
AppStyle.appCheckColor, | ||
AppStyle.red.withOpacity(rate) | ||
]), | ||
borderRadius: BorderRadius.circular(4), | ||
), | ||
) | ||
], | ||
), | ||
); | ||
} | ||
} |
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,73 @@ | ||
import 'package:all_in_one/system_monitor/components/process_item.dart'; | ||
import 'package:all_in_one/system_monitor/notifiers/process_notifier.dart'; | ||
import 'package:filesize/filesize.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
class Processes extends ConsumerStatefulWidget { | ||
const Processes({super.key}); | ||
|
||
@override | ||
ConsumerState<Processes> createState() => _ProcessesState(); | ||
} | ||
|
||
class _ProcessesState extends ConsumerState<Processes> | ||
with TickerProviderStateMixin { | ||
late final TabController controller; | ||
@override | ||
void initState() { | ||
controller = TabController(length: 2, vsync: this); | ||
super.initState(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final state = ref.watch(processProvider); | ||
|
||
return Column( | ||
children: [ | ||
SizedBox( | ||
height: 50, | ||
child: TabBar(controller: controller, tabs: const [ | ||
Text( | ||
"cpu", | ||
style: TextStyle(color: Colors.white), | ||
), | ||
Text( | ||
"memory", | ||
style: TextStyle(color: Colors.white), | ||
) | ||
]), | ||
), | ||
Expanded( | ||
child: Padding( | ||
padding: const EdgeInsets.all(10), | ||
child: TabBarView(controller: controller, children: [ | ||
ListView.builder( | ||
itemBuilder: (c, i) { | ||
final value = state.cpus[i].cpu / state.cpus.first.cpu; | ||
|
||
return ProcessItem( | ||
name: state.cpus[i].name, | ||
rate: value, | ||
value: "${state.cpus[i].cpu.ceilToDouble()}%"); | ||
}, | ||
itemCount: state.cpus.length, | ||
), | ||
ListView.builder( | ||
itemBuilder: (c, i) { | ||
final value = | ||
state.memories[i].memory / state.memories.first.memory; | ||
return ProcessItem( | ||
name: state.memories[i].name, | ||
rate: value, | ||
value: filesize(state.memories[i].memory)); | ||
}, | ||
itemCount: state.memories.length, | ||
) | ||
]), | ||
)) | ||
], | ||
); | ||
} | ||
} |
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 @@ | ||
import 'package:all_in_one/src/rust/system_monitor.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
import 'process_state.dart'; | ||
|
||
class ProcessNotifier extends AutoDisposeNotifier<ProcessState> { | ||
@override | ||
ProcessState build() { | ||
return ProcessState(); | ||
} | ||
|
||
changeState(List<SoftwareCpu> cpus, List<SoftwareMemory> memories) { | ||
state = ProcessState(cpus: cpus, memories: memories); | ||
} | ||
} | ||
|
||
final processProvider = | ||
AutoDisposeNotifierProvider<ProcessNotifier, ProcessState>( | ||
() => ProcessNotifier(), | ||
); |
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,8 @@ | ||
import 'package:all_in_one/src/rust/system_monitor.dart'; | ||
|
||
class ProcessState { | ||
final List<SoftwareCpu> cpus; | ||
final List<SoftwareMemory> memories; | ||
|
||
ProcessState({this.cpus = const [], this.memories = const []}); | ||
} |
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
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