Last active
March 1, 2024 08:45
-
-
Save OnlyTarg/dc21de603d828a369d4c73c9e5100dc4 to your computer and use it in GitHub Desktop.
flutter 3.19
This file contains 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:flutter/material.dart'; | |
import 'package:flutter/gestures.dart'; | |
void main() { | |
runApp(const FlutterPresentation()); | |
} | |
class _FlutterPresentationState extends State<FlutterPresentation> { | |
Set<AnimationStyles> _animationStyleSelection = <AnimationStyles>{ | |
AnimationStyles.defaultStyle, | |
}; | |
AnimationStyle? _animationStyle; | |
bool isDarkTheme = false; | |
final switchList = List.generate(100, (index) => false); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
scrollBehavior: MyCustomScrollBehavior(), | |
themeAnimationStyle: _animationStyle, | |
key: FlutterPresentation._globalKey, | |
themeMode: isDarkTheme ? ThemeMode.dark : ThemeMode.light, | |
theme: ThemeData( | |
brightness: Brightness.light, | |
useMaterial3: true, | |
), | |
darkTheme: ThemeData( | |
brightness: Brightness.dark, | |
useMaterial3: true, | |
), | |
builder: (context, child) => MediaQuery.withClampedTextScaling( | |
minScaleFactor: 1.0, | |
maxScaleFactor: 2.0, | |
child: child!, | |
), | |
home: Scaffold( | |
body: SafeArea( | |
child: Center( | |
child: CustomScrollView( | |
// scrollBehavior: MyCustomScrollBehavior(), | |
slivers: [ | |
const SliverAppBar( | |
title: Text('Flutter 3.19 Example App'), | |
), | |
SliverToBoxAdapter( | |
child: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
SegmentedButton<AnimationStyles>( | |
selected: _animationStyleSelection, | |
onSelectionChanged: (Set<AnimationStyles> styles) { | |
setState(() { | |
_animationStyleSelection = styles; | |
switch (styles.first) { | |
case AnimationStyles.defaultStyle: | |
_animationStyle = null; | |
case AnimationStyles.custom: | |
_animationStyle = AnimationStyle( | |
curve: Easing.emphasizedAccelerate, | |
duration: const Duration(seconds: 1), | |
); | |
case AnimationStyles.none: | |
_animationStyle = AnimationStyle.noAnimation; | |
} | |
}); | |
}, | |
segments: animationStyleSegments | |
.map<ButtonSegment<AnimationStyles>>( | |
((AnimationStyles, String) shirt) { | |
return ButtonSegment<AnimationStyles>( | |
value: shirt.$1, | |
label: Text(shirt.$2), | |
); | |
}).toList(), | |
), | |
const SizedBox(height: 10), | |
OutlinedButton.icon( | |
onPressed: () { | |
setState(() { | |
isDarkTheme = !isDarkTheme; | |
}); | |
}, | |
icon: Icon( | |
isDarkTheme | |
? Icons.wb_sunny | |
: Icons.nightlight_round, | |
), | |
label: const Text('Switch Theme Mode'), | |
), | |
Center( | |
child: Column( | |
children: <Widget>[ | |
const ExpansionTile( | |
title: Text('ExpansionTile 1'), | |
subtitle: Text('Trailing expansion arrow icon'), | |
children: <Widget>[ | |
ListTile( | |
title: Text('This is tile number 1'), | |
), | |
], | |
), | |
ExpansionTile( | |
expansionAnimationStyle: AnimationStyle( | |
duration: const Duration(seconds: 1), | |
curve: Curves.bounceOut, | |
), | |
title: const Text('ExpansionTile 2'), | |
subtitle: | |
const Text('Trailing expansion arrow icon'), | |
children: const <Widget>[ | |
ListTile( | |
title: Text('This is tile number 2'), | |
), | |
], | |
), | |
], | |
), | |
), | |
PopupMenuButton<Menu>( | |
popUpAnimationStyle: _animationStyle, | |
icon: const Icon(Icons.more_vert), | |
onSelected: (Menu item) {}, | |
itemBuilder: (BuildContext context) => | |
<PopupMenuEntry<Menu>>[ | |
const PopupMenuItem<Menu>( | |
value: Menu.preview, | |
child: ListTile( | |
leading: Icon(Icons.visibility_outlined), | |
title: Text('Preview'), | |
), | |
), | |
const PopupMenuItem<Menu>( | |
value: Menu.share, | |
child: ListTile( | |
leading: Icon(Icons.share_outlined), | |
title: Text('Share'), | |
), | |
), | |
const PopupMenuItem<Menu>( | |
value: Menu.getLink, | |
child: ListTile( | |
leading: Icon(Icons.link_outlined), | |
title: Text('Get link'), | |
), | |
), | |
const PopupMenuDivider(), | |
const PopupMenuItem<Menu>( | |
value: Menu.remove, | |
child: ListTile( | |
leading: Icon(Icons.delete_outline), | |
title: Text('Remove'), | |
), | |
), | |
const PopupMenuItem<Menu>( | |
value: Menu.download, | |
child: ListTile( | |
leading: Icon(Icons.download_outlined), | |
title: Text('Download'), | |
), | |
), | |
], | |
), | |
], | |
), | |
), | |
), | |
SliverList( | |
delegate: SliverChildBuilderDelegate( | |
(context, index) { | |
return Row( | |
children: [ | |
SizedBox(width: 0 + index * 2), | |
const Text('Test switch'), | |
Switch.adaptive( | |
value: switchList[index], | |
onChanged: (value) { | |
setState(() { | |
switchList[index] = value; | |
}); | |
}, | |
), | |
], | |
); | |
}, | |
childCount: 100, | |
), | |
), | |
], | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
enum AnimationStyles { defaultStyle, custom, none } | |
const List<(AnimationStyles, String)> animationStyleSegments = | |
<(AnimationStyles, String)>[ | |
(AnimationStyles.defaultStyle, 'Default'), | |
(AnimationStyles.custom, 'Custom'), | |
(AnimationStyles.none, 'None'), | |
]; | |
enum Menu { preview, share, getLink, remove, download } | |
class MyCustomScrollBehavior extends MaterialScrollBehavior { | |
@override | |
MultitouchDragStrategy get multitouchDragStrategy => | |
MultitouchDragStrategy.latestPointer; | |
} | |
class FlutterPresentation extends StatefulWidget { | |
const FlutterPresentation({super.key}); | |
static final _globalKey = GlobalKey(); | |
@override | |
State<FlutterPresentation> createState() => _FlutterPresentationState(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment