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 24, 2025
1 parent 9033728 commit 86b5191
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 165 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
12 changes: 11 additions & 1 deletion 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,8 +31,8 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
_preCacheImages(context);
return ScreenUtilInit(
designSize: const Size(360, 690),
builder: (context, child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
Expand All @@ -50,3 +52,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);
}
17 changes: 14 additions & 3 deletions lib/view/instruments_screen.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:pslab/constants.dart';
import 'package:pslab/view/widgets/applications_list_item.dart';
import 'package:pslab/view/widgets/main_scaffold_widget.dart';
Expand All @@ -15,7 +16,16 @@ class _InstrumentsScreenState extends State<InstrumentsScreen> {
void _onItemTapped(int index) {
switch (index) {
case 0:
Navigator.pushNamed(context, '/oscilloscope');
if (Navigator.canPop(context) &&
ModalRoute.of(context)?.settings.name == '/oscilloscope') {
Navigator.popUntil(context, ModalRoute.withName('/oscilloscope'));
} else {
Navigator.pushNamedAndRemoveUntil(
context,
'/oscilloscope',
(route) => route.isFirst,
);
}
break;
default:
break;
Expand All @@ -35,8 +45,6 @@ class _InstrumentsScreenState extends State<InstrumentsScreen> {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}

Expand All @@ -47,6 +55,9 @@ class _InstrumentsScreenState extends State<InstrumentsScreen> {

@override
Widget build(BuildContext context) {
ScreenUtil.configure(
designSize: const Size(360, 690),
);
return MainScaffold(
index: 0,
title: 'Instruments',
Expand Down
7 changes: 5 additions & 2 deletions lib/view/oscilloscope_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class _OscilloscopeScreenState extends State<OscilloscopeScreen> {

@override
Widget build(BuildContext context) {
ScreenUtil.configure(
designSize: const Size(690, 360),
);
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => OscilloscopeStateProvider()),
Expand All @@ -50,12 +53,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
94 changes: 47 additions & 47 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 @@ -47,33 +47,33 @@ class _ChannelParametersState extends State<ChannelParametersWidget> {
},
),
Padding(
padding: EdgeInsets.only(top: 2.h),
child: const Text(
padding: EdgeInsets.only(top: 1.h),
child: Text(
'CH1',
style: TextStyle(
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontSize: 15,
fontSize: 14.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: 13.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: 14.sp,
),
),
),
],
),
),
Positioned(
left: 2.w,
bottom: 8.h,
left: 4.w,
bottom: 2.h,
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
Expand All @@ -168,38 +168,38 @@ class _ChannelParametersState extends State<ChannelParametersWidget> {
},
),
Padding(
padding: EdgeInsets.only(top: 2.h),
child: const Text(
padding: EdgeInsets.only(top: 1.h),
child: Text(
'CH2',
style: TextStyle(
fontWeight: FontWeight.bold,
fontStyle: FontStyle.normal,
fontSize: 15,
fontSize: 14.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: 13.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: 14.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: 14.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: 14.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: 14.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
5 changes: 3 additions & 2 deletions lib/view/widgets/common_scaffold_widget.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class CommonScaffold extends StatefulWidget {
final String title;
Expand Down Expand Up @@ -52,9 +53,9 @@ class _CommonScaffoldState extends State<CommonScaffold> {
title: Text(
key: widget.scaffoldKey,
widget.title,
style: const TextStyle(
style: TextStyle(
color: Colors.white,
fontSize: 15,
fontSize: 15.sp,
),
),
actions: [
Expand Down
Loading

0 comments on commit 86b5191

Please sign in to comment.