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

Add YaruColorDisk #112

Merged
merged 1 commit into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 7 additions & 1 deletion example/lib/example_page_items.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:yaru_icons/yaru_icons.dart';
import 'package:yaru_widgets/yaru_widgets.dart';
import 'package:yaru_widgets_example/pages/carousel_page.dart';
import 'package:yaru_widgets_example/pages/check_box_row_page.dart';
import 'package:yaru_widgets_example/pages/color_disk_page.dart';
import 'package:yaru_widgets_example/pages/color_picker_page.dart';
import 'package:yaru_widgets_example/pages/extra_option_row_page.dart';
import 'package:yaru_widgets_example/pages/section_page.dart';
Expand Down Expand Up @@ -117,5 +118,10 @@ final examplePageItems = <YaruPageItem>[
YaruPageItem(
titleBuilder: (context) => Text('YaruCarousel'),
builder: (_) => CarouselPage(),
iconData: YaruIcons.refresh)
iconData: YaruIcons.refresh),
YaruPageItem(
titleBuilder: (context) => Text('YaruColorDisk'),
builder: (context) => ColorDiskPage(),
iconData: YaruIcons.color_select,
)
];
14 changes: 11 additions & 3 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:yaru/yaru.dart';
import 'package:yaru_icons/yaru_icons.dart';
import 'package:yaru_widgets/yaru_widgets.dart';
import 'package:yaru_widgets_example/example_page_items.dart';
import 'package:yaru_widgets_example/theme.dart';

void main() {
runApp(Home());
runApp(MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => LightTheme(yaruLight)),
ChangeNotifierProvider(create: (_) => DarkTheme(yaruDark)),
],
child: Home(),
));
}

class Home extends StatefulWidget {
Expand Down Expand Up @@ -39,8 +47,8 @@ class _HomeState extends State<Home> {
return MaterialApp(
scrollBehavior: TouchMouseStylusScrollBehavior(),
debugShowCheckedModeBanner: false,
theme: yaruLight,
darkTheme: yaruDark,
theme: context.watch<LightTheme>().value,
darkTheme: context.watch<DarkTheme>().value,
home: YaruMasterDetailPage(
leftPaneWidth: 280,
previousIconData: YaruIcons.go_previous,
Expand Down
105 changes: 105 additions & 0 deletions example/lib/pages/color_disk_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:yaru/yaru.dart';
import 'package:yaru_widgets/yaru_widgets.dart';
import 'package:yaru_widgets_example/theme.dart';

class ColorDiskPage extends StatefulWidget {
const ColorDiskPage({Key? key}) : super(key: key);

@override
State<ColorDiskPage> createState() => _ColorDiskPageState();
}

class _ColorDiskPageState extends State<ColorDiskPage> {
@override
Widget build(BuildContext context) {
final lightTheme = context.read<LightTheme>();
final darkTheme = context.read<DarkTheme>();
return YaruPage(children: [
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
for (var globalTheme in globalThemeList)
YaruColorDisk(
onPressed: () {
lightTheme.value = globalTheme.lightTheme;
darkTheme.value = globalTheme.darkTheme;
},
color: globalTheme.primaryColor,
selected:
Theme.of(context).primaryColor == globalTheme.primaryColor,
),
],
),
)
]);
}
}

final List<GlobalTheme> globalThemeList = [
GlobalTheme(
lightTheme: yaruLight,
darkTheme: yaruDark,
primaryColor: YaruColors.ubuntuOrange,
),
GlobalTheme(
lightTheme: yaruSageLight,
darkTheme: yaruSageDark,
primaryColor: sageMaterialColor,
),
GlobalTheme(
lightTheme: yaruBarkLight,
darkTheme: yaruBarkDark,
primaryColor: barkMaterialColor,
),
GlobalTheme(
lightTheme: yaruOliveLight,
darkTheme: yaruOliveDark,
primaryColor: oliveMaterialColor,
),
GlobalTheme(
lightTheme: yaruViridianLight,
darkTheme: yaruViridianDark,
primaryColor: viridianMaterialColor,
),
GlobalTheme(
lightTheme: yaruPrussianGreenLight,
darkTheme: yaruPrussianGreenDark,
primaryColor: prussianGreenMaterialColor,
),
GlobalTheme(
lightTheme: yaruBlueLight,
darkTheme: yaruBlueDark,
primaryColor: blueMaterialColor,
),
GlobalTheme(
lightTheme: yaruPurpleLight,
darkTheme: yaruPurpleDark,
primaryColor: purpleMaterialColor,
),
GlobalTheme(
lightTheme: yarMagentaLight,
darkTheme: yaruMagentaDark,
primaryColor: magentaMaterialColor,
),
GlobalTheme(
lightTheme: yaruRedLight,
darkTheme: yaruRedDark,
primaryColor: lightRedMaterialColor,
),
];

class GlobalTheme {
final ThemeData lightTheme;
final ThemeData darkTheme;
final MaterialColor primaryColor;

GlobalTheme({
required this.lightTheme,
required this.darkTheme,
required this.primaryColor,
});
}
9 changes: 9 additions & 0 deletions example/lib/theme.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:flutter/material.dart';

class LightTheme extends ValueNotifier<ThemeData> {
LightTheme(ThemeData value) : super(value);
}

class DarkTheme extends ValueNotifier<ThemeData> {
DarkTheme(ThemeData value) : super(value);
}
3 changes: 2 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ environment:
dependencies:
flutter:
sdk: flutter
provider: ^6.0.2
yaru:
git: http://github.com/ubuntu/yaru.dart
yaru_icons: ^0.1.2
yaru_icons: ^0.2.0
yaru_widgets:
path: ../

Expand Down
43 changes: 43 additions & 0 deletions lib/src/yaru_color_disk.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:flutter/material.dart';

class YaruColorDisk extends StatelessWidget {
const YaruColorDisk(
{Key? key,
required this.onPressed,
required this.color,
required this.selected})
: super(key: key);

final VoidCallback onPressed;
final Color color;
final bool selected;

@override
Widget build(BuildContext context) {
return SizedBox(
width: 42,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextButton(
style: TextButton.styleFrom(
padding: const EdgeInsets.all(0),
shape: CircleBorder(
side: BorderSide(
color: selected
? Theme.of(context).primaryColor
: Colors.transparent)),
),
onPressed: onPressed,
child: SizedBox(
height: 20,
width: 20,
child: DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(100), color: color),
),
),
),
),
);
}
}
1 change: 1 addition & 0 deletions lib/yaru_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export 'src/ubuntu_logo.dart';
export 'src/yaru_alert_dialog.dart';
export 'src/yaru_carousel.dart';
export 'src/yaru_checkbox_row.dart';
export 'src/yaru_color_disk.dart';
export 'src/yaru_color_picker_button.dart';
export 'src/yaru_dialog_title.dart';
export 'src/yaru_expansion_panel_list.dart';
Expand Down