Complete Dialog is not scrollable but just the listview inside it is scrollable - flutter

I am trying to create a modal which contains some details and is scrollable. The modal contains a ListView which is scrollable, but the complete modal is not.
I have tried adding the following options to the ListView, but it didn't help
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics()
The minimum reproducible code is
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
// Application name
title: 'Flutter Stateful Clicker Counter',
theme: ThemeData(
// Application theme data, you can set the colors for the application as
// you want
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Clicker Counter Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
final String title;
const MyHomePage({Key? key, required this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
#override
_MyHomePageState createState() => _MyHomePageState();
}
_buildTheDescriptionWizard() {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
child: Text(
"Paneer is a fresh cheese used in a wide variety of Indian recipes, made by heating and then curdling milk using acid. It's very mild and milky in flavor, white in color, and its texture is soft, spongy, and squeaky. This texture helps it to absorb the flavors of sauces or marinades. It can be made from cow's milk or buffalo milk, either pasteurized or raw, and can be made from whole, skim or reduced-fat milk. ",
textAlign: TextAlign.left,
style: TextStyle(fontSize: 15, height: 1.5, color: Colors.black))),
);
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
#override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(40)),
elevation: 16,
child: createModal());
}
createModal() {
return Container(
height: 600,
width: 800,
child: Container(
color: Colors.white,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(children: <Widget>[
Container(
height: 300,
child: ListView(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
children: [
Container(
width: 300,
color: Colors.white,
// child:
// DropShadow(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Image.network(
'https://picsum.photos/250?image=9',
height: 250,
width: 250),
),
// )
),
Container(
width: 450, height: 300, color: Colors.black)
],
)),
Divider(),
_buildTheDescriptionWizard()
]))));
}
}
Can someone please help me figure out how I can make the complete modal scrollable ?

remove SingleChildScrollView and Column just use ListView and don't use shrinkWrap: true and physics: const NeverScrollableScrollPhysics()

Related

Flutter How to change container height based on the ListView's item height?

Hello I have a Scaffold wrapped with SingleChildScrollView and child is Column.
Inside Column; Container, TabBar and TabBarView.
First Container is just there for black space.
Container(
color: Colors.black,
height: 300,
),
The second widget of Column which mean TabBar:
(I know we can use it in AppBar but now it is what it is.)
const TabBar(
labelColor: Colors.red,
tabs: [
Tab(text: "Tab1"),
Tab(text: "Tab2"),
Tab(text: "Tab3"),
],
),
Last Column widget is TabBarView. It wrapped by Container that has 300 height.
Container(
height: 300, // here is problem
color: Colors.amber,
child: TabBarView(
children: [
buildContainer(200, Colors.red, 2),
buildContainer(100, Colors.red, 2),
buildContainer(150, Colors.red, 3),
],
),
),
and also this is buildContainer method;
buildContainer(double height, Color color, int count) => ListView.builder(
shrinkWrap: true,
itemCount: count,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: height,
color: color,
child: Center(
child: Text("my height ${height.toString()}"),
),
),
);
});
Here is my question. I have 3 tabs and I have three ListViewBuilder.Each one has own child count. But all of them height limited to 300 because of their parent that is Container. I want to set Tab's height dynamicly with each ListViewBuilder's item count.
How can I do that ? I accept dynamic height without child scrolling. I mean, I can scroll whole page for reach the last child. In example, Instagram profile tab. If I have 30 photo, height is phone height. But I have 300 photo, it scrolling all the way down. But also, I don't want to understand pagenation for this one. I am not going to do Instagram. I just want to that, If I create 5 container, okey show me your max height. If I create 1 container, show me just that without scrolling.
I added a dynamic height calculation depending on the number of objects in the ListView.builder. The formula is not perfect, you can add to it, but the point is to subtract the AppBar height and padding to get a clean screen area that the widget completely occupies.
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: mainWidget(),
);
}
Widget mainWidget() {
AppBar appBar = AppBar(
toolbarHeight: 56, //You can manually set the AppBar height
title: const Text("App bar"),
);
print(appBar.preferredSize); // Or you can save this value and use it later, it will not be fixed, but will depend on the screen size
return Scaffold(
appBar: appBar,
body: HelpSO(color: Colors.red, count: 5),
);
}
}
class HelpSO extends StatelessWidget {
late double height;
Color color;
int count;
HelpSO({Key? key, required this.color, required this.count})
: super(key: key);
#override
Widget build(BuildContext context) {
// height = (deviceHeight / itemCount) - padding (top + bottom) - appbar.prefferedSize.height / 2;
height = (MediaQuery.of(context).size.height / count) - 16.0 - 56 / 2;
return ListView.builder(
shrinkWrap: true,
itemCount: count,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.all(8.0), // Subtract this value
child: Container(
height: height,
color: color,
child: Center(
child: Text("My height ${height.toString()}"),
),
),
);
});
}
}
I'm new at flutter(2 m).I just come accros with this problem.
My solution was juste wrap first or second(base on your logic) container with a SingleChildScrollView
Hope it will be helpful

Flutter: ListView - Green overlay instead of arrows in widget inspector

I'm creating a ListView with a builder function. I use the widget inspector to assess the any issues with the layout of the widgets.
Usually, the listView shows downwards green arrows as shown here:
[ListView layout][1]
However, in my current app, whenever I create a listView, it shows this green overlay on the listView. This creates artefacts with Image widget nested in stack; the images flicker when scrolling. [artefact layout][2]
This layout does look like it will take the space of 'drawer' in scaffold however, this page does not have a drawer, although all the other pages do.
Please find the code below for your reference.
const BlogListPage({Key? key}) : super(key: key);
#override
State<BlogListPage> createState() => _BlogListPageState();
}
class _BlogListPageState extends State<BlogListPage> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: ASAppBar(
title: const Text('Blogs'),
),
body: ListView.builder(
itemCount: 10,
itemBuilder: (BuildContext context, int index) {
return Container(
margin:
const EdgeInsets.symmetric(vertical: 16.0, horizontal: 24.0),
color: Colors.amber,
child: const SizedBox(
height: 100,
width: double.infinity,
),
);
},
));
}
} ```
[1]: https://i.stack.imgur.com/O7Pnc.png
[2]: https://i.stack.imgur.com/0g5HF.png

PageStorageKey not loading between navigation

I've looked at just about every piece of info I can find on this subject but none of the solutions seem to be working for me. I have a persistent top nav bar that I pass the views through using a the MaterialApp builder function as shown below. Inside that NavFrame class I simply have two buttons to switch between views. The second view has a GridView with a PageStorageKey attached to it. If you scroll and switch between views you'll see the scroll position is not loaded when going back to the grid in view 2. I'm using the latest Auto-Route package for generating my routes.
main.dart
void main() {
runApp(MyApp());
}
final _navKey = GlobalKey<NavigatorState>();
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'PageStorageKey Debugging',
theme: ThemeData(
primarySwatch: Colors.green,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
initialRoute: Routes.view1,
navigatorKey: _navKey,
onGenerateRoute: Router().onGenerateRoute,
builder: (context, child) => NavFrame(_navKey, child),
);
}
}
nav_frame.dart
class NavFrame extends StatelessWidget {
final Widget child;
final GlobalKey<NavigatorState> _navKey;
const NavFrame(this._navKey, this.child, {Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Stack(
children: [
Positioned(
top: 0,
left: 0,
right: 0,
child: Container(
color: Colors.black,
height: 100,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
RaisedButton(
onPressed: () {
_navKey.currentState.pushReplacementNamed(Routes.view1);
},
child: Text('View 1'),
),
SizedBox(
width: 50,
),
RaisedButton(
onPressed: () {
_navKey.currentState.pushReplacementNamed(Routes.view2);
},
child: Text('View 2'),
),
],
),
)),
Positioned(
top: 100,
left: 0,
right: 0,
bottom: 0,
child: Container(
child: child,
),
),
],
);
}
}
view1.dart
class View1 extends StatelessWidget {
const View1({Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Column(
children: [
Expanded(
child: Container(
color: Colors.blue,
))
],
);
}
}
view2.dart
class View2 extends StatefulWidget {
const View2({Key key}) : super(key: key);
#override
_View2State createState() => _View2State();
}
class _View2State extends State<View2>
with AutomaticKeepAliveClientMixin<View2> {
final bucket = PageStorageBucket();
#override
Widget build(BuildContext context) {
super.build(context);
return Column(
children: [
Expanded(
child: GridView.builder(
key: new PageStorageKey('test-key'),
addAutomaticKeepAlives: true,
padding: EdgeInsets.all(30),
shrinkWrap: true,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 1,
childAspectRatio: 2,
crossAxisSpacing: 30,
mainAxisSpacing: 30,
),
itemCount: 10,
itemBuilder: (BuildContext context, int index) {
return Container(
decoration: BoxDecoration(
border: Border.all(width: 1.5, color: Colors.black),
borderRadius: BorderRadius.all(Radius.circular(10.0)),
),
child: Center(
child: Material(
child: Text(
index.toString(),
style: TextStyle(fontSize: 20),
),
),
));
},
),
)
],
);
}
#override
bool get wantKeepAlive => true;
}
router.dart
#MaterialAutoRouter(
generateNavigationHelperExtension: true,
routes: <AutoRoute>[
MaterialRoute(page: View1, initial: true),
MaterialRoute(page: View2, path: "/view2"),
],
)
class $Router {}
pubspec.yaml
name: PageStorageKeyTest
description: Debugging PageStorageKey.
publish_to: "none"
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# Navigation
auto_route: 0.6.6
# Cupertino
cupertino_icons: ^0.1.3
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: 1.10.1
auto_route_generator:
flutter:
uses-material-design: true
As mentioned I've tried many different suggested solutions I've been able to find. Currently in View2 you'll see I'm using the AutomaticKeepAliveCluentMixin with wantKeepAlive set to true. I did also make sure to call the super.build(context) as I saw suggested in one question on here. I also have tried using the PageStoreBucket in just about every place I can imagine and it doesn't seem to be doing anything. (Currently not being used in the above code). I've tried to set maintainState to true in the MaterialRoute. In my actual project where I'm running into this I'm using Stacked architecture and even tried passing the keys through the viewModel and having the viewModel builder only build once and nothing seems to be doing the trick. Running the above code should produce the exact issue I'm having. I'm also on the latest dev build I believe (1.21.0-1.0.pre). Any suggestions?
I was looking at this the wrong way from a UX perspective. You can achieved the desired effect of what I was talking about using a scrollController and saving the offset to a global variable or something and just reassigning it in the initState method to the initialOffset parameter of the scrollController. I used stacked architecture personally and stored the offset in a service class with a reactiveServiceMixin. This works for what I described, but it's not what I actually wanted, which I didn't realize until doing it and seeing it for myself. If you use the navigator to navigate to for example a shop page and then go to a blog and then click shop again from the navigator you would probably expect to be back to the beginning of the shop. When clicking the back button from the blog page to go back to the shop you would then probably expect it to save the scroll position. Turns out it was already doing all of that before implementing this.

How to open a web view of a link from an api?

See the image first:
enter image description here
So i have made a news app using https://newsapi.org/s/google-news-in-api
Code:
Widget build(BuildContext context) {
return Container(
child: Center(
child: isLoading
? CircularProgressIndicator()
: ListView.builder(
itemCount: newsData == null ? 0 : newsData.length,
itemBuilder: (context, int index) {
return GestureDetector(
onTap: () => Navigator.of(context).pushNamed("/headlines"),
child: Card(
margin: EdgeInsets.all(10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
elevation: 5,
child: Column(
children: <Widget>[
ClipRRect(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(15),
topRight: Radius.circular(15),
),
child: Image.network(newsData[index]['urlToImage']),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
newsData[index]['title'],
style: TextStyle(
fontSize: 23.0, fontWeight: FontWeight.bold),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child:
Align(
alignment: Alignment.bottomLeft,
child: Text(
newsData[index]['publishedAt'][11]
),
),
)
],
),
semanticContainer: false,
color: Colors.white70,
),
);
},
),
So how can i open the news website when the card is clicked/tapped in this app itself,
I mean how should i open the news website in this app rather than open it up in the browser using url_launcher
Note: I found a plugin "flutter_webview_plugin"
But still not able to implement it.
Also do remember that I need to keep the index number common for both the card and the source url.
Edit add click event to image
https://inducesmile.com/google-flutter/how-to-add-on-click-event-to-image-in-flutter/
You can wrap you news image with GestureDetector and do action in onTap
GestureDetector(
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => MyInAppWebView(webUrl: newsData[index][url],webRect: Rect.fromLTWH(0, 0, 300, 300))));
);
},
child: CircleAvatar(
backgroundImage: ExactAssetImage('assets/images/umbrella.png'),
minRadius: 80,
maxRadius: 120,
),
),
You can use https://pub.dev/packages/flutter_inappbrowser
You can display in widget directly or
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => MyInAppWebView(webUrl: "https://flutter.dev/",webRect: Rect.fromLTWH(0, 0, 300, 300))));
You can reference both situations in my full code
the simple MyInAppWebView just pass webUrl and WebRect
or you can reference complex demo (picture 2) in official site
class MyInAppWebView extends StatelessWidget {
String webUrl;
final Rect webRect;
InAppWebViewController webView;
MyInAppWebView({Key key, this.webUrl, this.webRect}) : super(key: key);
#override
Widget build(BuildContext context) {
InAppWebView webWidget = new InAppWebView(
initialUrl: webUrl,
initialHeaders: {},
initialOptions: {},
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {
print("InAppWebView.onLoadStart: $url");
this.webUrl = url;
},
onProgressChanged: (InAppWebViewController controller, int progress) {
double prog = progress / 100;
print('InAppWebView.onProgressChanged: $prog');
});
return Container(
width: webRect.width,
height: webRect.height,
child: webWidget,
);
}
}
full code
import 'package:flutter/material.dart';
import 'package:flutter_inappbrowser/flutter_inappbrowser.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
Navigator.push(context, MaterialPageRoute(builder: (BuildContext context) => MyInAppWebView(webUrl: "https://flutter.dev/",webRect: Rect.fromLTWH(0, 0, 300, 300))));
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
#override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Invoke "debug painting" (press "p" in the console, choose the
// "Toggle Debug Paint" action from the Flutter Inspector in Android
// Studio, or the "Toggle Debug Paint" command in Visual Studio Code)
// to see the wireframe for each widget.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Expanded( child: MyInAppWebView(webUrl: "https://flutter.dev/", webRect: Rect.fromLTWH(0, 0, 300, 300),)),
Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
);
}
}
class MyInAppWebView extends StatelessWidget {
String webUrl;
final Rect webRect;
InAppWebViewController webView;
MyInAppWebView({Key key, this.webUrl, this.webRect}) : super(key: key);
#override
Widget build(BuildContext context) {
InAppWebView webWidget = new InAppWebView(
initialUrl: webUrl,
initialHeaders: {},
initialOptions: {},
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {
print("InAppWebView.onLoadStart: $url");
this.webUrl = url;
},
onProgressChanged: (InAppWebViewController controller, int progress) {
double prog = progress / 100;
print('InAppWebView.onProgressChanged: $prog');
});
return Container(
width: webRect.width,
height: webRect.height,
child: webWidget,
);
}
}
example code demo
official demo
Did you try forceWebview option as explained in https://medium.com/#muaazmusthafa08/how-to-load-a-web-page-in-flutter-app-607fa9184e4a

What is wrong with my code? It only shows a black screen

I am trying to make an application and now what I want to do is just create a container with shadows.
It said dead code so I deleted some code, and tried some other things.
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class appBar extends StatelessWidget {
appBar({this.title});
final Widget title;
#override
Widget build(BuildContext context) {
return Container(
height: 60.0,
padding: const EdgeInsets.all(10.0));
decoration: new BoxDecoration(color: Colors.cyan[500]);
child: Container(
decoration: new BoxDecoration(
boxShadow:[
BoxShadow(
color: Colors.black12,
blurRadius: 20,
spreadRadius: 4.0,
offset: Offset(
8.0,
8.0,
)
),
]
));
}
}
I expected a container but I got a black screen.
Instead of using decoration in Container to get the color. Just add color widget to your container. An example is as follows
return Container(
color:Colors.cyan
)
You see a black screen when you are missing a material widget. Wrapping the whole widget in a Scafold works.
I also see some wrong syntax, so here's the fix.
class appBar extends StatelessWidget {
appBar({this.title});
final Widget title;
#override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
height: 60.0,
padding: const EdgeInsets.all(10.0),
decoration: new BoxDecoration(color: Colors.cyan[500]),
child: Container(
decoration: new BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black12,
blurRadius: 20,
spreadRadius: 4.0,
offset: Offset(
8.0,
8.0,
),
),
],
),
),
),
);
}
}
You have to warp your container with Scaffold widget. and you will get reslove your issue !! enjoy.because in flutter scaffold provide black screen with white canvas.
There were too many mistakes in your code, you unnecessarily used ; at the end of every line, and make sure your class name start with capital letter.
Here is the 100% working code.
void main() => runApp(MaterialApp(home: MyAppBar(title: "AppBar")));
class MyAppBar extends StatelessWidget {
MyAppBar({this.title});
final String title;
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
height: 60.0,
width: double.maxFinite,
padding: const EdgeInsets.all(10.0),
decoration: new BoxDecoration(color: Colors.cyan[500]),
child: Container(
child: Text(title ?? ''),
decoration: new BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black12,
blurRadius: 20,
spreadRadius: 4.0,
offset: Offset(8.0, 8.0),
),
],
),
),
),
),
);
}
}
appBar is not a nice class name. The convention is to start a class name with a capital letter. So AppBar would be nicer;
But AppBar is a flutter defined class, so... not a good choice;
your code has some ";" where you should have "," instead (you are inside of a Container function call, not a normal code body) Ex: padding: const EdgeInsets.all(10.0));
So i made corrections and tested your code this way (this is my main.dart file in a newly created flutter project):
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
#override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
}
#override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return AppBarCustom(title: Text('teste'));
}
}
class AppBarCustom extends StatelessWidget {
AppBarCustom({this.title});
final Widget title;
#override
Widget build(BuildContext context) {
return Container(
height: 60.0,
padding: const EdgeInsets.all(10.0),
decoration: new BoxDecoration(color: Colors.cyan[500]),
child: Container(
decoration: new BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 20,
spreadRadius: 10.0,
offset: Offset(
8.0,
8.0,
)),
],
),
),
);
}
}
I added a white background color to your inner Container just to show it more clearly and messed with the shadows...
Note your class at the end of the code.
He is the final rendering: