Skip to content

Commit

Permalink
refactor: update flutter and mews_pedantic (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
ookami-kb committed Feb 15, 2024
1 parent 98c2600 commit 0b0e676
Show file tree
Hide file tree
Showing 23 changed files with 35 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v2
- uses: subosito/flutter-action@v1
with:
flutter-version: "3.10.2"
flutter-version: "3.16.8"
- run: echo "$HOME/.pub-cache/bin" >> $GITHUB_PATH
- run: dart pub global activate melos
- run: melos run check_master
Expand Down
4 changes: 4 additions & 0 deletions packages/storybook_flutter/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
include: package:mews_pedantic/analysis_options.yaml

dart_code_metrics:
rules:
avoid-barrel-files: false
10 changes: 5 additions & 5 deletions packages/storybook_flutter/example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import 'package:flutter/material.dart';
import 'package:storybook_flutter/storybook_flutter.dart';
import 'package:storybook_flutter_example/router_aware_stories.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
const MyApp({super.key});

@override
Widget build(BuildContext context) => Storybook(
initialStory: 'Screens/Scaffold',
stories: [
...routerAwareStories,
Story(
name: 'Screens/Scaffold',
description: 'Story with scaffold and different knobs.',
Expand Down Expand Up @@ -75,6 +73,7 @@ class MyApp extends StatelessWidget {
description: 'Show FAB button',
)
? FloatingActionButton(
heroTag: 'FAB',
onPressed: () {},
child: const Icon(Icons.add),
)
Expand Down Expand Up @@ -120,10 +119,10 @@ class MyApp extends StatelessWidget {

class CounterPage extends StatefulWidget {
const CounterPage({
Key? key,
super.key,
required this.title,
this.enabled = true,
}) : super(key: key);
});

final String title;
final bool enabled;
Expand Down Expand Up @@ -168,6 +167,7 @@ class _CounterPageState extends State<CounterPage> {
),
floatingActionButton: widget.enabled
? FloatingActionButton(
heroTag: 'FAB',
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
Expand Down
74 changes: 0 additions & 74 deletions packages/storybook_flutter/example/lib/router_aware_stories.dart

This file was deleted.

This file was deleted.

5 changes: 1 addition & 4 deletions packages/storybook_flutter/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,16 @@ environment:
sdk: ">=3.0.0 <4.0.0"

dependencies:
auto_route: ^5.0.2
flutter:
sdk: flutter
storybook_flutter:
path: ..
universal_html: ^2.0.8

dev_dependencies:
auto_route_generator: ^5.0.2
build_runner: ^2.3.2
flutter_test:
sdk: flutter
mews_pedantic: ^0.11.0
mews_pedantic: ^0.23.0

flutter:
uses-material-design: true
2 changes: 1 addition & 1 deletion packages/storybook_flutter/lib/src/knobs/knob.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Knob<T> {
T get value => knobValue.value;

/// {@macro knob.value}
set value(T newValue) => knobValue.value = newValue;
set value(T value) => knobValue.value = value;

@protected
KnobValue<T> knobValue;
Expand Down
2 changes: 2 additions & 0 deletions packages/storybook_flutter/lib/src/knobs/nullable_knob.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: match-getter-setter-field-names

import 'package:flutter/material.dart';
import 'package:storybook_flutter/src/knobs/knobs.dart';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ class _ContentsState extends State<_Contents> {
childrenPadding:
EdgeInsets.only(left: (depth - 1) * _sectionPadding),
stories: grouped[k]!,
// ignore: avoid-recursive-calls, intentional recursion
children: _buildListChildren(grouped[k]!, depth: depth + 1),
),
),
...sectionStories
...sectionStories,
];
}

Expand Down
7 changes: 3 additions & 4 deletions packages/storybook_flutter/lib/src/plugins/device_frame.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:device_frame/device_frame.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:storybook_flutter/src/plugins/plugin.dart';
Expand Down Expand Up @@ -63,7 +62,7 @@ const DeviceFrameData defaultDeviceFrameData = (
);

class DeviceFrameDataNotifier extends ValueNotifier<DeviceFrameData> {
DeviceFrameDataNotifier(super.value);
DeviceFrameDataNotifier(super._value);
}

Widget _buildWrapper(
Expand Down Expand Up @@ -96,7 +95,7 @@ Widget _buildPanel(BuildContext context, List<DeviceInfo>? deviceInfos) {
),
subtitle: Text(
'${device.screenSize.width.toInt()}×'
'${device.screenSize.height.toInt()} (${describeEnum(device.identifier.platform)})',
'${device.screenSize.height.toInt()} (${device.identifier.platform.name})',
),
trailing: d.device == device ? const Icon(Icons.check) : null,
onTap: () => update(
Expand Down Expand Up @@ -134,7 +133,7 @@ Widget _buildPanel(BuildContext context, List<DeviceInfo>? deviceInfos) {
if (i == 1) {
return ListTile(
title: const Text('Orientation'),
subtitle: Text(describeEnum(d.orientation)),
subtitle: Text(d.orientation.name),
onTap: () {
final orientation = d.orientation == Orientation.portrait
? Orientation.landscape
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook_flutter/lib/src/plugins/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ enum Layout { compact, expanded, auto }
enum EffectiveLayout { compact, expanded }

class LayoutProvider extends ValueNotifier<Layout> {
LayoutProvider(super.value);
LayoutProvider(super._value);
}

class LayoutPlugin extends Plugin {
Expand Down
19 changes: 6 additions & 13 deletions packages/storybook_flutter/lib/src/plugins/theme_mode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ Widget _buildIcon(BuildContext context) {
switch (context.watch<ThemeModeNotifier>().value) {
case ThemeMode.system:
icon = Icons.brightness_auto_outlined;
break;
case ThemeMode.light:
icon = Icons.brightness_5_outlined;
break;
case ThemeMode.dark:
icon = Icons.brightness_3_outlined;
break;
}

return Icon(icon);
Expand All @@ -39,16 +36,12 @@ void _onPressed(BuildContext context, ValueSetter<ThemeMode>? onThemeChanged) {
case ThemeMode.system:
context.read<ThemeModeNotifier>().value = ThemeMode.light;
onThemeChanged?.call(ThemeMode.light);
break;
case ThemeMode.light:
context.read<ThemeModeNotifier>().value = ThemeMode.dark;
onThemeChanged?.call(ThemeMode.dark);

break;
case ThemeMode.dark:
context.read<ThemeModeNotifier>().value = ThemeMode.system;
onThemeChanged?.call(ThemeMode.system);
break;
}
}

Expand All @@ -58,11 +51,11 @@ Widget _buildWrapper(BuildContext _, Widget? child, ThemeMode? initialTheme) =>
child: Builder(
builder: (context) {
final themeMode = context.watch<ThemeModeNotifier>().value;
final brightness = themeMode == ThemeMode.system
? MediaQuery.platformBrightnessOf(context)
: themeMode == ThemeMode.light
? Brightness.light
: Brightness.dark;
final brightness = switch (themeMode) {
ThemeMode.system => MediaQuery.platformBrightnessOf(context),
ThemeMode.light => Brightness.light,
ThemeMode.dark => Brightness.dark,
};

return MediaQuery(
data: MediaQuery.of(context).copyWith(
Expand All @@ -78,5 +71,5 @@ Widget _buildWrapper(BuildContext _, Widget? child, ThemeMode? initialTheme) =>
///
/// `ThemeModePlugin` should be added to plugins for this to work.
class ThemeModeNotifier extends ValueNotifier<ThemeMode> {
ThemeModeNotifier(super.value);
ThemeModeNotifier(super._value);
}
2 changes: 1 addition & 1 deletion packages/storybook_flutter/lib/src/storybook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class _StorybookState extends State<Storybook> {
...widget.plugins
.map((p) => p.wrapperBuilder)
.whereType<TransitionBuilder>()
.map((builder) => SingleChildBuilder(builder: builder))
.map((builder) => SingleChildBuilder(builder: builder)),
],
child: widget.showPanel
? Stack(
Expand Down
6 changes: 3 additions & 3 deletions packages/storybook_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ dependencies:
recase: ^4.0.0

dev_dependencies:
build_runner: ^2.0.3
build_runner: ^2.4.8
flutter_test:
sdk: flutter
golden_toolkit: ^0.9.0
mews_pedantic: ^0.15.0-dev.3
golden_toolkit: ^0.15.0
mews_pedantic: ^0.23.0
mocktail: ^0.2.0

flutter:
Expand Down
2 changes: 1 addition & 1 deletion packages/storybook_flutter/test/golden_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Widget simpleStorybook(String initialStory) => Storybook(
onPressed: () {},
child: Text(context.knobs.text(label: 'Text', initial: 'Push me')),
),
)
),
],
);

Expand Down
Binary file modified packages/storybook_flutter/test/goldens/simple_story_layout.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified packages/storybook_flutter/test/goldens/story_layout.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/storybook_flutter_test/lib/src/font_loader.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: avoid-accessing-collections-by-constant-index

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand Down

0 comments on commit 0b0e676

Please sign in to comment.