Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: integrate Widget Book with a sample button code #3 #5

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/app_scaffold.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter/material.dart';
import 'package:pactus_gui_widgetbook/src/core/theme/app_theme.dart';


esmaeil-ahmadipour marked this conversation as resolved.
Show resolved Hide resolved
class AppScaffold extends StatelessWidget {
const AppScaffold({
super.key,
required this.child,
});

final Widget child;

@override
Widget build(BuildContext context) {
return Container(
color: AppTheme.of(context).scaffoldBackgroundColor,
child: child,
);
}
}
151 changes: 41 additions & 110 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,125 +1,56 @@
import 'package:flutter/material.dart';
import 'package:pactus_gui_widgetbook/app_scaffold.dart';
import 'package:pactus_gui_widgetbook/src/core/theme/app_theme.dart';
import 'package:pactus_gui_widgetbook/src/core/theme/app_theme_data.dart';
import 'package:widgetbook/widgetbook.dart';
import 'package:widgetbook_annotation/widgetbook_annotation.dart' as widgetbook;

void main() {
runApp(const MyApp());
}

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

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}

class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
import 'main.directories.g.dart';

// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.

// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".

final String title;

@override
State<MyHomePage> createState() => _MyHomePageState();
void main() {
runApp(const WidgetBookApp());
}

class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;

void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
@widgetbook.App()
class WidgetBookApp extends StatelessWidget {
const WidgetBookApp({super.key});

@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
return Widgetbook(
appBuilder: (context, child) {
return child;
},
addons: [
DeviceFrameAddon(
devices: [
Devices.ios.iPhone13,
PouriaMoradi021 marked this conversation as resolved.
Show resolved Hide resolved
],
),
AlignmentAddon(),
ThemeAddon(
themes: [
WidgetbookTheme(
name: 'Light',
data: AppThemeData.lightTheme(),
),
WidgetbookTheme(
name: 'Dark',
data: AppThemeData.darkTheme(),
)
],
themeBuilder: (context, data, child) {
return AppTheme(
themeData: data,
child: AppScaffold(child: child),
);
},
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
],
// The [directories] variable does not exist yet,
// it will be generated in the next step
directories: directories,
);
}
}
39 changes: 39 additions & 0 deletions lib/main.directories.g.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_import, prefer_relative_imports, directives_ordering

// GENERATED CODE - DO NOT MODIFY BY HAND

// **************************************************************************
// AppGenerator
// **************************************************************************

// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:pactus_gui_widgetbook/src/features/widgets/custom_button/custom_button_usecase.dart'
as _i2;
import 'package:widgetbook/widgetbook.dart' as _i1;

final directories = <_i1.WidgetbookNode>[
_i1.WidgetbookFolder(
name: 'features',
children: [
_i1.WidgetbookFolder(
name: 'widgets',
children: [
_i1.WidgetbookFolder(
name: 'custom_button',
children: [
_i1.WidgetbookLeafComponent(
name: 'CustomButtonWidget',
useCase: _i1.WidgetbookUseCase(
name: 'Custom Button with Knobs',
builder: _i2.customButtonWidgetUseCase,
),
)
],
)
],
)
],
)
];
4 changes: 4 additions & 0 deletions lib/src/core/enum/button_icon_state_enum.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enum ButtonIconState {
withIcon,
withoutIcon,
}
100 changes: 100 additions & 0 deletions lib/src/core/pallets/on_surface_pallet.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import 'package:fluent_ui/fluent_ui.dart';

@immutable
PouriaMoradi021 marked this conversation as resolved.
Show resolved Hide resolved
class OnSurfacePallet extends ThemeExtension<OnSurfacePallet> {
const OnSurfacePallet({
required this.onSurface4,
required this.onSurface3,
required this.onSurface2,
required this.onSurface1,
required this.onSurface0,
});

final Color? onSurface4;
final Color? onSurface3;
final Color? onSurface2;
final Color? onSurface1;
final Color? onSurface0;

@override
OnSurfacePallet copyWith({
Color? onSurface4,
Color? onSurface3,
Color? onSurface2,
Color? onSurface1,
Color? onSurface0,
}) {
return OnSurfacePallet(
onSurface4: onSurface4 ?? this.onSurface4,
onSurface3: onSurface3 ?? this.onSurface3,
onSurface2: onSurface2 ?? this.onSurface2,
onSurface1: onSurface1 ?? this.onSurface1,
onSurface0: onSurface0 ?? this.onSurface0,
);
}

// Controls how the properties change on theme changes
@override
OnSurfacePallet lerp(ThemeExtension<OnSurfacePallet>? other, double t) {
if (other is! OnSurfacePallet) {
return this;
}
return OnSurfacePallet(
onSurface4: Color.lerp(onSurface4, other.onSurface4, t),
onSurface3: Color.lerp(onSurface3, other.onSurface3, t),
onSurface2: Color.lerp(onSurface2, other.onSurface2, t),
onSurface1: Color.lerp(onSurface1, other.onSurface1, t),
onSurface0: Color.lerp(onSurface0, other.onSurface0, t),
);
}

// Controls how it displays when the instance is being passed
// to the `print()` method.
@override
String toString() => 'OnSurfacePallet('
'onSurface4: $onSurface4, '
'onSurface3: $onSurface3, '
'onSurface2: $onSurface2, '
'onSurface1: $onSurface1, '
'onSurface0: $onSurface0, '
')';

Color? getByIndex(int index) {
switch (index) {
case 4:
return onSurface4;
case 3:
return onSurface3;
case 2:
return onSurface2;
case 1:
return onSurface1;
case 0:
return onSurface0;
default:
throw Exception('Invalid OnSurfacePallet color index');
}
}

// the light theme
static const light = OnSurfacePallet(
onSurface4: Color(0xff222222),
//FIGMA: Black 100
onSurface3: Color(0xff7A7A7A),
//FIGMA: Black 60
onSurface2: Color(0xffBDBDBD),
//FIGMA: Black 30
onSurface1: Color(0xffE9E9E9),
//FIGMA: Black 10
onSurface0: Color(0xffF8F8F8), //FIGMA: Black 03
);

// the dark theme
static const dark = OnSurfacePallet(
onSurface4: Color(0xffF8F8F8),
onSurface3: Color(0xffE9E9E9),
onSurface2: Color(0xffBDBDBD),
onSurface1: Color(0xff7A7A7A),
onSurface0: Color(0xff222222),
);
}
Loading