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

YaruCarousel: put indicator dots in expanded #100

Merged
merged 2 commits into from
Feb 22, 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
22 changes: 2 additions & 20 deletions example/lib/example_page_items.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
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_picker_page.dart';
import 'package:yaru_widgets_example/pages/extra_option_row_page.dart';
Expand Down Expand Up @@ -118,22 +116,6 @@ final examplePageItems = <YaruPageItem>[
iconData: YaruIcons.color_select),
YaruPageItem(
titleBuilder: (context) => Text('YaruCarousel'),
builder: (_) => YaruPage(children: [
YaruCarousel(
fit: BoxFit.fitHeight,
images: kIsWeb
? [
AssetImage('assets/ubuntuhero.jpg'),
AssetImage('assets/ubuntuhero.jpg'),
AssetImage('assets/ubuntuhero.jpg'),
]
: [
FileImage(File('assets/ubuntuhero.jpg')),
FileImage(File('assets/ubuntuhero.jpg')),
FileImage(File('assets/ubuntuhero.jpg')),
],
height: 400,
)
]),
builder: (_) => CarouselPage(),
iconData: YaruIcons.refresh)
];
56 changes: 56 additions & 0 deletions example/lib/pages/carousel_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:yaru_icons/yaru_icons.dart';
import 'package:yaru_widgets/yaru_widgets.dart';

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

@override
_CarouselPageState createState() => _CarouselPageState();
}

class _CarouselPageState extends State<CarouselPage> {
int length = 3;

@override
Widget build(BuildContext context) {
return YaruPage(children: [
YaruCarousel(
fit: BoxFit.fitHeight,
images: kIsWeb
? [
for (var i = 0; i < length; i++)
AssetImage('assets/ubuntuhero.jpg'),
]
: [
for (var i = 0; i < length; i++)
FileImage(File('assets/ubuntuhero.jpg')),
],
height: 400,
),
YaruRow(
trailingWidget: Text('length: $length'),
actionWidget: Row(
children: [
YaruOptionButton(
onPressed: () => setState(() {
length++;
}),
iconData: YaruIcons.plus),
SizedBox(
width: 10,
),
YaruOptionButton(
onPressed: () => setState(() {
length >= 2 ? length-- : length = length;
}),
iconData: YaruIcons.minus)
],
),
enabled: true)
]);
}
}
8 changes: 8 additions & 0 deletions example/linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
list(APPEND FLUTTER_PLUGIN_LIST
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
)

set(PLUGIN_BUNDLED_LIBRARIES)

foreach(plugin ${FLUTTER_PLUGIN_LIST})
Expand All @@ -13,3 +16,8 @@ foreach(plugin ${FLUTTER_PLUGIN_LIST})
list(APPEND PLUGIN_BUNDLED_LIBRARIES $<TARGET_FILE:${plugin}_plugin>)
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries})
endforeach(plugin)

foreach(ffi_plugin ${FLUTTER_FFI_PLUGIN_LIST})
add_subdirectory(flutter/ephemeral/.plugin_symlinks/${ffi_plugin}/linux plugins/${ffi_plugin})
list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${ffi_plugin}_bundled_libraries})
endforeach(ffi_plugin)
63 changes: 45 additions & 18 deletions lib/src/yaru_carousel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,51 @@ class _YaruCarouselState extends State<YaruCarousel> {
),
)),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: List<Widget>.generate(
widget.images.length,
(index) => Container(
margin: const EdgeInsets.all(5),
width: 12,
height: 12,
decoration: BoxDecoration(
color: _index == index
? Theme.of(context).colorScheme.primary
: Theme.of(context)
.colorScheme
.primary
.withOpacity(0.3),
shape: BoxShape.circle),
)),
)
widget.images.length < 30
? SizedBox(
width: widget.images.length < 5
? widget.width / 3
: widget.images.length < 10
? widget.width / 2
: widget.width,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: List<Widget>.generate(
widget.images.length,
(index) => Expanded(
child: Container(
margin: const EdgeInsets.all(5),
width: 12,
height: 12,
decoration: BoxDecoration(
color: _index == index
? Theme.of(context).colorScheme.primary
: Theme.of(context)
.colorScheme
.primary
.withOpacity(0.3),
shape: BoxShape.circle),
),
),
),
),
)
: SizedBox(
width: widget.width,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
'$_index/${widget.images.length}',
style: Theme.of(context).textTheme.caption,
),
)
],
),
)
],
);
}
Expand Down