Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ International:
## Usage

```
FlatButton(
TextButton(
onPressed: () {
DatePicker.showDatePicker(context,
showTitleActions: true,
Expand Down
22 changes: 15 additions & 7 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<application
android:name="io.flutter.app.FlutterApplication"
android:label="example"
android:icon="@mipmap/ic_launcher">
<activity
Expand All @@ -23,17 +22,26 @@
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<!-- Specify that the launch screen should continue being displayed -->
<!-- until Flutter renders its first frame. -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
android:name="io.flutter.embedding.android.SplashScreenDrawable"
android:resource="@drawable/launch_background" />

<!-- Theme to apply as soon as Flutter begins rendering frames -->
<meta-data
android:name="io.flutter.embedding.android.NormalTheme"
android:resource="@style/NormalTheme" />

<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<meta-data
android:name="flutterEmbedding"
android:value="2" />

</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
package com.realank.example;
import io.flutter.embedding.android.FlutterActivity;

import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;

public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
public class MainActivity extends FlutterActivity {}
4 changes: 4 additions & 0 deletions example/android/app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
Flutter draws its first frame -->
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
<!-- You can name this style whatever you'd like -->
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
<item name="android:windowBackground">@drawable/launch_background</item>
</style>
</resources>
1 change: 1 addition & 0 deletions example/ios/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Icon?
/Flutter/Flutter.framework
/Flutter/Generated.xcconfig
/ServiceDefinitions.json
/Flutter/flutter_export_environment.sh

Pods/
.symlinks/
116 changes: 77 additions & 39 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ class CustomPicker extends CommonPickerModel {
return '$value'.padLeft(length, "0");
}

CustomPicker({DateTime currentTime, LocaleType locale}) : super(locale: locale) {
CustomPicker({DateTime? currentTime, LocaleType? locale})
: super(locale: locale) {
this.currentTime = currentTime ?? DateTime.now();
this.setLeftIndex(this.currentTime.hour);
this.setMiddleIndex(this.currentTime.minute);
this.setRightIndex(this.currentTime.second);
}

@override
String leftStringAtIndex(int index) {
String? leftStringAtIndex(int index) {
if (index >= 0 && index < 24) {
return this.digits(index, 2);
} else {
Expand All @@ -25,7 +26,7 @@ class CustomPicker extends CommonPickerModel {
}

@override
String middleStringAtIndex(int index) {
String? middleStringAtIndex(int index) {
if (index >= 0 && index < 60) {
return this.digits(index, 2);
} else {
Expand All @@ -34,7 +35,7 @@ class CustomPicker extends CommonPickerModel {
}

@override
String rightStringAtIndex(int index) {
String? rightStringAtIndex(int index) {
if (index >= 0 && index < 60) {
return this.digits(index, 2);
} else {
Expand All @@ -60,10 +61,20 @@ class CustomPicker extends CommonPickerModel {
@override
DateTime finalTime() {
return currentTime.isUtc
? DateTime.utc(currentTime.year, currentTime.month, currentTime.day,
this.currentLeftIndex(), this.currentMiddleIndex(), this.currentRightIndex())
: DateTime(currentTime.year, currentTime.month, currentTime.day, this.currentLeftIndex(),
this.currentMiddleIndex(), this.currentRightIndex());
? DateTime.utc(
currentTime.year,
currentTime.month,
currentTime.day,
this.currentLeftIndex(),
this.currentMiddleIndex(),
this.currentRightIndex())
: DateTime(
currentTime.year,
currentTime.month,
currentTime.day,
this.currentLeftIndex(),
this.currentMiddleIndex(),
this.currentRightIndex());
}
}

Expand Down Expand Up @@ -91,7 +102,7 @@ class HomePage extends StatelessWidget {
body: Center(
child: Column(
children: <Widget>[
FlatButton(
TextButton(
onPressed: () {
DatePicker.showDatePicker(context,
showTitleActions: true,
Expand All @@ -101,10 +112,14 @@ class HomePage extends StatelessWidget {
headerColor: Colors.orange,
backgroundColor: Colors.blue,
itemStyle: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold, fontSize: 18),
doneStyle: TextStyle(color: Colors.white, fontSize: 16)),
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 18),
doneStyle:
TextStyle(color: Colors.white, fontSize: 16)),
onChanged: (date) {
print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
print('change $date in time zone ' +
date.timeZoneOffset.inHours.toString());
}, onConfirm: (date) {
print('confirm $date');
}, currentTime: DateTime.now(), locale: LocaleType.en);
Expand All @@ -113,10 +128,12 @@ class HomePage extends StatelessWidget {
'show date picker(custom theme &date time range)',
style: TextStyle(color: Colors.blue),
)),
FlatButton(
TextButton(
onPressed: () {
DatePicker.showTimePicker(context, showTitleActions: true, onChanged: (date) {
print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
DatePicker.showTimePicker(context, showTitleActions: true,
onChanged: (date) {
print('change $date in time zone ' +
date.timeZoneOffset.inHours.toString());
}, onConfirm: (date) {
print('confirm $date');
}, currentTime: DateTime.now());
Expand All @@ -125,10 +142,12 @@ class HomePage extends StatelessWidget {
'show time picker',
style: TextStyle(color: Colors.blue),
)),
FlatButton(
TextButton(
onPressed: () {
DatePicker.showTime12hPicker(context, showTitleActions: true, onChanged: (date) {
print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
DatePicker.showTime12hPicker(context, showTitleActions: true,
onChanged: (date) {
print('change $date in time zone ' +
date.timeZoneOffset.inHours.toString());
}, onConfirm: (date) {
print('confirm $date');
}, currentTime: DateTime.now());
Expand All @@ -137,13 +156,14 @@ class HomePage extends StatelessWidget {
'show 12H time picker with AM/PM',
style: TextStyle(color: Colors.blue),
)),
FlatButton(
TextButton(
onPressed: () {
DatePicker.showDateTimePicker(context,
showTitleActions: true,
minTime: DateTime(2020, 5, 5, 20, 50),
maxTime: DateTime(2020, 6, 7, 05, 09), onChanged: (date) {
print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
print('change $date in time zone ' +
date.timeZoneOffset.inHours.toString());
}, onConfirm: (date) {
print('confirm $date');
}, locale: LocaleType.zh);
Expand All @@ -152,10 +172,12 @@ class HomePage extends StatelessWidget {
'show date time picker (Chinese)',
style: TextStyle(color: Colors.blue),
)),
FlatButton(
TextButton(
onPressed: () {
DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
DatePicker.showDateTimePicker(context, showTitleActions: true,
onChanged: (date) {
print('change $date in time zone ' +
date.timeZoneOffset.inHours.toString());
}, onConfirm: (date) {
print('confirm $date');
}, currentTime: DateTime(2008, 12, 31, 23, 12, 34));
Expand All @@ -164,49 +186,65 @@ class HomePage extends StatelessWidget {
'show date time picker (English-America)',
style: TextStyle(color: Colors.blue),
)),
FlatButton(
TextButton(
onPressed: () {
DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
DatePicker.showDateTimePicker(context, showTitleActions: true,
onChanged: (date) {
print('change $date in time zone ' +
date.timeZoneOffset.inHours.toString());
}, onConfirm: (date) {
print('confirm $date');
}, currentTime: DateTime(2008, 12, 31, 23, 12, 34), locale: LocaleType.nl);
},
currentTime: DateTime(2008, 12, 31, 23, 12, 34),
locale: LocaleType.nl);
},
child: Text(
'show date time picker (Dutch)',
style: TextStyle(color: Colors.blue),
)),
FlatButton(
TextButton(
onPressed: () {
DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
DatePicker.showDateTimePicker(context, showTitleActions: true,
onChanged: (date) {
print('change $date in time zone ' +
date.timeZoneOffset.inHours.toString());
}, onConfirm: (date) {
print('confirm $date');
}, currentTime: DateTime(2008, 12, 31, 23, 12, 34), locale: LocaleType.ru);
},
currentTime: DateTime(2008, 12, 31, 23, 12, 34),
locale: LocaleType.ru);
},
child: Text(
'show date time picker (Russian)',
style: TextStyle(color: Colors.blue),
)),
FlatButton(
TextButton(
onPressed: () {
DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
DatePicker.showDateTimePicker(context, showTitleActions: true,
onChanged: (date) {
print('change $date in time zone ' +
date.timeZoneOffset.inHours.toString());
}, onConfirm: (date) {
print('confirm $date');
}, currentTime: DateTime.utc(2019, 12, 31, 23, 12, 34), locale: LocaleType.de);
},
currentTime: DateTime.utc(2019, 12, 31, 23, 12, 34),
locale: LocaleType.de);
},
child: Text(
'show date time picker in UTC (German)',
style: TextStyle(color: Colors.blue),
)),
FlatButton(
TextButton(
onPressed: () {
DatePicker.showPicker(context, showTitleActions: true, onChanged: (date) {
print('change $date in time zone ' + date.timeZoneOffset.inHours.toString());
DatePicker.showPicker(context, showTitleActions: true,
onChanged: (date) {
print('change $date in time zone ' +
date.timeZoneOffset.inHours.toString());
}, onConfirm: (date) {
print('confirm $date');
}, pickerModel: CustomPicker(currentTime: DateTime.now()), locale: LocaleType.en);
},
pickerModel: CustomPicker(currentTime: DateTime.now()),
locale: LocaleType.en);
},
child: Text(
'show custom time picker,\nyou can custom picker model like this',
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ description: A new Flutter application.
version: 1.0.0+1

environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"

dependencies:
flutter:
sdk: flutter

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
cupertino_icons: ^1.0.2
flutter_datetime_picker:
path: ../

Expand Down
Loading