Hi how do i disable appbar from loading during splash screen flutter? I tried adding it into scaffold only but still the same.
import 'dart:async';
import 'dart:io';
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:connectivity/connectivity.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:double_back_to_close_app/double_back_to_close_app.dart';
import 'package:onesignal_flutter/onesignal_flutter.dart';
Future main() async {
runApp(new MyApp());
}
class MyApp extends StatefulWidget {
#override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _outputText = "";
#override
void initState() {
super.initState();
initOneSignal();
}
#override
void dispose() {
super.dispose();
}
#override
Widget build(BuildContext context) {
return MaterialApp(
home: IndexedStack(
index: 0,
children: <Widget>[
InAppWebViewPage(),
Container(
child: Text(_outputText),
)
],
));
}
Future<void> initOneSignal() async {
await OneSignal.shared
.init("xxxxxxxxxxxxxxxxxxxxxxxxxxx", iOSSettings: null);
OneSignal.shared
.setInFocusDisplayType(OSNotificationDisplayType.notification);
OneSignal.shared
.setNotificationReceivedHandler((OSNotification notification) {
this.setState(() {
_outputText =
"Received notification: \n${notification.jsonRepresentation().replaceAll("\\n", "\n")}";
});
});
}
}
class InAppWebViewPage extends StatefulWidget {
#override
_InAppWebViewPageState createState() => new _InAppWebViewPageState();
}
class _InAppWebViewPageState extends State<InAppWebViewPage> {
InAppWebViewController webView;
int _page = 2;
bool _loadError = false;
StreamSubscription<ConnectivityResult> subscription;
#override
initState() {
super.initState();
subscription = Connectivity()
.onConnectivityChanged
.listen((ConnectivityResult result) {
if (result != ConnectivityResult.none && webView != null) {
print("reload");
_loadError = false;
webView.reload();
}
});
}
#override
dispose() {
super.dispose();
subscription.cancel();
}
#override
Widget build(BuildContext context) {
return Scaffold(
body: IndexedStack(
index: _page,
children: <Widget>[
Container(
child: InAppWebView(
initialUrl: "www.google.com",
initialHeaders: {},
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
userAgent: Platform.isIOS
? 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_1_2 like Mac OS X) AppleWebKit/605.1.15' +
' (KHTML, like Gecko) Version/13.0.1 Mobile/15E148 Safari/604.1'
: 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) ' +
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Mobile Safari/537.36',
clearCache: false,
debuggingEnabled: true,
),
),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {},
onLoadStop: (InAppWebViewController controller, String url) {
print(url);
setState(() {
if (!_loadError) {
_page = 0;
} else {
_page = 1;
}
});
},
onLoadError: (InAppWebViewController controller, String url,
int code, String message) async {
print("error $url: $code, $message");
_loadError = true;
},
onLoadHttpError: (InAppWebViewController controller, String url,
int statusCode, String description) async {
print("HTTP error $url: $statusCode, $description");
},
),
),
(Platform.isAndroid)
? Container(
child: Text("My custom error message"),
)
: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/splash.png'),
fit: BoxFit.fitWidth,
),
)),
Container(
color: Colors.transparent,
decoration: BoxDecoration(
image: DecorationImage(
image: ExactAssetImage('assets/images/splash.png'),
fit: BoxFit.fitWidth,
),
),
),
],
),
);
}
}
I already tried searching for a few answer but i cant seem to find the one related to flutter. Do you guys know where should i put the appbar so it wont show on splash screen? Thank in advance!
Below is my pubspec.yaml as requested :
name: testing_app
description: A new Flutter project.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: "none" # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+2
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
flutter_inappwebview: ^3.4.0
connectivity: ^2.0.2
double_back_to_close_app: ^2.0.1
onesignal_flutter: ^2.0.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter_launcher_icons: "^0.8.0"
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
flutter_icons:
android: "launcher_icon"
ios: true
image_path: "assets/images/icon.png"
Related
I developed a flutter package multi_image_picker_view:
https://pub.dev/packages/multi_image_picker_view
This package depends on file_picker and flutter_reorderable_grid_view, they both support the Web. But in my package, web option is not visible in pub.dev. Even this package works fine on the web.
👉Help me to figure out why WEB is not showing on pub.dev.
📜My pubspec.yaml
name: multi_image_picker_view
description: A complete widget that can easily pick multiple images from a device and display them in UI. Also picked image can be re-ordered and removed easily.
version: 0.0.6
homepage: https://github.com/shubham-gupta-16/multi_image_picker_view
repository: https://github.com/shubham-gupta-16/multi_image_picker_view
issue_tracker: https://github.com/shubham-gupta-16/multi_image_picker_view/issues
environment:
sdk: ">=2.17.1 <3.0.0"
flutter: ">=1.17.0"
dependencies:
flutter:
sdk: flutter
flutter_reorderable_grid_view: ^3.1.3
file_picker: ^5.0.1
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^2.0.0
flutter:
assets:
- packages/multi_image_picker_view/assets/close-48.png
👨💻Commands I used to publish
flutter pub publish
🗃️My Matchine Info
Flutter Version: 3.0.1
Channel: Stable
Dart Version: 2.17.1
IDE: Android Studio Chipmunk | 2021.2.1 Patch 1
🚀You can find the complete code Github:
https://github.com/shubham-gupta-16/multi_image_picker_view
Thank you in advance.
Conditional import required
The reason why this package is not showing Web on pub.dev is that it uses dart.io without conditional import.
To fix this, I separated the file where it is used. One for web and one for non-web platforms. Then import them by using conditions based on the running platform.
web_preview.dart
import 'package:flutter/material.dart';
import '../image_file.dart';
class ImagePreview extends StatelessWidget {
final ImageFile file;
const ImagePreview({Key? key, required this.file}) : super(key: key);
#override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(4),
child: Image.memory(
file.bytes!,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return const Center(child: Text('No Preview'));
},
),
);
}
}
non_web_preview.dart
import 'dart:io'; // here I imported dart:io
import 'package:flutter/material.dart';
import '../image_file.dart';
class ImagePreview extends StatelessWidget {
final ImageFile file;
const ImagePreview({Key? key, required this.file}) : super(key: key);
#override
Widget build(BuildContext context) {
return ClipRRect(
borderRadius: BorderRadius.circular(4),
child: Image.file(
File(file.path!), // Now I can use File class
fit: BoxFit.cover,
),
);
}
}
my_package_file.dart
...
import 'non_web_preview.dart' if (dart.library.html) 'web_preview.dart'; // conditional import
class MyPackageFile extends StatelessWidget {
...
#override
Widget build(BuildContext context) {
return ImagePreview(file: imageFile); // Using ImagePreview class
}
}
I tried use Hive package in my application. But when I initialised in my app get error message:
The following HiveError was thrown building MyApp(dirty): Box not
found. Did you forget to call Hive.openBox()?
Her is my code:
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'dart:io';
import 'package:path_provider/path_provider.dart' as path_provider;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final appDocDir = await path_provider.getApplicationDocumentsDirectory();
Hive.init(appDocDir.path);
runApp(MyApp());
final box = await Hive.openBox('storage');
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
final box = Hive.box('storage');
return MaterialApp(
title: 'Test App',
debugShowCheckedModeBanner: false,
home: CheckAuth(),
);
}
}
class CheckAuth extends StatefulWidget {
#override
_CheckAuthState createState() => _CheckAuthState();
}
class _CheckAuthState extends State<CheckAuth> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Text('Hive initialised!'),
);
}
}
Emulator
API: 28
Android: 9
Packages
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
hive: ^1.4.4+1
hive_flutter: ^0.3.1
http: ^0.12.2
cupertino_icons: ^1.0.0
path_provider: ^1.6.24
dev_dependencies:
flutter_test:
sdk: flutter
hive_generator: ^0.8.2
build_runner: ^1.10.11
flutter:
uses-material-design: true
Where I have any error in my code?
Why don't you use await Hive.initFlutter() instead of Hive.init()? The former is supposed to take care of proper app folder path on specific platform and put it's files there.
It is part of package:hive_flutter/hive_flutter.dart which deals with Flutter specific stuff
I'm developing a Flutter application that needs to make http requests. I installed the http package as usual, but when it came time to test the app in a real device, the http requests are hanging, I never get a response or status code. I decided then to start a new application just to mess around with http package, but still I got the same issue.
This is what I get while debugging in Android Emulator (I get a response almost immediately) and this is what I get on a real device (hanging forever).
Possible solutions I have already tried: built signed and unsigned apk, ran flutter clean before building apk, built apk using --no-shrink flag, changed the version of http package in pubspec.yaml, and none of these seemed to solve the issue.
I am using the latest stable version of Flutter SDK (v1.17.5), Android Studio for coding, and Ubuntu 20.04 as Operating System.
Here is my dart code:
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
class AuthScreen extends StatefulWidget {
#override
_AuthScreenState createState() => _AuthScreenState();
}
class _AuthScreenState extends State<AuthScreen> {
final TextEditingController _urlController = TextEditingController();
String _status = 'Waiting for request';
void _submit() async {
setState(() {
_status = 'Waiting for response...';
});
var response = await http.get(_urlController.text);
if (response.statusCode == 200) {
setState(() {
_status = response.body.substring(0, 40) + ' [...]';
});
} else {
_status = 'Something went wrong';
}
}
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
TextFormField(
controller: _urlController,
),
FlatButton(
child: Text('Send request'),
onPressed: _submit,
),
Text(_status)
],
),
),
);
}
}
Here is my pubspec.yaml, in case it's useful:
name: testingHttpPackage
description: A new Flutter application.
publish_to: 'none'
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
http: ^0.12.1
cupertino_icons: ^0.1.3
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
Did you mention internet permission in AndroidManifest.xml file?
In android/app/src/main/, there is AndroidManifest.xml file, put the below line after manifest tag i.e. after the first tag.
<uses-permission android:name="android.permission.INTERNET" />
So I'm new to flutter and dart.I've made multiple android apps and I am pretty familiar with coding but I just can't get to know flutter. I use Android Studio as Ide and when I try to compile my code , on the assembleDebug part, This error is thrown:
c:\b\s\w\ir\k\src\third_party\dart\runtime\vm\zone.cc: 54: error: Out
of memory.
version=2.4.0 (Wed Jun 19 11:53:45 2019 +0200) on "windows_x64"
thread=1336, isolate=main(0000029506C2CDE0)
pc 0x00007ff7b33d2b1b fp 0x000000d10cbfb0a0 Unknown symbol
-- End of DumpStackTrace
For now, I haven't done anything to fix the problem because I don't know why
main.dart
import 'package:flutter/material.dart';
import 'constants.dart';
import 'package:flutter_svg/flutter_svg.dart';
void main() {
runApp(UnitConverterApp());
}
//on create
class UnitConverterApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Distivity Todolist',
theme: Constants.getTheme(),
home: CategoryRoute(),
);
}
}
class CategoryRoute extends StatefulWidget {
const CategoryRoute();
#override
_CategoryRouteState createState() => _CategoryRouteState();
}
class _CategoryRouteState extends State<CategoryRoute> {
/// Function to call when a [Category] is tapped.
void _onCategoryTap() {
setState(() {
});
}
#override
Widget build(BuildContext context) {
return Center(
child: InkWell(
onTap: () => _onCategoryTap(),
child: SvgPicture.asset(
Constants.add,
semanticsLabel: 'ad'
),
)
);
}
}
constants.dart
import 'package:flutter/material.dart';
class Constants{
static ThemeData getTheme(){
return ThemeData(
primaryColor: colorSwatch,
);
}
static const primaryColor = 0xff4FB484;
static ColorSwatch colorSwatch = ColorSwatch(primaryColor, const<String,Color>{
"primary_color": Color(primaryColor),
"primary_dark":Color(0xff306D50),
"black_16": Color(0xff161616),
"black_20":Color(0xff202020),
"the_blackest":Color(0xff000000),
"color_white":Color(0xffF7F7F7),
"the_whitest":Color(0xffffffff)
});
static const String add = 'assets/add.svg';
}
pubspec.yaml
name: distivity_todolist
description: A new Flutter application.
https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_svg: 0.13.1
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/add.svg
Problem Description -
I am writing a search widget which is an AutoCompletTextField. It takes the queryString entered by the user and fetches related suggestions from the internet and then attaches those suggestions to the AutoCompleteTextField. Everything till fetching the suggestions from the internet is working just fine. The suggestions are not popping up when I call the setState() method of the widget. The suggestions don't pop up even after the call to setState(). Please help.
Code -
`import 'package:flutter/material.dart';
import 'miscellaneous_widgets.dart';
import 'models/AppContextData.dart';
import 'package:autocomplete_textfield/autocomplete_textfield.dart';
import 'workers/MCAutoSuggestionsGetter.dart';`
class CompanySearchBox extends StatefulWidget {
#override
_CompanySearchBoxState createState() => _CompanySearchBoxState();
}
class _CompanySearchBoxState extends State<CompanySearchBox> {
GlobalKey<AutoCompleteTextFieldState<String>> key =
GlobalKey<AutoCompleteTextFieldState<String>>();
List<String> lstSuggestions = List<String>();
TextEditingController companySearchBoxController = TextEditingController();
#override
Widget build(BuildContext context) {
AutoCompleteTextField<String> myCompanySearchBox;
TextEditingController CompanyNameController = TextEditingController();
myCompanySearchBox = AutoCompleteTextField<String>(
key: key,
clearOnSubmit: false,
style: TextFieldStyle.get(),
decoration: InputDecoration(
labelText: "Search companies here.",
//border: OutlineInputBorder(),
suffixIcon: Icon(Icons.search),
),
submitOnSuggestionTap: true,
suggestions: lstSuggestions,
textChanged: (queryString){
if(queryString.length >= 3)
queryCompanyNames(queryString);
},
itemBuilder: (context,item){
return Center(
heightFactor: 1,
child: Column(
children: <Widget>[
ListTile(
contentPadding: EdgeInsets.all(2.0),
title: Text(
item,
style: TextRegularStyle.get()),
),
Divider(color: Colors.blueGrey,)
],)
);
},
itemFilter: (item,queryString ){
if(item.toLowerCase().startsWith(queryString.toLowerCase()))
return true;
},
itemSorter: (item1, item2){
return item1.toLowerCase().compareTo(item2.toLowerCase());
},
itemSubmitted: (SelectedItem){
//Not doing here anything as of now.
},
);
//myCompanySearchBox.textField.controller = CompanyNameController,
return myCompanySearchBox;
}
queryCompanyNames(String queryString) async
{
/*Calling the MCAutoSuggestionsGetter which fetches the suggestions from the internet. This step is working fine. We are getting a List<String> in "Suggestions" variable below. But when setState() is called, the previous "lstSuggestions" should be cleared and new "Suggestions" should be added. And these newly added suggestions should be displayed. But I am unable to achieve this.*/
MCAutoSuggestionsGetter.fetchSuggestions(queryString).then((Suggestions){
setState((){
lstSuggestions.clear();
lstSuggestions.addAll(Suggestions);
});
});
}
}
My pubspec.yaml -
name: dev1_stock_meter
description: A new Flutter application.
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
firebase_core: ^0.2.5+1
firebase_auth: ^0.7.0
fluttertoast: ^3.0.4
autocomplete_textfield: ^1.6.4
html: ^0.13.3+3
http: ^0.12.0
date_format: ^1.0.6
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- images/logo.jpg
fonts:
- family: GoogleSans
fonts:
- asset: fonts/GoogleSans-Regular.ttf
weight: 300
- asset: fonts/GoogleSans-Bold.ttf
weight: 400
Expected Behaviour:
The expected behaviour is when the user types a string that is more than 3 characters long, the suggestions should be fetched from internet and these suggestions should be attached to the AutoCompletTextField and the suggestions should be displayed.