Skip to content

Commit 18e00a4

Browse files
author
Vivek Chib
committed
commit 2
1 parent 13910fd commit 18e00a4

File tree

12 files changed

+992
-108
lines changed

12 files changed

+992
-108
lines changed

lib/main.dart

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
11
import 'package:flutter/material.dart';
2-
2+
import 'package:flutter_curve_visualizer/screen_mode.dart';
3+
import 'package:flutter_curve_visualizer/utils/theme/theme.dart';
34
import 'views/home_page.dart';
45

5-
void main() {
6+
Future<void> main() async {
7+
WidgetsFlutterBinding.ensureInitialized();
8+
69
runApp(const MyApp());
710
}
811

912
class MyApp extends StatelessWidget {
1013
const MyApp({super.key});
1114

15+
ScreenMode getLayoutType(double width) {
16+
if (width < 500) {
17+
return ScreenMode.mobile;
18+
} else if (width < 850) {
19+
return ScreenMode.tablet;
20+
} else {
21+
return ScreenMode.web;
22+
}
23+
}
24+
1225
@override
1326
Widget build(BuildContext context) {
27+
final theme = MaterialTheme(Theme.of(context).textTheme);
28+
1429
return MaterialApp(
1530
title: 'Flutter Curve Visualizer',
16-
theme: ThemeData(
17-
useMaterial3: true,
31+
themeMode: ThemeMode.dark,
32+
theme: theme.lightMediumContrast(),
33+
darkTheme: theme.dark(),
34+
home: LayoutBuilder(
35+
builder: (context, constraints) {
36+
return ScreenModeWidget(
37+
mode: getLayoutType(constraints.maxWidth),
38+
child: const HomePage(),
39+
);
40+
},
1841
),
19-
home: const HomePage(),
2042
);
2143
}
2244
}

lib/model/graph_config.dart

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@ import 'package:flutter/material.dart';
33
class GraphConfiguration {
44
final int graphDivisions;
55
final int curveDivisions;
6-
final Color graphAxisColor;
7-
final Color graphCurveColor;
6+
final Color axisColor;
7+
final Color curveLineColor;
8+
final Color curveOutlineColor;
89
final Color graphMarkerColor;
9-
final double graphAxisWidth;
10-
final double graphCurveWidth;
11-
final double graphMarkerSize;
10+
final double axisWidth;
11+
final double curveLineWidth;
12+
final double pointerSize;
13+
final bool showCurveOutline;
1214

1315
const GraphConfiguration({
1416
this.graphDivisions = 10,
1517
this.curveDivisions = 1000,
16-
required this.graphAxisColor,
17-
required this.graphCurveColor,
18+
required this.axisColor,
19+
required this.curveLineColor,
1820
required this.graphMarkerColor,
19-
required this.graphAxisWidth,
20-
required this.graphCurveWidth,
21-
required this.graphMarkerSize,
22-
});
21+
required this.axisWidth,
22+
required this.curveLineWidth,
23+
required this.pointerSize,
24+
required this.curveOutlineColor,
25+
this.showCurveOutline = false,
26+
}) : assert(pointerSize > 0, 'pointerSize must be greater than 0'),
27+
assert(axisWidth > 0, 'axisWidth must be greater than 0'),
28+
assert(curveLineWidth > 0, 'curveLineWidth must be greater than 0'),
29+
assert(curveDivisions > 0, 'curveDivisions must be greater than 0'),
30+
assert(graphDivisions >= 0, 'graphDivisions must be not negative');
2331
}

lib/screen_mode.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import 'package:flutter/material.dart';
2+
3+
enum ScreenMode {
4+
mobile,
5+
tablet,
6+
web;
7+
8+
bool get isMobile => this == ScreenMode.mobile;
9+
10+
bool get isTablet => this == ScreenMode.tablet;
11+
12+
bool get isWeb => this == ScreenMode.web;
13+
14+
bool get isMobileOrTablet =>
15+
this == ScreenMode.mobile || this == ScreenMode.tablet;}
16+
17+
class ScreenModeWidget extends InheritedWidget {
18+
final ScreenMode mode;
19+
20+
const ScreenModeWidget({super.key, required super.child, required this.mode});
21+
22+
static ScreenMode of(BuildContext context) {
23+
final responsiveLayout =
24+
context.dependOnInheritedWidgetOfExactType<ScreenModeWidget>();
25+
26+
if (responsiveLayout == null) {
27+
throw FlutterError('ResponsiveLayout not found in widget tree!');
28+
}
29+
return responsiveLayout.mode;
30+
}
31+
32+
@override
33+
bool updateShouldNotify(covariant ScreenModeWidget oldWidget) =>
34+
mode != oldWidget.mode;
35+
}

lib/utils/curves_enum.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ enum CurvesEnum {
4343
bounceInOut(Curves.bounceInOut),
4444
elasticIn(Curves.elasticIn),
4545
elasticOut(Curves.elasticOut),
46-
elasticInOut(Curves.elasticInOut);
46+
elasticInOut(Curves.elasticInOut),
47+
custom(Cubic(0.77, 0.0, 0.175, 1.0));
4748

4849
final Curve curve;
4950

lib/utils/extension/string.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extension StringExtension on String {
2+
String capitalizeFirst() => "${this[0].toUpperCase()}${substring(1)}";
3+
}

0 commit comments

Comments
 (0)