我想制作一个小吃店,例如YouTube用于连接状态,但是我无法更改小吃店的高度。有人可以帮我吗?
这是我完成的代码。
Get.snackbar("", "You are connected to internet",
snackPosition: SnackPosition.BOTTOM,
backgroundColor: Colors.green,
padding: EdgeInsets.symmetric(
vertical: 0,
),
barBlur: 0,
maxWidth: double.infinity,
snackStyle: SnackStyle.GROUNDED,
borderRadius: 0.0);
答案 0 :(得分:2)
使用ConnectivityWidget可以完全解决您的目的
ConnectivityWidget(
builder: (context, isOnline) => Center(
child: Column([
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("${isOnline ? 'Connected' : 'No connectivity'}", style: TextStyle(fontSize: 30, color: isOnline ? Colors.green : Colors.red),),
SizedBox(height: 20,),
Text(
'Number of times we connected to the internet:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
)
输出:
答案 1 :(得分:2)
SnackBar将小部件作为子级。
SnackBar采用子对象的高度进行渲染。
例如
当您通过一个高度为200的容器时,它将设置快餐栏的高度为200。
scaffoldKey.currentState.showSnackBar(
SnackBar(
content: Container(
height: 200,
child: Center(child: Text('Hi')),
),
),
);
或者它会随着小吃店的孩子的成长而增长。
scaffoldKey.currentState.showSnackBar(
SnackBar(
content: Container(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('Hi'),
SizedBox(height: 25,),
Text('Hello'),
],
),
),
),
);
您可以创建将小部件传递给小吃店的通行证。
答案 2 :(得分:0)
依赖项:
dependencies:
connectivity_widget: ^0.1.7
代码:
ConnectivityWidget(
builder: (context, isOnline) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"${isOnline ? 'Connected' : 'Offline'}",
style: TextStyle(
fontSize: 30,
color: isOnline ? Colors.green : Colors.red),
),
],
),
),
)
全球使用
void main() => runApp(MaterialApp(
title: 'Flutter Calendar',
home: Scaffold(
body: ConnectivityWidget(
builder: (context, isOnline) => MyApp(),
),
),
));
完整代码
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_applicationdemo08/splashScreen.dart';
import 'package:image_picker/image_picker.dart';
import 'package:connectivity_widget/connectivity_widget.dart';
void main() => runApp(MaterialApp(
title: 'Flutter Calendar',
home: Scaffold(
body: ConnectivityWidget(
builder: (context, isOnline) => MyApp(),
),
),
));
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
fontFamily: "intel",
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: Splash(),
);
}
}
输出: