Skip to content

Instantly share code, notes, and snippets.

@rashmisridar
Created December 17, 2020 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rashmisridar/18217dcbf3b8451cba13cd4b79b9c595 to your computer and use it in GitHub Desktop.
Save rashmisridar/18217dcbf3b8451cba13cd4b79b9c595 to your computer and use it in GitHub Desktop.
In the pageview item need to add border
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
// This widget is the root of your application.
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
double _deviceHeight = 0;
double _deviceWidth = 0;
List<MaterialColor> _colorList = List();
@override
void initState() {
super.initState();
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
_colorList.add(Colors.red);
} else {
_colorList.add(Colors.blue);
}
}
}
@override
Widget build(BuildContext context) {
_deviceHeight = MediaQuery.of(context).size.height;
_deviceWidth = MediaQuery.of(context).size.width;
return Scaffold(
body: Container(
child: Stack(children: [
PageView.builder(
itemCount: _colorList.length,
itemBuilder: (BuildContext context, int index) {
return Container(
color: _colorList[index],
);
}),
Positioned(
top: 0.0,
left: -3.0,
right: 0.0,
child: PreferredSize(
preferredSize: Size.fromHeight(100.0),
child: Container(
margin: EdgeInsets.fromLTRB(5.0, 10.0, 0.0, 10.0),
child: AppBar(
backgroundColor: Colors.transparent,
elevation: 0,
centerTitle: false,
titleSpacing: 0.0,
automaticallyImplyLeading: false,
title: Text(
"Welcome to flutter ",
style: TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
),
),
),
),
Positioned(
top: _deviceHeight / 8,
left: -3.0,
right: 0.0,
child: Center(
child: Text(
"Hi",
style: TextStyle(color: Colors.white, fontSize: 60),
textAlign: TextAlign.center,
),
)),
Positioned(
top: _deviceHeight / 1.5,
left: 0.0,
right: 0.0,
child: Text(
"Bottom",
style: TextStyle(color: Colors.white, fontSize: 60),
textAlign: TextAlign.center,
)),
]),
));
}
@override
void dispose() {
super.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment