I have a Flutter project where I show the default page with all project licenses.
However I have copied a small piece of external code (which does not have a package), and I would like to add its license to all the others. Not having imported a package, I guess I have to do it manually.
Looking at the documentation, in theory I have to modify LicenseRegistry and add a license via addLicense(), but I didn't understand how to do it and how to enter the data.
onPressed: () {
// addLicense:
// MIT License
// Copyright ... ... ... ...
// Permission is hereby.......
// ...........................
// ...........................
// etc...
showLicensePage(
context: context,
applicationName: 'name',
applicationVersion: 'version',
applicationLegalese: 'copyright',
applicationIcon: Padding(
padding: const EdgeInsets.all(8),
child: Image.asset("assets/icon.png", width: 48, height: 48),
),
);
}
CodePudding user response:
If you git grep addLicense
in the current Flutter SDK, you'll see a few dozen examples of how your package needs to look to add license material.
CodePudding user response:
This code add a License to the LicenseRegistry (so to the LicensePage) (copied from https://api.flutter.dev/flutter/foundation/LicenseEntryWithLineBreaks-class.html):
LicenseRegistry.addLicense(() => Stream<LicenseEntry>.value(
const LicenseEntryWithLineBreaks(<String>['my_library'], '''
Copyright 2016 The Sample Authors. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Example Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.''',
),
));