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-963: Update avatar #49

Closed
wants to merge 13 commits into from
20 changes: 15 additions & 5 deletions example/lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:zeta_example/pages/components/button_example.dart';
import 'package:zeta_example/pages/components/checkbox_example.dart';
import 'package:zeta_example/pages/components/chip_example.dart';
import 'package:zeta_example/pages/components/date_input_example.dart';
import 'package:zeta_example/pages/components/dialog_example.dart';
import 'package:zeta_example/pages/components/dialpad_example.dart';
import 'package:zeta_example/pages/components/dropdown_example.dart';
import 'package:zeta_example/pages/components/list_item_example.dart';
Expand Down Expand Up @@ -48,9 +49,11 @@ final List<Component> components = [
Component(CheckBoxExample.name, (context) => const CheckBoxExample()),
Component(ChipExample.name, (context) => const ChipExample()),
Component(ListItemExample.name, (context) => const ListItemExample()),
Component(NavigationBarExample.name, (context) => const NavigationBarExample()),
Component(
NavigationBarExample.name, (context) => const NavigationBarExample()),
Component(PaginationExample.name, (context) => const PaginationExample()),
Component(PasswordInputExample.name, (context) => const PasswordInputExample()),
Component(
PasswordInputExample.name, (context) => const PasswordInputExample()),
Component(DropdownExample.name, (context) => const DropdownExample()),
Component(ProgressExample.name, (context) => const ProgressExample()),
Component(SnackBarExample.name, (context) => const SnackBarExample()),
Expand All @@ -60,6 +63,7 @@ final List<Component> components = [
Component(RadioButtonExample.name, (context) => const RadioButtonExample()),
Component(SwitchExample.name, (context) => const SwitchExample()),
Component(DateInputExample.name, (context) => const DateInputExample()),
Component(DialogExample.name, (context) => const DialogExample()),
];

final List<Component> theme = [
Expand Down Expand Up @@ -124,21 +128,27 @@ class _HomeState extends State<Home> {
title: Text('Widgets'),
backgroundColor: Zeta.of(context).colors.warm.shade30,
children: _components
.map((item) => ListTile(title: Text(item.name), onTap: () => context.go('/${item.name}')))
.map((item) => ListTile(
title: Text(item.name),
onTap: () => context.go('/${item.name}')))
.toList(),
),
ExpansionTile(
title: Text('Theme'),
backgroundColor: Zeta.of(context).colors.warm.shade30,
children: _theme
.map((item) => ListTile(title: Text(item.name), onTap: () => context.go('/${item.name}')))
.map((item) => ListTile(
title: Text(item.name),
onTap: () => context.go('/${item.name}')))
.toList(),
),
ExpansionTile(
title: Text('Assets'),
backgroundColor: Zeta.of(context).colors.warm.shade30,
children: _assets
.map((item) => ListTile(title: Text(item.name), onTap: () => context.go('/${item.name}')))
.map((item) => ListTile(
title: Text(item.name),
onTap: () => context.go('/${item.name}')))
.toList(),
),
],
Expand Down
194 changes: 138 additions & 56 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,69 +1,151 @@
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:zeta_example/theme_service.dart';
import 'package:go_router/go_router.dart';
import 'package:zeta_example/pages/components/accordion_example.dart';
import 'package:zeta_example/pages/components/app_bar_example.dart';
import 'package:zeta_example/pages/components/avatar_example.dart';
import 'package:zeta_example/pages/components/badges_example.dart';
import 'package:zeta_example/pages/components/banner_example.dart';
import 'package:zeta_example/pages/components/bottom_sheet_example.dart';
import 'package:zeta_example/pages/components/breadcrumbs_example.dart';
import 'package:zeta_example/pages/components/button_example.dart';
import 'package:zeta_example/pages/components/checkbox_example.dart';
import 'package:zeta_example/pages/components/chip_example.dart';
import 'package:zeta_example/pages/components/date_input_example.dart';
import 'package:zeta_example/pages/components/dialog_example.dart';
import 'package:zeta_example/pages/components/dialpad_example.dart';
import 'package:zeta_example/pages/components/dropdown_example.dart';
import 'package:zeta_example/pages/components/list_item_example.dart';
import 'package:zeta_example/pages/components/navigation_bar_example.dart';
import 'package:zeta_example/pages/components/radio_example.dart';
import 'package:zeta_example/pages/components/stepper_example.dart';
import 'package:zeta_example/pages/components/switch_example.dart';
import 'package:zeta_example/pages/components/snackbar_example.dart';
import 'package:zeta_example/pages/components/tabs_example.dart';
import 'package:zeta_example/pages/theme/color_example.dart';
import 'package:zeta_example/pages/components/password_input_example.dart';
import 'package:zeta_example/pages/components/progress_example.dart';
import 'package:zeta_example/pages/assets/icons_example.dart';
import 'package:zeta_example/pages/theme/radius_example.dart';
import 'package:zeta_example/pages/theme/spacing_example.dart';
import 'package:zeta_example/pages/theme/typography_example.dart';
import 'package:zeta_example/widgets.dart';
import 'package:zeta_flutter/zeta_flutter.dart';
import 'home.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
class Component {
final String name;
final WidgetBuilder pageBuilder;
final List<Component> children;
Component(this.name, this.pageBuilder, [this.children = const []]);
}

final preferences = await SharedPreferences.getInstance();
final themeService = SharedPrefsThemeService(preferences);
final themePreferences = await themeService.loadTheme();
final List<Component> components = [
Component(AccordionExample.name, (context) => const AccordionExample()),
Component(AppBarExample.name, (context) => const AppBarExample()),
Component(AvatarExample.name, (context) => const AvatarExample()),
Component(BannerExample.name, (context) => const BannerExample()),
Component(BadgesExample.name, (context) => const BadgesExample()),
Component(BottomSheetExample.name, (context) => const BottomSheetExample()),
Component(BreadCrumbsExample.name, (context) => const BreadCrumbsExample()),
Component(ButtonExample.name, (context) => const ButtonExample()),
Component(CheckBoxExample.name, (context) => const CheckBoxExample()),
Component(ChipExample.name, (context) => const ChipExample()),
Component(ListItemExample.name, (context) => const ListItemExample()),
Component(NavigationBarExample.name, (context) => const NavigationBarExample()),
Component(PasswordInputExample.name, (context) => const PasswordInputExample()),
Component(DropdownExample.name, (context) => const DropdownExample()),
Component(ProgressExample.name, (context) => const ProgressExample()),
Component(SnackBarExample.name, (context) => const SnackBarExample()),
Component(StepperExample.name, (context) => const StepperExample()),
Component(TabsExample.name, (context) => const TabsExample()),
Component(DialPadExample.name, (context) => const DialPadExample()),
Component(RadioButtonExample.name, (context) => const RadioButtonExample()),
Component(SwitchExample.name, (context) => const SwitchExample()),
Component(DateInputExample.name, (context) => const DateInputExample()),
Component(DialogExample.name, (context) => const DialogExample()),
];

runApp(
ZetaExample(
themeService: themeService,
initialThemeData: themePreferences.$1 ?? ZetaThemeData(),
initialThemeMode: themePreferences.$2 ?? ThemeMode.system,
initialContrast: themePreferences.$3 ?? ZetaContrast.aa,
),
);
}
final List<Component> theme = [
Component(ColorExample.name, (context) => const ColorExample()),
Component(TypographyExample.name, (context) => const TypographyExample()),
Component(RadiusExample.name, (context) => const RadiusExample()),
Component(SpacingExample.name, (context) => const SpacingExample()),
];
final List<Component> assets = [
Component(IconsExample.name, (context) => const IconsExample()),
];

class ZetaExample extends StatelessWidget {
const ZetaExample({
super.key,
required this.themeService,
required this.initialContrast,
required this.initialThemeMode,
required this.initialThemeData,
});
class Home extends StatefulWidget {
const Home({super.key});

@override
State<Home> createState() => _HomeState();
}

final ZetaThemeService themeService;
final ZetaContrast initialContrast;
final ThemeMode initialThemeMode;
final ZetaThemeData initialThemeData;
final GoRouter router = GoRouter(
routes: [
GoRoute(
path: '/',
name: 'Home',
builder: (_, __) => const Home(),
routes: [
...[
...components,
...assets,
...theme,
].map(
(e) => GoRoute(
path: e.name,
name: e.name,
builder: (_, __) => e.pageBuilder.call(_),
routes: e.children
.map((f) => GoRoute(
path: f.name,
name: f.name,
builder: (_, __) => f.pageBuilder(_),
))
.toList(),
),
),
],
),
],
);

class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return ZetaProvider(
themeService: themeService,
initialContrast: initialContrast,
initialThemeData: initialThemeData,
initialThemeMode: initialThemeMode,
builder: (context, themeData, themeMode) {
final dark = themeData.colorsDark.toScheme();
final light = themeData.colorsLight.toScheme();
return MaterialApp.router(
routerConfig: router,
themeMode: themeMode,
theme: ThemeData(
useMaterial3: true,
fontFamily: themeData.fontFamily,
scaffoldBackgroundColor: light.background,
colorScheme: light,
textTheme: zetaTextTheme,
),
darkTheme: ThemeData(
useMaterial3: true,
fontFamily: themeData.fontFamily,
scaffoldBackgroundColor: dark.background,
colorScheme: dark,
textTheme: zetaTextTheme,
),
);
},
final _components = components..sort((a, b) => a.name.compareTo(b.name));
final _assets = assets..sort((a, b) => a.name.compareTo(b.name));
final _theme = theme..sort((a, b) => a.name.compareTo(b.name));
return ExampleScaffold(
name: 'Zeta',
child: SingleChildScrollView(
child: Column(
children: [
ExpansionTile(
title: Text('Widgets'),
backgroundColor: Zeta.of(context).colors.warm.shade30,
children: _components
.map((item) => ListTile(title: Text(item.name), onTap: () => context.go('/${item.name}')))
.toList(),
),
ExpansionTile(
title: Text('Theme'),
backgroundColor: Zeta.of(context).colors.warm.shade30,
children: _theme
.map((item) => ListTile(title: Text(item.name), onTap: () => context.go('/${item.name}')))
.toList(),
),
ExpansionTile(
title: Text('Assets'),
backgroundColor: Zeta.of(context).colors.warm.shade30,
children: _assets
.map((item) => ListTile(title: Text(item.name), onTap: () => context.go('/${item.name}')))
.toList(),
),
],
),
),
);
}
}
Loading
Loading