Skip to content

Commit

Permalink
refactor example codes
Browse files Browse the repository at this point in the history
  • Loading branch information
jacky-dtravel committed Jul 6, 2022
1 parent 1246dd4 commit b9cc4b4
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 166 deletions.
51 changes: 0 additions & 51 deletions example/lib/example/card_list_item.dart

This file was deleted.

22 changes: 0 additions & 22 deletions example/lib/example/circle_list_item.dart

This file was deleted.

14 changes: 0 additions & 14 deletions example/lib/example/label_shimmer.dart

This file was deleted.

126 changes: 47 additions & 79 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import 'package:flutter/material.dart';
import 'package:shimmer/shimmer.dart';
import 'package:shimmer_example/example/circle_list_item.dart';

import 'example/card_list_item.dart';
import 'example/label_shimmer.dart';
import 'package:shimmer_example/placeholders.dart';

void main() => runApp(MyApp());

Expand Down Expand Up @@ -36,17 +33,20 @@ class _MyHomePageState extends State<MyHomePage> {
appBar: AppBar(
title: const Text('Shimmer'),
),
body: Column(
children: <Widget>[
ListTile(
title: const Text('Loading List'),
onTap: () => Navigator.of(context).pushNamed('loading'),
),
ListTile(
title: const Text('Slide To Unlock'),
onTap: () => Navigator.of(context).pushNamed('slide'),
)
],
body: Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Column(
children: <Widget>[
ListTile(
title: const Text('Loading List'),
onTap: () => Navigator.of(context).pushNamed('loading'),
),
ListTile(
title: const Text('Slide To Unlock'),
onTap: () => Navigator.of(context).pushNamed('slide'),
)
],
),
),
);
}
Expand All @@ -66,68 +66,37 @@ class _LoadingListPageState extends State<LoadingListPage> {
appBar: AppBar(
title: const Text('Loading List'),
),
body: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
child: Shimmer.fromColors(
baseColor: Colors.grey.shade300,
highlightColor: Colors.grey.shade100,
enabled: _enabled,
child: SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
const LabelShimmer(),
const SizedBox(
height: 10,
),
SizedBox(
child: ListView.builder(
itemBuilder: (BuildContext context, int index) {
return const CircleListItem();
},
itemCount: 6,
scrollDirection: Axis.horizontal,
),
height: 80,
),
const SizedBox(
height: 10,
),
const LabelShimmer(),
const SizedBox(
height: 10,
),
const CardListItem(),
const SizedBox(
height: 10,
),
const LabelShimmer(),
const SizedBox(
height: 10,
),
ConstrainedBox(
constraints:
const BoxConstraints(maxHeight: 400, minHeight: 56.0),
child: ListView.builder(
itemBuilder: (BuildContext context, int index) {
return const CardListItem();
},
shrinkWrap: true,
itemCount: 3,
scrollDirection: Axis.vertical,
),
),
const SizedBox(
height: 10,
),
const LabelShimmer(),
],
),
)),
),
body: Shimmer.fromColors(
baseColor: Colors.grey.shade300,
highlightColor: Colors.grey.shade100,
enabled: _enabled,
child: SingleChildScrollView(
physics: const NeverScrollableScrollPhysics(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.max,
children: [
const BannerPlaceholder(),
const TitlePlaceholder(width: double.infinity),
const SizedBox(height: 16.0),
const ContentPlaceholder(
lineType: ContentLineType.thressLines,
),
const SizedBox(height: 16.0),
const TitlePlaceholder(width: 200.0),
const SizedBox(height: 16.0),
const ContentPlaceholder(
lineType: ContentLineType.twoLines,
),
const SizedBox(height: 16.0),
const TitlePlaceholder(width: 200.0),
const SizedBox(height: 16.0),
const ContentPlaceholder(
lineType: ContentLineType.twoLines,
),
],
),
)),
);
}
}
Expand Down Expand Up @@ -202,7 +171,7 @@ class SlideToUnlockPage extends StatelessWidget {
),
),
Positioned(
bottom: 24.0,
bottom: 32.0,
left: 0.0,
right: 0.0,
child: Center(
Expand All @@ -229,7 +198,6 @@ class SlideToUnlockPage extends StatelessWidget {
),
baseColor: Colors.black12,
highlightColor: Colors.white,
loop: 3,
),
),
))
Expand Down
113 changes: 113 additions & 0 deletions example/lib/placeholders.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import 'package:flutter/material.dart';

class BannerPlaceholder extends StatelessWidget {
const BannerPlaceholder({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Container(
width: double.infinity,
height: 200.0,
margin: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
color: Colors.white,
),
);
}
}

class TitlePlaceholder extends StatelessWidget {
final double width;

const TitlePlaceholder({
Key? key,
required this.width,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: width,
height: 12.0,
color: Colors.white,
),
SizedBox(height: 8.0),
Container(
width: width,
height: 12.0,
color: Colors.white,
),
],
),
);
}
}

enum ContentLineType {
twoLines,
thressLines,
}

class ContentPlaceholder extends StatelessWidget {
final ContentLineType lineType;

const ContentPlaceholder({
Key? key,
required this.lineType,
}) : super(key: key);

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Row(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
width: 96.0,
height: 72.0,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
color: Colors.white,
),
),
const SizedBox(width: 12.0),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: double.infinity,
height: 10.0,
color: Colors.white,
margin: const EdgeInsets.only(bottom: 8.0),
),
if (lineType == ContentLineType.thressLines)
Container(
width: double.infinity,
height: 10.0,
color: Colors.white,
margin: const EdgeInsets.only(bottom: 8.0),
),
Container(
width: 100.0,
height: 10.0,
color: Colors.white,
)
],
),
)
],
),
);
}
}

0 comments on commit b9cc4b4

Please sign in to comment.