Skip to content

Commit

Permalink
+ speedtest page
Browse files Browse the repository at this point in the history
+ syncfusion_flutter_gauges package
  • Loading branch information
Fabio-web committed Jan 27, 2022
1 parent 809dbc0 commit 05c7399
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 70 deletions.
4 changes: 3 additions & 1 deletion lib/app/modules/global/view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import 'package:speed_test_app/app/modules/global/controller.dart';
import 'package:speed_test_app/app/modules/global/widgets/bottom_nav_bar.dart';
import 'package:speed_test_app/app/modules/home/view.dart';
import 'package:speed_test_app/app/modules/settings/view.dart';
import 'package:speed_test_app/app/modules/speedtest/binding.dart';
import 'package:speed_test_app/app/modules/speedtest/view.dart';

class GlobalPage extends GetView<GlobalController> {

Expand All @@ -24,7 +26,7 @@ class GlobalPage extends GetView<GlobalController> {
],
)),
floatingActionButton: FloatingActionButton(
onPressed: () {},
onPressed: () => Get.to(SpeedtestPage(), binding: SpeedtestBinding(),transition: Transition.downToUp),
backgroundColor: primary,
elevation: 0,
enableFeedback: true,
Expand Down
50 changes: 1 addition & 49 deletions lib/app/modules/home/controller.dart
Original file line number Diff line number Diff line change
@@ -1,60 +1,12 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:internet_speed_test/callbacks_enum.dart';
import 'package:internet_speed_test/internet_speed_test.dart';
import 'package:speed_test_app/app/data/models/speedtest.dart';
import 'package:speed_test_app/app/data/services/storage/repository.dart';

class HomeController extends GetxController {

SpeedtestRepository speedtestRepository;

final tabIndex = 1.obs;
final tab = <String>["Daily", "Weekly", "Monthly"].obs;

final speedtests = <Speedtest>[].obs;
final internetSpeedTest = InternetSpeedTest();

final percentDownload = 0.0.obs;
final transferRateDownload = 0.0.obs;
final Rx<SpeedUnit> unitDownload = SpeedUnit.Mbps.obs;

final percentUpload = 0.0.obs;
final transferRateUpload = 0.0.obs;
final Rx<SpeedUnit> unitUpload = SpeedUnit.Mbps.obs;

HomeController({required this.speedtestRepository});

@override
void onInit() {
super.onInit();
speedtests.assignAll(speedtestRepository.readSpeedtest());
ever(speedtests, (_) => speedtestRepository.writeSpeedtest(speedtests));
}

void changePercentDownload(double value) {
percentDownload.value = value;
}

void changeTransferRateDownload(double value) {
transferRateDownload.value = value;
}

void changeUnitDownload(SpeedUnit unit) {
unitDownload.value = unit;
}

void changePercentUpload(double value) {
percentUpload.value = value;
}

void changeTransferRateUpload(double value) {
transferRateUpload.value = value;
}

void changeUnitUpload(SpeedUnit unit) {
unitUpload.value = unit;
}
HomeController();

void changeTabIndex(int index) {
tabIndex.value = index;
Expand Down
11 changes: 11 additions & 0 deletions lib/app/modules/speedtest/binding.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import 'package:get/get.dart';
import 'package:speed_test_app/app/modules/speedtest/controller.dart';

class SpeedtestBinding implements Bindings {

@override
void dependencies() {
Get.lazyPut<SpeedtestController>(() => SpeedtestController());
}

}
20 changes: 20 additions & 0 deletions lib/app/modules/speedtest/controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:get/get.dart';

class SpeedtestController extends GetxController {

final isStarted = false.obs;

final transferRate = 0.0.obs;

SpeedtestController();

void changeTransferRate(double value) {
transferRate.value = value;
}

void launchTest() {
isStarted.value = true;
changeTransferRate(73.5);
}

}
119 changes: 119 additions & 0 deletions lib/app/modules/speedtest/view.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:speed_test_app/app/core/values/colors.dart';
import 'package:speed_test_app/app/core/values/sizes.dart';
import 'package:speed_test_app/app/modules/home/widgets/text_info.dart';
import 'package:speed_test_app/app/modules/home/widgets/top_app_bar.dart';
import 'package:speed_test_app/app/modules/settings/controller.dart';
import 'package:speed_test_app/app/modules/speedtest/controller.dart';
import 'package:speed_test_app/app/core/utils/extension.dart';
import 'package:speed_test_app/app/modules/speedtest/widgets/build_gauge.dart';
import 'package:speed_test_app/app/modules/speedtest/widgets/network_info.dart';
import 'package:speed_test_app/app/widgets/button_builder.dart';

class SpeedtestPage extends GetView<SpeedtestController> {

final settingsController = Get.find<SettingsController>();

SpeedtestPage({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
body: SingleChildScrollView(
child: SafeArea(
child: Column(
children: [
TopAppBar(
title: "Speedtest",
divider: false,
icon: GestureDetector(
onTap: () => Get.back(),
child: const Icon(Icons.close),
)
),
Padding(
padding: container,
child: Container(
padding: EdgeInsets.all(5.0.wp),
decoration: BoxDecoration(
color: secondary,
borderRadius: BorderRadius.circular(6)
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
//language
NetworkInfo(
icon: const Icon(Icons.router_outlined, color: Colors.white, size: 35),
color: accent,
label: "Server",
value: settingsController.getNameServer()
),
NetworkInfo(
icon: const Icon(Icons.router_outlined, color: Colors.white, size: 35),
label: "Location",
value: settingsController.getLocationCity()
)
],
),
),
),
SizedBox(height: 5.0.wp),
BuildGauge(),
SizedBox(height: 5.0.wp),
Obx(() => Padding(
padding: container,
child: controller.isStarted.value ?
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Wrap(
spacing: 3.0.wp,
children: [
const Icon(Icons.south_outlined),
TextInfo(label: "Download", text: "${controller.transferRate.value} Mbps"),
],
),
Wrap(
spacing: 3.0.wp,
children: [
const Icon(Icons.north_outlined),
TextInfo(label: "Upload", text: "${controller.transferRate.value-7.6} Mbps")
],
)
],
)
: ButtonBuilder("Start Test",
onPressed: () => controller.launchTest(),
width: 35.0.wp,
paddingVertical: 2.0.wp,
backgroundColor: Colors.white,
color: primary,
border: const BorderSide(color: primary, width: 2),
),
)),
SizedBox(height: 10.0.wp),
Padding(
padding: container,
child: Column(
children: [
Text("Speedtest Global", style: TextStyle(fontSize: 14.0.sp, fontWeight: FontWeight.bold)),
SizedBox(height: 2.0.wp),
Text("Fint out how your country's internet ranks on\n the Speedtest Global",
style: TextStyle(fontSize: 10.0.sp, color: Colors.grey), textAlign: TextAlign.center),
SizedBox(height: 5.0.wp),
ButtonBuilder("See Ranking")
],
),
),
SizedBox(height: 10.0.wp),
],
),
),
),
);
}


}
65 changes: 65 additions & 0 deletions lib/app/modules/speedtest/widgets/build_gauge.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:speed_test_app/app/core/values/colors.dart';
import 'package:speed_test_app/app/modules/speedtest/controller.dart';
import 'package:syncfusion_flutter_gauges/gauges.dart';

class BuildGauge extends StatelessWidget {

final speedtestController = Get.find<SpeedtestController>();

BuildGauge({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Obx(() => SfRadialGauge(
key: UniqueKey(),
axes: [
RadialAxis(
showLabels: false,
showTicks: false,
axisLineStyle: AxisLineStyle(
thickness: 40,
color: Colors.grey[300]
),
),
RadialAxis(
pointers: [
NeedlePointer(
value: speedtestController.transferRate.value,
knobStyle: const KnobStyle(
knobRadius: 0.041
),
needleEndWidth: 7,
needleLength: 0.4,
enableAnimation: true,
),
const NeedlePointer(
knobStyle: KnobStyle(
color: Colors.white,
knobRadius: 0.015
),
needleLength: 0,
),
RangePointer(
value: speedtestController.transferRate.value,
color: primary,
width: 50,
enableAnimation: true,
)
],
showTicks: false,
axisLabelStyle: const GaugeTextStyle(
color: Colors.grey,
fontSize: 14,
),
labelOffset: 25,
axisLineStyle: const AxisLineStyle(
thickness: 50,
color: Colors.transparent
),
),
],
));
}
}
46 changes: 46 additions & 0 deletions lib/app/modules/speedtest/widgets/network_info.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
import 'package:speed_test_app/app/core/values/colors.dart';
import 'package:speed_test_app/app/core/utils/extension.dart';

class NetworkInfo extends StatelessWidget {

final Icon icon;
final Color color;
final String label;
final String value;

const NetworkInfo({Key? key,
required this.icon,
this.color = primary,
required this.label,
required this.value
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Wrap(
spacing: 4.0.wp,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Container(
padding: EdgeInsets.all(2.0.wp),
decoration: BoxDecoration(color: color, borderRadius: BorderRadius.circular(50)),
child: icon,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(label, style: TextStyle(color: Colors.grey, fontSize: 10.0.sp)),
SizedBox(height: 1.0.wp),
ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 90),
child: Text(value, maxLines: 1, softWrap: false,
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12.0.sp, overflow: TextOverflow.fade)),
),
],
)
],
);
}
}
Loading

0 comments on commit 05c7399

Please sign in to comment.