Created
May 3, 2020 09:57
-
-
Save agvozditskiy/f08ed81591c39d0a91ef41fd6da1e167 to your computer and use it in GitHub Desktop.
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:flutter/material.dart'; | |
final Color darkBlue = Color.fromARGB(255, 18, 32, 47); | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue), | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: MyWidget(), | |
), | |
), | |
); | |
} | |
} | |
class MyWidget extends StatelessWidget { | |
final List<String> items = ['one', 'two', 'three', 'four', 'five']; | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
color: Colors.white10, | |
width: 200, | |
height: 300, | |
child: PageView.builder( | |
physics: PageScrollPhysics(), | |
scrollDirection: Axis.horizontal, | |
controller: PageController(viewportFraction: 0.7), | |
itemCount: items.length, | |
itemBuilder: (_, index) => | |
_Item(index, items.length - 1, items[index])), | |
); | |
} | |
} | |
class _Item extends StatelessWidget { | |
const _Item( | |
this._index, | |
this._maxIndex, | |
this._name, { | |
Key key, | |
}) : super(key: key); | |
final int _index; | |
final int _maxIndex; | |
final String _name; | |
Widget build(BuildContext context) { | |
return Padding( | |
padding: EdgeInsets.fromLTRB( | |
_index == 0 ? 4 : 8.0, | |
8.0, | |
_index == _maxIndex ? 4 : 8.0, | |
8.0, | |
), | |
child: Container( | |
width: 140, color: Colors.amber, child: Center(child: Text(_name))), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment