Created
October 31, 2024 10:46
-
-
Save MaherSafadii/0393dd9593175e76816569b13028f1f8 to your computer and use it in GitHub Desktop.
SwiftUI Demo Config - Flutter replica
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:cupertino_calendar_picker/cupertino_calendar_picker.dart'; | |
import 'package:flutter/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const CupertinoApp( | |
localizationsDelegates: [ | |
DefaultWidgetsLocalizations.delegate, | |
DefaultCupertinoLocalizations.delegate, | |
DefaultMaterialLocalizations.delegate, | |
], | |
home: SwiftUIDemo(), | |
)); | |
} | |
class SwiftUIDemo extends StatefulWidget { | |
const SwiftUIDemo({super.key}); | |
@override | |
State<SwiftUIDemo> createState() => _SwiftUIDemoState(); | |
} | |
class _SwiftUIDemoState extends State<SwiftUIDemo> { | |
bool switchValue = true; | |
int awesomenessCount = 0; | |
@override | |
Widget build(BuildContext context) { | |
return CupertinoPageScaffold( | |
backgroundColor: CupertinoColors.secondarySystemBackground.resolveFrom(context), | |
child: CustomScrollView( | |
slivers: [ | |
const CupertinoSliverNavigationBar( | |
largeTitle: Text('SwiftUI Config Demo'), | |
stretch: true, | |
), | |
SliverToBoxAdapter( | |
child: Column( | |
children: [ | |
CupertinoListSection.insetGrouped( | |
footer: Padding( | |
padding: const EdgeInsets.only(left: 20), | |
child: Transform.translate( | |
offset: const Offset(0, -3), | |
child: const Text( | |
'This section contains some useful settings.', | |
style: | |
TextStyle(fontSize: 13, color: CupertinoColors.secondaryLabel, fontWeight: FontWeight.w400), | |
), | |
), | |
), | |
header: const Padding( | |
padding: EdgeInsets.only(left: 20), | |
child: Text( | |
'FIRST SECTION', | |
style: | |
TextStyle(fontSize: 13, color: CupertinoColors.secondaryLabel, fontWeight: FontWeight.w400), | |
), | |
), | |
children: [ | |
CupertinoListTile( | |
title: const Text('On or off: you choose'), | |
trailing: CupertinoSwitch( | |
value: switchValue, | |
onChanged: (value) { | |
switchValue = value; | |
setState(() {}); | |
}), | |
), | |
CupertinoListTile( | |
title: Text('Awesomeness: $awesomenessCount'), | |
trailing: customStepper(context, changeValue: (value) { | |
// awesomenessCount = value; | |
}), | |
), | |
CupertinoListTile( | |
title: const Text('Date'), | |
trailing: Row( | |
spacing: 5, | |
children: [ | |
CupertinoCalendarPickerButton( | |
mainColor: CupertinoTheme.of(context).primaryColor, | |
minimumDateTime: DateTime(2024, 7, 10), | |
maximumDateTime: DateTime(2025, 7, 10), | |
initialDateTime: DateTime.now(), | |
currentDateTime: DateTime.now(), | |
mode: CupertinoCalendarMode.date, | |
timeLabel: 'Ends', | |
onDateTimeChanged: (date) {}, | |
), | |
CupertinoTimePickerButton( | |
mainColor: CupertinoTheme.of(context).primaryColor, | |
initialTime: const TimeOfDay(hour: 9, minute: 41), | |
onTimeChanged: (time) {}, | |
), | |
], | |
), | |
), | |
], | |
), | |
CupertinoListSection.insetGrouped( | |
header: const Padding( | |
padding: EdgeInsets.only(left: 20), | |
child: Text( | |
'SECOND SECTION', | |
style: | |
TextStyle(fontSize: 13, color: CupertinoColors.secondaryLabel, fontWeight: FontWeight.w400), | |
), | |
), | |
children: const [ | |
CupertinoListTile( | |
title: Text('Hello, world!'), | |
), | |
CupertinoListTile( | |
title: Text('Hello, world!'), | |
), | |
CupertinoListTile( | |
title: Text('Hello, world!'), | |
), | |
CupertinoListTile( | |
title: Text('Hello, world!'), | |
), | |
], | |
) | |
], | |
), | |
), | |
], | |
), | |
); | |
} | |
Widget customStepper(BuildContext context, | |
{double width = 94, double height = 32, required void Function(bool isIncrement) changeValue}) { | |
return SizedBox( | |
width: width, | |
height: height, | |
child: Container( | |
decoration: BoxDecoration( | |
borderRadius: BorderRadius.circular(8), color: CupertinoColors.tertiarySystemFill.resolveFrom(context)), | |
child: Row( | |
children: [ | |
CupertinoButton( | |
padding: EdgeInsets.zero, | |
onPressed: () { | |
awesomenessCount--; | |
setState(() {}); | |
}, | |
child: const Icon(CupertinoIcons.minus, color: Colors.black), | |
), | |
SizedBox( | |
width: 1.2, | |
child: Container( | |
margin: const EdgeInsets.fromLTRB(0, 6, 0, 6), | |
color: const Color(0xffd6d6d6), | |
), | |
), | |
Expanded( | |
flex: 1, | |
child: Stack( | |
children: [ | |
CupertinoButton( | |
padding: EdgeInsets.zero, | |
onPressed: () { | |
awesomenessCount++; | |
setState(() {}); | |
}, | |
child: const Icon(CupertinoIcons.add, color: Colors.black), | |
), | |
], | |
)), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment