Skip to content

Instantly share code, notes, and snippets.

@agvozditskiy
Created May 3, 2020 09:54
Show Gist options
  • Save agvozditskiy/32a1a13c85bf48558bb30c70798d4b0d to your computer and use it in GitHub Desktop.
Save agvozditskiy/32a1a13c85bf48558bb30c70798d4b0d to your computer and use it in GitHub Desktop.
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: ListView.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