Skip to content

Commit 0b64808

Browse files
Merge pull request #2 from zeeshan-rsys/main
feat: draggable widget
2 parents 20c24e7 + 54b0dc8 commit 0b64808

File tree

11 files changed

+208
-61
lines changed

11 files changed

+208
-61
lines changed

android/app/src/debug/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.example.project">
2+
package="com.example.100daysofflutter">
33
<!-- The INTERNET permission is required for development. Specifically,
44
the Flutter tool needs it to communicate with the running application
55
to allow setting breakpoints, to provide hot reload, etc.

android/app/src/main/kotlin/com/example/project/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.example.project
1+
package com.example.100daysofflutter
22

33
import io.flutter.embedding.android.FlutterActivity
44

android/app/src/profile/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.example.project">
2+
package="com.example.100daysofflutter">
33
<!-- The INTERNET permission is required for development. Specifically,
44
the Flutter tool needs it to communicate with the running application
55
to allow setting breakpoints, to provide hot reload, etc.

assets/images/app_icon.png

115 KB
Loading

lib/constants/assets.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Assets {
2+
Assets._();
3+
static const appIcon = 'assets/images/app_icon.png';
4+
}

lib/ui/Alignment_align/animated_align_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class _AnimatedAlignWidgetState extends State<AnimatedAlignWidget> {
6161
Widget build(BuildContext context) {
6262
return Scaffold(
6363
appBar: LightAppBar(
64-
title: 'Day 1',
64+
title: 'Animated align',
6565
),
6666
body: SafeArea(
6767
child: InkWell(

lib/ui/dragabble/dragabble.dart

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import 'dart:developer';
2+
3+
import 'package:flutter/material.dart';
4+
import 'package:project/constants/assets.dart';
5+
import 'package:project/constants/colors.dart';
6+
import 'package:project/constants/text_theme.dart';
7+
import 'package:project/widget/light_app_bar.dart';
8+
9+
class DraggableScreen extends StatefulWidget {
10+
const DraggableScreen({Key? key}) : super(key: key);
11+
12+
@override
13+
State<DraggableScreen> createState() => _DraggableScreenState();
14+
}
15+
16+
class _DraggableScreenState extends State<DraggableScreen> {
17+
Offset _drag(Draggable draggable, BuildContext contex, Offset offset) {
18+
log('check drag - ${offset}');
19+
return Offset(20, 40);
20+
}
21+
22+
@override
23+
Widget build(BuildContext context) {
24+
return Scaffold(
25+
appBar: LightAppBar(title: 'Dragabble'),
26+
body: SafeArea(
27+
child: Column(
28+
mainAxisAlignment: MainAxisAlignment.center,
29+
crossAxisAlignment: CrossAxisAlignment.center,
30+
children: [
31+
Center(
32+
child: Draggable(
33+
// use axis to fix your drag in single axis
34+
axis: Axis.vertical,
35+
affinity: Axis.vertical,
36+
// this show you the initial position of draggable widget
37+
feedbackOffset: const Offset(1, 1),
38+
maxSimultaneousDrags: 1,
39+
onDragCompleted: () {
40+
log('drag is done');
41+
},
42+
data: 10,
43+
dragAnchorStrategy: _drag,
44+
childWhenDragging: Container(
45+
height: 100,
46+
width: 100,
47+
decoration: BoxDecoration(
48+
border: Border.all(color: AppColors.primaryColor),
49+
),
50+
child: Center(
51+
child: Text(
52+
'Leave me now',
53+
style: themeData.textTheme.bodyText2?.copyWith(
54+
color: AppColors.primaryColor,
55+
),
56+
),
57+
),
58+
),
59+
feedback: Center(
60+
child: Image.asset(
61+
Assets.appIcon,
62+
height: 100,
63+
width: 100,
64+
),
65+
),
66+
child: Container(
67+
height: 100,
68+
width: 100,
69+
color: AppColors.gray,
70+
child: Center(
71+
child: Text(
72+
'Drag me ',
73+
style: themeData.textTheme.bodyText2?.copyWith(
74+
color: AppColors.white,
75+
),
76+
),
77+
),
78+
),
79+
),
80+
),
81+
],
82+
),
83+
),
84+
);
85+
}
86+
}

lib/ui/home_screen.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ class _HomeScreenState extends State<HomeScreen> {
2525
physics: const NeverScrollableScrollPhysics(),
2626
itemBuilder: ((context, index) {
2727
var data = tasks[index];
28-
return ListCard(data: data);
28+
return ListCard(
29+
data: data,
30+
index: index,
31+
);
2932
}),
3033
separatorBuilder: (ctx, index) => DeviceUtils.blankHeight(16),
3134
itemCount: tasks.length,

lib/utils/routes.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import 'package:flutter/material.dart';
22
import 'package:project/ui/Alignment_align/animated_align_screen.dart';
3+
import 'package:project/ui/dragabble/dragabble.dart';
34

45
class Routes {
5-
static Map<String, Widget Function(BuildContext)> route = {
6-
day1:(context) => const AnimatedAlignWidget(),
7-
};
6+
static Map<String, Widget Function(BuildContext)> route = {
7+
ep1: (context) => const AnimatedAlignWidget(),
8+
ep2: (p0) => const DraggableScreen(),
9+
};
810

9-
static String day1='/day_1_animated_align';
11+
static String ep1 = '/animated_align_screen';
12+
static String ep2 = '/dragabble';
1013
}

lib/utils/task_list.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@ class DailyTask {
1717
List<DailyTask> tasks = [
1818
DailyTask(
1919
description: 'Animated align',
20-
title: 'Day 1',
20+
title: 'Ep: 1',
2121
cretedAt: DateTime(2022, 10, 8),
22-
route: Routes.day1,
22+
route: Routes.ep1,
23+
),
24+
DailyTask(
25+
description: 'Dragabble',
26+
title: 'Ep: 2',
27+
cretedAt: DateTime(2022, 10, 16),
28+
route: Routes.ep2,
2329
),
2430
];

0 commit comments

Comments
 (0)