Skip to content

Commit f1fee34

Browse files
committed
Fixed calculator height issues, better dynamic themes.
1 parent 4edb874 commit f1fee34

File tree

4 files changed

+143
-144
lines changed

4 files changed

+143
-144
lines changed

lib/components/helpers/calculator.dart

Lines changed: 99 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import 'package:csocsort_szamla/helpers/currencies.dart';
2+
import 'package:csocsort_szamla/helpers/providers/screen_width_provider.dart';
23
import 'package:csocsort_szamla/helpers/validation_rules.dart';
34
import 'package:customized_keyboard/customized_keyboard.dart';
45
import 'package:easy_localization/easy_localization.dart';
56
import 'package:flutter/material.dart';
67
import 'package:flutter/services.dart';
8+
import 'package:provider/provider.dart';
79

810
enum Operator { add, subtract, multiply, divide, none }
911

@@ -251,32 +253,108 @@ class CalculatorTextField extends StatelessWidget {
251253
}
252254
}
253255

254-
class Calculator extends StatelessWidget {
255-
Calculator({super.key});
256+
class CalculatorButton extends StatefulWidget {
257+
const CalculatorButton({
258+
required this.keyEvent,
259+
required this.backgroundColor,
260+
required this.textColor,
261+
required this.child,
262+
super.key,
263+
});
264+
265+
final CustomKeyboardEvent keyEvent;
266+
final Color backgroundColor;
267+
final Color textColor;
268+
final Widget child;
269+
270+
@override
271+
State<CalculatorButton> createState() => _CalculatorButtonState();
272+
}
273+
274+
class _CalculatorButtonState extends State<CalculatorButton> with SingleTickerProviderStateMixin {
275+
late AnimationController _controller;
276+
277+
@override
278+
void initState() {
279+
super.initState();
280+
_controller = AnimationController(
281+
vsync: this,
282+
duration: const Duration(milliseconds: 70),
283+
reverseDuration: const Duration(milliseconds: 300),
284+
)..addListener(() => setState(() {}));
285+
}
286+
287+
@override
288+
void dispose() {
289+
_controller.dispose();
290+
super.dispose();
291+
}
256292

257293
@override
258294
Widget build(BuildContext context) {
259-
return Container(
260-
constraints: const BoxConstraints(
261-
maxHeight: 380,
262-
),
263-
padding: const EdgeInsets.only(
264-
left: 10,
265-
right: 10,
266-
top: 15,
267-
),
295+
return Ink(
268296
decoration: BoxDecoration(
269-
color: Theme.of(context).colorScheme.surfaceContainer,
270-
borderRadius: BorderRadius.circular(20),
297+
color: widget.backgroundColor,
298+
borderRadius: BorderRadius.circular(20 + (1 - _controller.value) * 50),
271299
),
272-
child: Material(
273-
type: MaterialType.transparency,
274-
child: Table(
275-
children: [0, 1, 2, 3].map((index) {
276-
return TableRow(
277-
children: _generateRow(context, index),
278-
);
279-
}).toList(),
300+
child: AspectRatio(
301+
aspectRatio: 1,
302+
child: InkWell(
303+
onTapDown: (details) => _controller.forward(from: 0),
304+
onTapUp: (details) => _controller.reverse(from: 1),
305+
onTapCancel: () => _controller.reverse(from: 1),
306+
overlayColor: WidgetStateProperty.all(Colors.transparent),
307+
onTap: () {
308+
HapticFeedback.lightImpact();
309+
final keyboardWrapper = KeyboardWrapper.of(context);
310+
if (keyboardWrapper == null) {
311+
throw KeyboardWrapperNotFound();
312+
}
313+
keyboardWrapper.onKey(widget.keyEvent);
314+
},
315+
child: Center(child: widget.child),
316+
),
317+
),
318+
);
319+
}
320+
}
321+
322+
class CalculatorKeyboard extends CustomKeyboard {
323+
@override
324+
Widget build(BuildContext context) {
325+
return TextFieldTapRegion(
326+
child: Container(
327+
decoration: BoxDecoration(
328+
color: Theme.of(context).colorScheme.surfaceContainerHigh,
329+
borderRadius: BorderRadius.circular(20),
330+
),
331+
child: Material(
332+
type: MaterialType.transparency,
333+
child: OverflowBox(
334+
minWidth: 0,
335+
minHeight: 0,
336+
maxWidth: context.read<ScreenSize>().width,
337+
maxHeight: 380,
338+
child: Center(
339+
child: Container(
340+
constraints: const BoxConstraints(
341+
maxHeight: 380,
342+
maxWidth: (370 / 4 * 5),
343+
),
344+
padding: const EdgeInsets.only(
345+
left: 10,
346+
right: 10,
347+
),
348+
child: Table(
349+
children: [0, 1, 2, 3].map((index) {
350+
return TableRow(
351+
children: _generateRow(context, index),
352+
);
353+
}).toList(),
354+
),
355+
),
356+
),
357+
),
280358
),
281359
),
282360
);
@@ -334,82 +412,6 @@ class Calculator extends StatelessWidget {
334412
);
335413
}).toList();
336414
}
337-
}
338-
339-
class CalculatorButton extends StatefulWidget {
340-
const CalculatorButton({
341-
required this.keyEvent,
342-
required this.backgroundColor,
343-
required this.textColor,
344-
required this.child,
345-
super.key,
346-
});
347-
348-
final CustomKeyboardEvent keyEvent;
349-
final Color backgroundColor;
350-
final Color textColor;
351-
final Widget child;
352-
353-
@override
354-
State<CalculatorButton> createState() => _CalculatorButtonState();
355-
}
356-
357-
class _CalculatorButtonState extends State<CalculatorButton> with SingleTickerProviderStateMixin {
358-
late AnimationController _controller;
359-
360-
@override
361-
void initState() {
362-
super.initState();
363-
_controller = AnimationController(
364-
vsync: this,
365-
duration: const Duration(milliseconds: 70),
366-
reverseDuration: const Duration(milliseconds: 300),
367-
)..addListener(() => setState(() {}));
368-
}
369-
370-
@override
371-
void dispose() {
372-
_controller.dispose();
373-
super.dispose();
374-
}
375-
376-
@override
377-
Widget build(BuildContext context) {
378-
return AspectRatio(
379-
aspectRatio: 1,
380-
child: Ink(
381-
decoration: BoxDecoration(
382-
color: widget.backgroundColor,
383-
borderRadius: BorderRadius.circular(20 + (1 - _controller.value) * 50),
384-
),
385-
child: AspectRatio(
386-
aspectRatio: 1,
387-
child: InkWell(
388-
onTapDown: (details) => _controller.forward(from: 0),
389-
onTapUp: (details) => _controller.reverse(from: 1),
390-
onTapCancel: () => _controller.reverse(from: 1),
391-
overlayColor: WidgetStateProperty.all(Colors.transparent),
392-
onTap: () {
393-
HapticFeedback.lightImpact();
394-
final keyboardWrapper = KeyboardWrapper.of(context);
395-
if (keyboardWrapper == null) {
396-
throw KeyboardWrapperNotFound();
397-
}
398-
keyboardWrapper.onKey(widget.keyEvent);
399-
},
400-
child: Center(child: widget.child),
401-
),
402-
),
403-
),
404-
);
405-
}
406-
}
407-
408-
class CalculatorKeyboard extends CustomKeyboard {
409-
@override
410-
Widget build(BuildContext context) {
411-
return TextFieldTapRegion(child: Calculator());
412-
}
413415

414416
@override
415417
double get height => 380;

lib/helpers/app_theme.dart

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
import 'package:dynamic_color/dynamic_color.dart';
12
import 'package:flutter/foundation.dart';
23
import 'package:flutter/material.dart';
4+
import 'package:material_color_utilities/material_color_utilities.dart';
35

46
enum ThemeType {
57
simpleColor(false),
@@ -419,10 +421,11 @@ class AppTheme {
419421
onErrorContainer: Color(0xff410002),
420422
surface: Color(0xfff6fff6),
421423
onSurface: Color(0xff151d18),
422-
surfaceContainer: Color(0xffeef0e7),
423-
surfaceContainerLow: Color(0xfff1f5ec),
424-
surfaceContainerHigh: Color(0xffd4e3d9),
425-
surfaceContainerHighest: Color(0xffebeae1),
424+
surfaceContainer: Color(0xFFF4F1F0),
425+
surfaceContainerLow: Color(0xfff6f3f1),
426+
surfaceContainerLowest: Color(0xffffffff),
427+
surfaceContainerHigh: Color(0xFFEEECEA),
428+
surfaceContainerHighest: Color(0xffe5e2e0),
426429
onSurfaceVariant: Color(0xff3c4a41),
427430
outline: Color(0xff6a7a6f),
428431
outlineVariant: Color(0xffbacbbe),
@@ -451,12 +454,14 @@ class AppTheme {
451454
onError: Color(0xff690005),
452455
errorContainer: Color(0xff93000a),
453456
onErrorContainer: Color(0xffffb4ab),
454-
surface: Color(0xff151d18),
455-
onSurface: Color(0xffdce5dc),
456-
surfaceContainerHighest: Color(0xff3c4a41),
457-
surfaceContainerLow: Color(0xff20241f),
458-
surfaceContainer: Color(0xff272823),
459-
onSurfaceVariant: Color(0xffbacbbe),
457+
surface: Color(0xff131313),
458+
onSurface: Color(0xffe5e2e0),
459+
surfaceContainerHighest: Color(0xff353534),
460+
surfaceContainerLow: Color(0xff1b1c1b),
461+
surfaceContainerLowest: Color(0xff0e0e0e),
462+
surfaceContainerHigh: Color(0xff2a2a29),
463+
surfaceContainer: Color(0xff1f201f),
464+
onSurfaceVariant: Color(0xffdac1bd),
460465
outline: Color(0xff859589),
461466
outlineVariant: Color(0xff3c4a41),
462467
inverseSurface: Color(0xffdce5dc),
@@ -509,49 +514,41 @@ class AppTheme {
509514
AppTheme.themes.remove(ThemeName.darkDynamic);
510515
}
511516

512-
static void addDynamicThemes(ColorScheme lightScheme, ColorScheme darkScheme) {
517+
static void addDynamicThemes(CorePalette palette) async {
518+
ColorScheme lightScheme = palette.toColorScheme();
519+
ColorScheme darkScheme = palette.toColorScheme(brightness: Brightness.dark);
520+
if (AppTheme.themes.containsKey(ThemeName.lightDynamic) && AppTheme.themes[ThemeName.lightDynamic]!.colorScheme.primary == lightScheme.primary) {
521+
print('Dynamic themes already added');
522+
return;
523+
}
513524
try {
514-
ColorScheme otherlightScheme = ColorScheme.fromSeed(seedColor: lightScheme.primary, brightness: Brightness.light);
515-
ColorScheme otherDarkScheme = ColorScheme.fromSeed(seedColor: darkScheme.primary, brightness: Brightness.dark);
516-
517-
lightScheme = lightScheme.copyWith(
518-
surface: otherlightScheme.surface,
519-
onSurface: otherlightScheme.onSurface,
520-
surfaceBright: otherlightScheme.surfaceBright,
521-
surfaceDim: otherlightScheme.surfaceDim,
522-
surfaceContainer: otherlightScheme.surfaceContainer,
523-
surfaceContainerHigh: otherlightScheme.surfaceContainerHigh,
524-
surfaceContainerLow: otherlightScheme.surfaceContainerLow,
525-
surfaceContainerHighest: otherlightScheme.surfaceContainerHighest,
526-
surfaceContainerLowest: otherlightScheme.surfaceContainerLowest,
527-
);
528-
529-
darkScheme = darkScheme.copyWith(
530-
surface: otherDarkScheme.surface,
531-
onSurface: otherDarkScheme.onSurface,
532-
surfaceBright: otherDarkScheme.surfaceBright,
533-
surfaceDim: otherDarkScheme.surfaceDim,
534-
surfaceContainer: otherDarkScheme.surfaceContainer,
535-
surfaceContainerHigh: otherDarkScheme.surfaceContainerHigh,
536-
surfaceContainerLow: otherDarkScheme.surfaceContainerLow,
537-
surfaceContainerHighest: otherDarkScheme.surfaceContainerHighest,
538-
surfaceContainerLowest: otherDarkScheme.surfaceContainerLowest,
539-
);
540-
541525
lightScheme = lightScheme.copyWith(
542-
surfaceContainerLow: ElevationOverlay.applySurfaceTint(lightScheme.surface, lightScheme.primary, 3),
526+
surface: Color(palette.neutral.get(98)),
527+
surfaceBright: Color(palette.neutral.get(98)),
528+
surfaceDim: Color(palette.neutral.get(87)),
529+
surfaceContainerLowest: Color(palette.neutral.get(100)),
530+
surfaceContainerLow: Color(palette.neutral.get(96)),
531+
surfaceContainer: Color(palette.neutral.get(94)),
532+
surfaceContainerHigh: Color(palette.neutral.get(92)),
533+
surfaceContainerHighest: Color(palette.neutral.get(90)),
543534
);
544535

545536
darkScheme = darkScheme.copyWith(
546-
surfaceContainerLow: ElevationOverlay.applySurfaceTint(darkScheme.surface, darkScheme.primary, 3),
537+
surface: Color(palette.neutral.get(6)),
538+
surfaceBright: Color(palette.neutral.get(24)),
539+
surfaceDim: Color(palette.neutral.get(6)),
540+
surfaceContainerLowest: Color(palette.neutral.get(4)),
541+
surfaceContainerLow: Color(palette.neutral.get(10)),
542+
surfaceContainer: Color(palette.neutral.get(12)),
543+
surfaceContainerHigh: Color(palette.neutral.get(17)),
544+
surfaceContainerHighest: Color(palette.neutral.get(22)),
547545
);
548546

549547
AppTheme.themes[ThemeName.lightDynamic] = ThemeData.from(
550548
colorScheme: lightScheme,
551549
useMaterial3: true,
552550
).copyWith(
553551
cardTheme: CardTheme(
554-
color: lightScheme.surfaceContainerLow,
555552
shape: RoundedRectangleBorder(
556553
borderRadius: BorderRadius.circular(15),
557554
),
@@ -573,7 +570,6 @@ class AppTheme {
573570
useMaterial3: true,
574571
).copyWith(
575572
cardTheme: CardTheme(
576-
color: darkScheme.surfaceContainerLow,
577573
shape: RoundedRectangleBorder(
578574
borderRadius: BorderRadius.circular(15),
579575
),

lib/helpers/providers/app_theme_provider.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ class AppThemeProvider extends StatelessWidget {
3232
Widget build(BuildContext context) {
3333
return ChangeNotifierProvider.value(
3434
value: _appTheme,
35-
builder: (context, _) => DynamicColorBuilder(
36-
builder: (ColorScheme? lightDynamic, ColorScheme? darkDynamic) {
37-
if (lightDynamic != null && !AppTheme.themes.containsKey(ThemeName.lightDynamic)) {
38-
AppTheme.addDynamicThemes(lightDynamic, darkDynamic!);
35+
builder: (context, _) => FutureBuilder(
36+
future: DynamicColorPlugin.getCorePalette(),
37+
builder: (context, snapshot) {
38+
if (snapshot.hasData) {
39+
AppTheme.addDynamicThemes(snapshot.data!);
3940
}
4041
return builder(context);
4142
},

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ description: Csocsort
1212
# Read more about iOS versioning at
1313
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
1414

15-
version: 4.4.0+5126 # 5 is the number of an appbundle, the digits after is the version number
15+
version: 4.4.1+5127 # 5 is the number of an appbundle, the digits after is the version number
1616

1717
environment:
1818
sdk: '>=3.0.0'

0 commit comments

Comments
 (0)