Skip to content

Commit

Permalink
feat: widgetbook (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-orion authored Feb 7, 2024
1 parent d8cb7c8 commit 16b5b3b
Show file tree
Hide file tree
Showing 13 changed files with 362 additions and 13 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ source "https://rubygems.org"

ruby '3.2.2'

gem 'cocoapods', '~> 1.14.3'
gem "fastlane"

plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
Expand Down
79 changes: 77 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@ GEM
specs:
CFPropertyList (3.0.6)
rexml
activesupport (7.1.3)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
artifactory (3.0.15)
atomos (0.1.3)
aws-eventstream (1.2.0)
Expand All @@ -24,18 +37,64 @@ GEM
aws-sigv4 (1.6.0)
aws-eventstream (~> 1, >= 1.0.2)
babosa (1.0.4)
base64 (0.2.0)
bigdecimal (3.1.6)
claide (1.1.0)
cocoapods (1.14.3)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.14.3)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 2.1, < 3.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.6.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (>= 2.3.0, < 3.0)
gh_inspector (~> 1.0)
molinillo (~> 0.8.0)
nap (~> 1.0)
ruby-macho (>= 2.3.0, < 3.0)
xcodeproj (>= 1.23.0, < 2.0)
cocoapods-core (1.14.3)
activesupport (>= 5.0, < 8)
addressable (~> 2.8)
algoliasearch (~> 1.0)
concurrent-ruby (~> 1.1)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
netrc (~> 0.11)
public_suffix (~> 4.0)
typhoeus (~> 1.0)
cocoapods-deintegrate (1.0.5)
cocoapods-downloader (2.1)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.1)
cocoapods-trunk (1.6.0)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.2.0)
colored (1.2)
colored2 (3.1.2)
commander (4.6.0)
highline (~> 2.0.0)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
declarative (0.0.20)
digest-crc (0.6.5)
rake (>= 12.0.0, < 14.0.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.8.1)
drb (2.2.0)
ruby2_keywords
emoji_regex (3.2.3)
escape (0.0.4)
ethon (0.16.0)
ffi (>= 1.15.0)
excon (0.102.0)
faraday (1.10.3)
faraday-em_http (~> 1.0)
Expand Down Expand Up @@ -107,6 +166,9 @@ GEM
xcpretty-travis-formatter (>= 0.0.3)
fastlane-plugin-firebase_app_distribution (0.7.2)
google-apis-firebaseappdistribution_v1 (~> 0.3.0)
ffi (1.16.3)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
google-apis-androidpublisher_v3 (0.48.0)
google-apis-core (>= 0.11.0, < 2.a)
Expand Down Expand Up @@ -152,20 +214,27 @@ GEM
http-cookie (1.0.5)
domain_name (~> 0.5)
httpclient (2.8.3)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
jmespath (1.6.2)
json (2.6.3)
jwt (2.7.1)
memoist (0.16.2)
mini_magick (4.12.0)
mini_mime (1.1.5)
minitest (5.22.1)
molinillo (0.8.0)
multi_json (1.15.0)
multipart-post (2.3.0)
mutex_m (0.2.0)
nanaimo (0.3.0)
nap (1.1.0)
naturally (2.2.1)
netrc (0.11.0)
optparse (0.1.1)
os (1.1.4)
plist (3.7.0)
public_suffix (5.0.3)
public_suffix (4.0.7)
rake (13.0.6)
representable (3.2.0)
declarative (< 0.1.0)
Expand All @@ -174,6 +243,7 @@ GEM
retriable (3.1.2)
rexml (3.2.6)
rouge (2.0.7)
ruby-macho (2.5.1)
ruby2_keywords (0.0.5)
rubyzip (2.3.2)
security (0.1.3)
Expand All @@ -193,14 +263,18 @@ GEM
tty-screen (0.8.1)
tty-spinner (0.9.3)
tty-cursor (~> 0.7)
typhoeus (1.4.1)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
uber (0.1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.8.2)
unicode-display_width (1.8.0)
webrick (1.8.1)
word_wrap (1.0.0)
xcodeproj (1.22.0)
xcodeproj (1.24.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
Expand All @@ -216,6 +290,7 @@ PLATFORMS
ruby

DEPENDENCIES
cocoapods (~> 1.14.3)
fastlane
fastlane-plugin-firebase_app_distribution

Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 7368163408c647b7eb699d0d788ba6718e18fb8d

COCOAPODS: 1.14.3
COCOAPODS: 1.15.2
37 changes: 37 additions & 0 deletions lib/app/shared/widgets/button/widgetbook.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:flutter/material.dart';
import 'package:ice/app/shared/widgets/button/button.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

@widgetbook.UseCase(
name: 'with green color',
type: Button,
)
Widget greenContainerUseCase(BuildContext context) {
return Center(
child: Button(
type: ButtonType.outlined,
label: Text(
context.knobs.string(
label: 'Title',
initialValue: 'Controllable Title',
),
),
onPressed: () {},
),
);
}

@widgetbook.UseCase(
name: 'with red color',
type: Button,
)
Widget redContainerUseCase(BuildContext context) {
return Center(
child: Button(
type: ButtonType.disabled,
label: const Text('Text'),
onPressed: () {},
),
);
}
8 changes: 2 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ class IceApp extends HookConsumerWidget {
builder: (BuildContext context, Widget? widget) => MaterialApp.router(
localizationsDelegates: I18n.localizationsDelegates,
supportedLocales: I18n.supportedLocales,
theme: template.whenOrNull(
data: (Template data) => buildLightTheme(data),
),
darkTheme: template.whenOrNull(
data: (Template data) => buildDarkTheme(data),
),
theme: template.whenOrNull(data: buildLightTheme),
darkTheme: template.whenOrNull(data: buildDarkTheme),
themeMode: appThemeMode,
routerConfig: appRouter,
),
Expand Down
1 change: 1 addition & 0 deletions lib/widgetbook/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# A playground to streamline shared UI Widgets with Widgetbook
50 changes: 50 additions & 0 deletions lib/widgetbook/main.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:ice/app/features/core/providers/init_provider.dart';
import 'package:ice/app/features/core/providers/template_provider.dart';
import 'package:ice/app/features/core/providers/theme_mode_provider.dart';
import 'package:ice/app/templates/template.dart';
import 'package:ice/app/theme/theme.dart';
import 'package:ice/generated/app_localizations.dart';
import 'package:ice/widgetbook/main.directories.g.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

void main() {
runApp(const ProviderScope(child: WidgetbookApp()));
}

@widgetbook.App()
class WidgetbookApp extends ConsumerWidget {
const WidgetbookApp({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final AsyncValue<void> init = ref.watch(initAppProvider);

return init.when(
data: (void data) => Widgetbook.material(
directories: directories,
appBuilder: (BuildContext context, Widget child) {
final ThemeMode appThemeMode = ref.watch(appThemeModeProvider);
final AsyncValue<Template> template = ref.watch(templateProvider);

return ScreenUtilInit(
designSize: const Size(375, 812),
builder: (BuildContext context, Widget? widget) => MaterialApp(
localizationsDelegates: I18n.localizationsDelegates,
supportedLocales: I18n.supportedLocales,
theme: template.whenOrNull(data: buildLightTheme),
darkTheme: template.whenOrNull(data: buildDarkTheme),
themeMode: appThemeMode,
home: child,
),
);
},
),
error: (Object err, StackTrace stack) => Text(err.toString()),
loading: () => const CircularProgressIndicator(),
);
}
}
22 changes: 22 additions & 0 deletions macos/Podfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
PODS:
- file_selector_macos (0.0.1):
- FlutterMacOS
- FlutterMacOS (1.0.0)

DEPENDENCIES:
- file_selector_macos (from `Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos`)
- FlutterMacOS (from `Flutter/ephemeral`)

EXTERNAL SOURCES:
file_selector_macos:
:path: Flutter/ephemeral/.symlinks/plugins/file_selector_macos/macos
FlutterMacOS:
:path: Flutter/ephemeral

SPEC CHECKSUMS:
file_selector_macos: 468fb6b81fac7c0e88d71317f3eec34c3b008ff9
FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24

PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367

COCOAPODS: 1.14.3
Loading

0 comments on commit 16b5b3b

Please sign in to comment.