refactor(example): make the example simpler
This commit is contained in:
parent
b371c2ba82
commit
f6950c2c9a
|
|
@ -1,16 +0,0 @@
|
||||||
# example
|
|
||||||
|
|
||||||
A new Flutter project.
|
|
||||||
|
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
This project is a starting point for a Flutter application.
|
|
||||||
|
|
||||||
A few resources to get you started if this is your first Flutter project:
|
|
||||||
|
|
||||||
- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
|
|
||||||
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)
|
|
||||||
|
|
||||||
For help getting started with Flutter development, view the
|
|
||||||
[online documentation](https://docs.flutter.dev/), which offers tutorials,
|
|
||||||
samples, guidance on mobile development, and a full API reference.
|
|
||||||
|
|
@ -1,80 +0,0 @@
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_card_swiper/flutter_card_swiper.dart';
|
|
||||||
|
|
||||||
class ExampleButton extends StatelessWidget {
|
|
||||||
final Function onTap;
|
|
||||||
final Widget child;
|
|
||||||
|
|
||||||
const ExampleButton({
|
|
||||||
required this.onTap,
|
|
||||||
required this.child,
|
|
||||||
Key? key,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () => onTap(),
|
|
||||||
child: child,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//swipe card to the right side
|
|
||||||
Widget swipeRightButton(CardSwiperController controller) {
|
|
||||||
return ExampleButton(
|
|
||||||
onTap: () => controller.swipeRight(),
|
|
||||||
child: Container(
|
|
||||||
height: 60,
|
|
||||||
width: 60,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: CupertinoColors.activeGreen,
|
|
||||||
borderRadius: BorderRadius.circular(50),
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: CupertinoColors.activeGreen.withOpacity(0.9),
|
|
||||||
spreadRadius: -10,
|
|
||||||
blurRadius: 20,
|
|
||||||
offset: const Offset(0, 20), // changes position of shadow
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
alignment: Alignment.center,
|
|
||||||
child: const Icon(
|
|
||||||
Icons.check,
|
|
||||||
color: CupertinoColors.white,
|
|
||||||
size: 40,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//swipe card to the left side
|
|
||||||
Widget swipeLeftButton(CardSwiperController controller) {
|
|
||||||
return ExampleButton(
|
|
||||||
onTap: () => controller.swipeLeft(),
|
|
||||||
child: Container(
|
|
||||||
height: 60,
|
|
||||||
width: 60,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFFFF3868),
|
|
||||||
borderRadius: BorderRadius.circular(50),
|
|
||||||
boxShadow: [
|
|
||||||
BoxShadow(
|
|
||||||
color: const Color(0xFFFF3868).withOpacity(0.9),
|
|
||||||
spreadRadius: -10,
|
|
||||||
blurRadius: 20,
|
|
||||||
offset: const Offset(0, 20), // changes position of shadow
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
alignment: Alignment.center,
|
|
||||||
child: const Icon(
|
|
||||||
Icons.close,
|
|
||||||
color: CupertinoColors.white,
|
|
||||||
size: 40,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,75 +1,42 @@
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
|
|
||||||
class ExampleCandidateModel {
|
class ExampleCandidateModel {
|
||||||
String? name;
|
String name;
|
||||||
String? job;
|
String job;
|
||||||
String? city;
|
String city;
|
||||||
LinearGradient? color;
|
List<Color> color;
|
||||||
|
|
||||||
ExampleCandidateModel({
|
ExampleCandidateModel({
|
||||||
this.name,
|
required this.name,
|
||||||
this.job,
|
required this.job,
|
||||||
this.city,
|
required this.city,
|
||||||
this.color,
|
required this.color,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
List<ExampleCandidateModel> candidates = [
|
List<ExampleCandidateModel> candidates = [
|
||||||
ExampleCandidateModel(
|
ExampleCandidateModel(
|
||||||
name: 'Two, 2',
|
name: 'One, 1',
|
||||||
job: 'Manager',
|
job: 'Developer',
|
||||||
city: 'Town',
|
city: 'Areado',
|
||||||
color: gradientPurple,
|
color: [Color(0xFFFF3868), Color(0xFFFFB49A)],
|
||||||
),
|
),
|
||||||
ExampleCandidateModel(
|
ExampleCandidateModel(
|
||||||
name: 'One, 1',
|
name: 'Two, 2',
|
||||||
job: 'Manager',
|
job: 'Manager',
|
||||||
city: 'Town',
|
city: 'New York',
|
||||||
color: gradientRed,
|
color: [Color(0xFF736EFE), Color(0xFF62E4EC)],
|
||||||
|
),
|
||||||
|
ExampleCandidateModel(
|
||||||
|
name: 'Three, 3',
|
||||||
|
job: 'Engineer',
|
||||||
|
city: 'London',
|
||||||
|
color: [Color(0xFF2F80ED), Color(0xFF56CCF2)],
|
||||||
|
),
|
||||||
|
ExampleCandidateModel(
|
||||||
|
name: 'Four, 4',
|
||||||
|
job: 'Designer',
|
||||||
|
city: 'Tokyo',
|
||||||
|
color: [Color(0xFF0BA4E0), Color(0xFFA9E4BD)],
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
const LinearGradient gradientRed = LinearGradient(
|
|
||||||
begin: Alignment.topCenter,
|
|
||||||
end: Alignment.bottomCenter,
|
|
||||||
colors: [
|
|
||||||
Color(0xFFFF3868),
|
|
||||||
Color(0xFFFFB49A),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
const LinearGradient gradientPurple = LinearGradient(
|
|
||||||
begin: Alignment.topCenter,
|
|
||||||
end: Alignment.bottomCenter,
|
|
||||||
colors: [
|
|
||||||
Color(0xFF736EFE),
|
|
||||||
Color(0xFF62E4EC),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
const LinearGradient gradientBlue = LinearGradient(
|
|
||||||
begin: Alignment.topCenter,
|
|
||||||
end: Alignment.bottomCenter,
|
|
||||||
colors: [
|
|
||||||
Color(0xFF0BA4E0),
|
|
||||||
Color(0xFFA9E4BD),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
const LinearGradient gradientPink = LinearGradient(
|
|
||||||
begin: Alignment.topCenter,
|
|
||||||
end: Alignment.bottomCenter,
|
|
||||||
colors: [
|
|
||||||
Color(0xFFFF6864),
|
|
||||||
Color(0xFFFFB92F),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
||||||
const LinearGradient kNewFeedCardColorsIdentityGradient = LinearGradient(
|
|
||||||
begin: Alignment.topCenter,
|
|
||||||
end: Alignment.bottomCenter,
|
|
||||||
colors: [
|
|
||||||
Color(0xFF7960F1),
|
|
||||||
Color(0xFFE1A5C9),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'example_candidate_model.dart';
|
import 'example_candidate_model.dart';
|
||||||
|
|
@ -6,20 +5,21 @@ import 'example_candidate_model.dart';
|
||||||
class ExampleCard extends StatelessWidget {
|
class ExampleCard extends StatelessWidget {
|
||||||
final ExampleCandidateModel candidate;
|
final ExampleCandidateModel candidate;
|
||||||
|
|
||||||
const ExampleCard({
|
const ExampleCard(
|
||||||
|
this.candidate, {
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.candidate,
|
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
|
clipBehavior: Clip.hardEdge,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
color: CupertinoColors.white,
|
color: Colors.white,
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: CupertinoColors.systemGrey.withOpacity(0.2),
|
color: Colors.grey.withOpacity(0.2),
|
||||||
spreadRadius: 3,
|
spreadRadius: 3,
|
||||||
blurRadius: 7,
|
blurRadius: 7,
|
||||||
offset: const Offset(0, 3),
|
offset: const Offset(0, 3),
|
||||||
|
|
@ -28,64 +28,45 @@ class ExampleCard extends StatelessWidget {
|
||||||
),
|
),
|
||||||
alignment: Alignment.center,
|
alignment: Alignment.center,
|
||||||
child: Column(
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Flexible(
|
Flexible(
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
gradient: candidate.color,
|
gradient: LinearGradient(
|
||||||
borderRadius: const BorderRadius.only(
|
begin: Alignment.topCenter,
|
||||||
topLeft: Radius.circular(10),
|
end: Alignment.bottomCenter,
|
||||||
topRight: Radius.circular(10),
|
colors: candidate.color,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
Padding(
|
||||||
padding: const EdgeInsets.all(15),
|
padding: const EdgeInsets.all(16),
|
||||||
decoration: const BoxDecoration(
|
child: Column(
|
||||||
color: Colors.white,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
borderRadius: BorderRadius.only(
|
|
||||||
bottomLeft: Radius.circular(10),
|
|
||||||
bottomRight: Radius.circular(10),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
children: [
|
||||||
Column(
|
Text(
|
||||||
mainAxisSize: MainAxisSize.min,
|
candidate.name,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
style: const TextStyle(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
color: Colors.black,
|
||||||
children: [
|
fontWeight: FontWeight.bold,
|
||||||
Text(
|
fontSize: 20,
|
||||||
candidate.name!,
|
),
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.black,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
fontSize: 20,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 5,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
candidate.job!,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.grey,
|
|
||||||
fontSize: 15,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 5,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
candidate.city!,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.grey,
|
|
||||||
fontSize: 15,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 5),
|
||||||
|
Text(
|
||||||
|
candidate.job,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.grey,
|
||||||
|
fontSize: 15,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 5),
|
||||||
|
Text(
|
||||||
|
candidate.city,
|
||||||
|
style: const TextStyle(color: Colors.grey),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -2,27 +2,14 @@ import 'dart:developer';
|
||||||
|
|
||||||
import 'package:example/example_candidate_model.dart';
|
import 'package:example/example_candidate_model.dart';
|
||||||
import 'package:example/example_card.dart';
|
import 'package:example/example_card.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_card_swiper/flutter_card_swiper.dart';
|
import 'package:flutter_card_swiper/flutter_card_swiper.dart';
|
||||||
|
|
||||||
import 'example_buttons.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MyApp());
|
runApp(const MaterialApp(
|
||||||
}
|
debugShowCheckedModeBanner: false,
|
||||||
|
home: Example(),
|
||||||
class MyApp extends StatelessWidget {
|
));
|
||||||
const MyApp({
|
|
||||||
Key? key,
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return const CupertinoApp(
|
|
||||||
debugShowCheckedModeBanner: false,
|
|
||||||
home: Example(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Example extends StatefulWidget {
|
class Example extends StatefulWidget {
|
||||||
|
|
@ -37,57 +24,44 @@ class Example extends StatefulWidget {
|
||||||
class _ExamplePageState extends State<Example> {
|
class _ExamplePageState extends State<Example> {
|
||||||
final CardSwiperController controller = CardSwiperController();
|
final CardSwiperController controller = CardSwiperController();
|
||||||
|
|
||||||
List<ExampleCard> cards = [];
|
final cards = candidates.map((candidate) => ExampleCard(candidate)).toList();
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
_loadCards();
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
void _loadCards() {
|
|
||||||
for (ExampleCandidateModel candidate in candidates) {
|
|
||||||
cards.add(
|
|
||||||
ExampleCard(
|
|
||||||
candidate: candidate,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return CupertinoPageScaffold(
|
return Scaffold(
|
||||||
child: Column(
|
body: SafeArea(
|
||||||
children: [
|
child: Column(
|
||||||
const SizedBox(
|
children: [
|
||||||
height: 50,
|
Flexible(
|
||||||
),
|
child: CardSwiper(
|
||||||
SizedBox(
|
controller: controller,
|
||||||
height: MediaQuery.of(context).size.height * 0.75,
|
cards: cards,
|
||||||
child: CardSwiper(
|
onSwipe: _swipe,
|
||||||
controller: controller,
|
padding: const EdgeInsets.all(24.0),
|
||||||
cards: cards,
|
|
||||||
onSwipe: _swipe,
|
|
||||||
padding: const EdgeInsets.only(
|
|
||||||
left: 25,
|
|
||||||
right: 25,
|
|
||||||
top: 50,
|
|
||||||
bottom: 40,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
Padding(
|
||||||
Row(
|
padding: EdgeInsets.symmetric(vertical: 16.0),
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
child: Row(
|
||||||
children: [
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
swipeLeftButton(controller),
|
children: [
|
||||||
const SizedBox(
|
FloatingActionButton(
|
||||||
width: 20,
|
onPressed: controller.swipe,
|
||||||
|
child: Icon(Icons.rotate_right),
|
||||||
|
),
|
||||||
|
FloatingActionButton(
|
||||||
|
onPressed: controller.swipeLeft,
|
||||||
|
child: Icon(Icons.keyboard_arrow_left),
|
||||||
|
),
|
||||||
|
FloatingActionButton(
|
||||||
|
onPressed: controller.swipeRight,
|
||||||
|
child: Icon(Icons.keyboard_arrow_right),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
swipeRightButton(controller),
|
)
|
||||||
],
|
],
|
||||||
)
|
),
|
||||||
],
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ packages:
|
||||||
path: ".."
|
path: ".."
|
||||||
relative: true
|
relative: true
|
||||||
source: path
|
source: path
|
||||||
version: "1.0.0"
|
version: "1.0.2"
|
||||||
material_color_utilities:
|
material_color_utilities:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue