Skip to content

Commit

Permalink
feat: added support for dynamic, scalable layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
AsCress committed Jan 23, 2025
1 parent 706ba22 commit 7b72171
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 180 deletions.
4 changes: 2 additions & 2 deletions lib/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ List<String> rangeMenuEntries = [
'CH2',
'CH3',
'MIC',
'CAP'
'RES',
'CAP',
'RES',
'VOL',
];

Expand Down
11 changes: 11 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import 'package:pslab/view/faq_screen.dart';
import 'package:pslab/view/instruments_screen.dart';
import 'package:pslab/view/oscilloscope_screen.dart';

import 'constants.dart';

void main() {
setupLocator();
WidgetsFlutterBinding.ensureInitialized();
Expand All @@ -29,6 +31,7 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
_preCacheImages(context);
return ScreenUtilInit(
designSize: const Size(360, 690),
builder: (context, child) {
Expand All @@ -50,3 +53,11 @@ class MyApp extends StatelessWidget {
);
}
}

void _preCacheImages(BuildContext context) {
for (final path in instrumentIcons) {
precacheImage(AssetImage(path), context);
}
precacheImage(
const AssetImage('assets/icons/ic_nav_header_logo.png'), context);
}
20 changes: 20 additions & 0 deletions lib/providers/oscilloscope_state_provider.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,34 @@
import 'package:flutter/material.dart';

import '../communication/science_lab.dart';

class OscilloscopeStateProvider extends ChangeNotifier {
int _selectedIndex = 0;

int? samples;
double? timeGap;
double? timebase;
double maxTimebase = 102.4;
bool? isCH1Selected = false;
bool? isCH2Selected = false;
bool? isCH3Selected = false;
bool? isMICSelected = false;
bool? isInBuiltMICSelected = false;
bool? isAudioInputSelected = false;
bool? isTriggerSelected;
bool? isTriggered;
bool? isFourierTransformSelected;
bool? isXYPlotSelected;
bool? sineFit;
bool? squareFit;
String? triggerChannel;
String? triggerMode;
String? curveFittingChannel1;
String? curveFittingChannel2;
Map<String, double>? xOffsets;
Map<String, double>? yOffsets;
double? trigger;
ScienceLab? scienceLab;

double yAxisRange = 16;

Expand Down
2 changes: 0 additions & 2 deletions lib/view/instruments_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class _InstrumentsScreenState extends State<InstrumentsScreen> {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/view/oscilloscope_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class _OscilloscopeScreenState extends State<OscilloscopeScreen> {

@override
Widget build(BuildContext context) {
ScreenUtil.init(context, designSize: const Size(690, 360));
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => OscilloscopeStateProvider()),
Expand All @@ -50,12 +51,12 @@ class _OscilloscopeScreenState extends State<OscilloscopeScreen> {
child: Row(
children: [
Container(
width: 310.w,
width: 590.w,
margin: const EdgeInsets.only(right: 5),
child: Column(
children: [
SizedBox(
height: 380.h,
height: 197.h,
child: LineChart(
LineChartData(
backgroundColor: Colors.black,
Expand Down
9 changes: 5 additions & 4 deletions lib/view/widgets/applications_list_item.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class ApplicationsListItem extends StatelessWidget {
final String heading;
Expand Down Expand Up @@ -82,17 +83,17 @@ class ApplicationsListItem extends StatelessWidget {
children: [
Text(
heading,
style: const TextStyle(
fontSize: 22,
style: TextStyle(
fontSize: 22.sp,
fontWeight: FontWeight.bold,
color: Colors.white,
),
textAlign: TextAlign.start,
),
Text(
description,
style: const TextStyle(
fontSize: 16,
style: TextStyle(
fontSize: 16.sp,
color: Colors.white,
),
textAlign: TextAlign.start,
Expand Down
90 changes: 45 additions & 45 deletions lib/view/widgets/channel_parameters_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class _ChannelParametersState extends State<ChannelParametersWidget> {
child: Stack(
children: [
Positioned(
top: 0.h,
left: 2.w,
top: -4.h,
left: 4.w,
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
Expand All @@ -48,32 +48,32 @@ class _ChannelParametersState extends State<ChannelParametersWidget> {
),
Padding(
padding: EdgeInsets.only(top: 2.h),
child: const Text(
child: Text(
'CH1',
style: TextStyle(
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontSize: 15,
fontSize: 15.sp,
),
),
),
Padding(
padding: EdgeInsets.only(top: 1.h, left: 3.w),
child: const Text(
padding: EdgeInsets.only(top: 1.h, left: 8.w),
child: Text(
'Range',
style: TextStyle(
color: Color(0xFF424242),
color: const Color(0xFF424242),
fontWeight: FontWeight.normal,
fontStyle: FontStyle.normal,
fontSize: 14,
fontSize: 14.sp,
),
),
),
Padding(
padding: EdgeInsets.only(top: 1.h, left: 4.w),
padding: EdgeInsets.only(left: 6.w),
child: DropdownMenu<String>(
initialSelection: yAxisRanges[0],
width: 60.w,
width: 130.w,
dropdownMenuEntries: yAxisRanges.map(
(String value) {
return DropdownMenuEntry<String>(
Expand All @@ -85,8 +85,8 @@ class _ChannelParametersState extends State<ChannelParametersWidget> {
inputDecorationTheme: const InputDecorationTheme(
border: InputBorder.none,
),
textStyle: const TextStyle(
fontSize: 14,
textStyle: TextStyle(
fontSize: 14.sp,
),
onSelected: (String? value) {
switch (yAxisRanges.indexOf(value!)) {
Expand Down Expand Up @@ -127,7 +127,7 @@ class _ChannelParametersState extends State<ChannelParametersWidget> {
Padding(
padding: EdgeInsets.only(top: 0.h),
child: DropdownMenu<String>(
width: 50.w,
width: 95.w,
initialSelection: rangeMenuEntries[0],
dropdownMenuEntries: rangeMenuEntries.map(
(String value) {
Expand All @@ -140,17 +140,17 @@ class _ChannelParametersState extends State<ChannelParametersWidget> {
inputDecorationTheme: const InputDecorationTheme(
border: InputBorder.none,
),
textStyle: const TextStyle(
fontSize: 15,
textStyle: TextStyle(
fontSize: 15.sp,
),
),
),
],
),
),
Positioned(
left: 2.w,
bottom: 8.h,
left: 4.w,
bottom: 2.h,
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
Expand All @@ -169,37 +169,37 @@ class _ChannelParametersState extends State<ChannelParametersWidget> {
),
Padding(
padding: EdgeInsets.only(top: 2.h),
child: const Text(
child: Text(
'CH2',
style: TextStyle(
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontSize: 15,
fontSize: 15.sp,
),
),
),
Padding(
padding: EdgeInsets.only(top: 1.h, left: 3.w),
child: const Text(
padding: EdgeInsets.only(top: 1.h, left: 8.w),
child: Text(
'Range',
style: TextStyle(
color: Color(0xFF424242),
color: const Color(0xFF424242),
fontWeight: FontWeight.normal,
fontStyle: FontStyle.normal,
fontSize: 14,
fontSize: 14.sp,
),
),
),
Padding(
padding: EdgeInsets.only(top: 2.h, left: 4.w),
padding: EdgeInsets.only(top: 2.h, left: 6.w),
child: SizedBox(
width: 60.w,
child: const Text(
width: 130.w,
child: Text(
'+/-16V',
style: TextStyle(
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
fontSize: 14,
fontSize: 14.sp,
),
),
),
Expand All @@ -208,12 +208,12 @@ class _ChannelParametersState extends State<ChannelParametersWidget> {
padding: EdgeInsets.only(top: 2.h),
child: SizedBox(
width: 45.w,
child: const Text(
child: Text(
'CH2',
style: TextStyle(
fontStyle: FontStyle.normal,
fontWeight: FontWeight.normal,
fontSize: 15,
fontSize: 15.sp,
),
),
),
Expand All @@ -222,8 +222,8 @@ class _ChannelParametersState extends State<ChannelParametersWidget> {
),
),
Positioned(
top: 16.h,
right: 4.w,
top: 4.h,
right: 8.w,
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
Expand All @@ -241,22 +241,22 @@ class _ChannelParametersState extends State<ChannelParametersWidget> {
},
),
Padding(
padding: EdgeInsets.only(top: 2.h),
child: const Text(
padding: EdgeInsets.only(top: 1.h),
child: Text(
'CH3 (+/- 3.3V)',
style: TextStyle(
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontSize: 15,
fontSize: 15.sp,
),
),
),
],
),
),
Positioned(
bottom: 8.h,
right: 4.w,
bottom: 2.h,
right: 8.w,
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
Expand Down Expand Up @@ -289,10 +289,10 @@ class _ChannelParametersState extends State<ChannelParametersWidget> {
),
Padding(
padding: EdgeInsets.only(top: 2.h),
child: const Text(
child: Text(
'In-Built MIC',
style: TextStyle(
fontSize: 15,
fontSize: 15.sp,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
),
Expand Down Expand Up @@ -324,10 +324,10 @@ class _ChannelParametersState extends State<ChannelParametersWidget> {
),
Padding(
padding: EdgeInsets.only(top: 2.h),
child: const Text(
child: Text(
'PSLab MIC',
style: TextStyle(
fontSize: 15,
fontSize: 15.sp,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
),
Expand All @@ -342,19 +342,19 @@ class _ChannelParametersState extends State<ChannelParametersWidget> {
Positioned(
left: 0.w,
right: 0.w,
top: 2.h,
top: 1.h,
child: Align(
alignment: Alignment.center,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 2.w),
decoration: const BoxDecoration(color: Colors.white),
child: const Text(
'Channel Parameters',
child: Text(
'Channels',
style: TextStyle(
color: Color(0xFFC72C2C),
color: const Color(0xFFC72C2C),
fontStyle: FontStyle.normal,
fontWeight: FontWeight.bold,
fontSize: 13,
fontSize: 13.sp,
),
),
),
Expand Down
Loading

0 comments on commit 7b72171

Please sign in to comment.